Repository navigation
Expand file tree
/
Copy pathtest-pem-workflow.js
More file actions
52 lines (43 loc) Β· 2.05 KB
/
Copy pathtest-pem-workflow.js
File metadata and controls
52 lines (43 loc) Β· 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { PemUtils, SigningService, CryptoUtils } from './packages/security-web/src/index.ts';
console.log('π§ͺ Testing complete PEM workflow...');
// 1. Generate a key pair in PEM format
const { keyPair, privateKeyPem, publicKeyPem } = PemUtils.generateKeyPairAsPem();
console.log('β
Generated key pair in PEM format');
console.log('Private key PEM length:', privateKeyPem.length);
console.log('Public key PEM length:', publicKeyPem.length);
// 2. Convert back to hex for signing
const hexKeys = PemUtils.pemToKeyPair(privateKeyPem, publicKeyPem);
console.log('β
Converted PEM back to hex');
console.log('Keys match original:',
hexKeys.privateKey === keyPair.privateKey &&
hexKeys.publicKey === keyPair.publicKey
);
// 3. Sign a document with command-only field selection
const toolDocument = { command: 'test-tool' };
const signature = SigningService.signDocument(toolDocument, hexKeys.privateKey, {
includeFields: ['command']
});
console.log('β
Signed document with command field only');
console.log('Signature length:', signature.signature.length);
console.log('Algorithm:', signature.algorithm);
// 4. Verify the signature
const isValid = CryptoUtils.verify(signature.publicKey,
CryptoUtils.hash(JSON.stringify({ command: 'test-tool' })),
signature.signature
);
console.log('β
Direct crypto verification:', isValid);
// 5. Validate the key pair
const validation = PemUtils.validateKeyPair(privateKeyPem, publicKeyPem);
console.log('β
Key pair validation:', validation.isValid);
// 6. Test download functionality (simulated)
console.log('β
PEM download functions available:');
console.log('- downloadPrivateKeyPem');
console.log('- downloadPublicKeyPem');
console.log('- downloadKeyPairPems');
// 7. Show the actual PEM content (first few lines)
console.log('\nπ Generated PEM files:');
console.log('Private Key PEM:');
console.log(privateKeyPem.split('\n').slice(0, 3).join('\n') + '...');
console.log('\nPublic Key PEM:');
console.log(publicKeyPem.split('\n').slice(0, 3).join('\n') + '...');
console.log('\nπ Complete PEM workflow test successful!');