provenance-protocol 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +7 -1
- package/src/keygen.d.ts +48 -0
- package/src/keygen.js +142 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "provenance-protocol",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "SDK for querying the Provenance agent identity index",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -9,11 +9,17 @@
|
|
|
9
9
|
".": {
|
|
10
10
|
"types": "./src/index.d.ts",
|
|
11
11
|
"import": "./src/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./keygen": {
|
|
14
|
+
"types": "./src/keygen.d.ts",
|
|
15
|
+
"import": "./src/keygen.js"
|
|
12
16
|
}
|
|
13
17
|
},
|
|
14
18
|
"files": [
|
|
15
19
|
"src/index.js",
|
|
16
20
|
"src/index.d.ts",
|
|
21
|
+
"src/keygen.js",
|
|
22
|
+
"src/keygen.d.ts",
|
|
17
23
|
"README.md"
|
|
18
24
|
],
|
|
19
25
|
"keywords": [
|
package/src/keygen.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* provenance-protocol — Key generation and signing utilities (TypeScript definitions)
|
|
3
|
+
* Node.js only. Not for browser use.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export interface KeyPair {
|
|
7
|
+
/** Base64-encoded SPKI DER public key. Put this in PROVENANCE.yml identity.public_key */
|
|
8
|
+
publicKey: string;
|
|
9
|
+
/** Base64-encoded PKCS8 DER private key. Store as PROVENANCE_PRIVATE_KEY env var. Never commit. */
|
|
10
|
+
privateKey: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Generate a new Ed25519 keypair for Provenance identity.
|
|
15
|
+
* Run once during agent setup.
|
|
16
|
+
*/
|
|
17
|
+
export function generateProvenanceKeyPair(): KeyPair;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Sign a challenge nonce from a receiving system.
|
|
21
|
+
* Returns a base64-encoded signature over `${provenanceId}:${nonce}`.
|
|
22
|
+
*
|
|
23
|
+
* @param privateKeyBase64 Your PROVENANCE_PRIVATE_KEY (base64 PKCS8 DER)
|
|
24
|
+
* @param provenanceId Your agent's Provenance ID
|
|
25
|
+
* @param nonce The nonce sent by the receiving system
|
|
26
|
+
*/
|
|
27
|
+
export function signChallenge(privateKeyBase64: string, provenanceId: string, nonce: string): string;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Sign your PROVENANCE.yml identity claim.
|
|
31
|
+
*
|
|
32
|
+
* Produces the `identity.signature` value for PROVENANCE.yml.
|
|
33
|
+
* Signs `${provenanceId}:${publicKeyBase64}` — binding the keypair to your specific agent ID.
|
|
34
|
+
* Run once during setup, after generateProvenanceKeyPair().
|
|
35
|
+
*
|
|
36
|
+
* @param privateKeyBase64 Your PROVENANCE_PRIVATE_KEY (base64 PKCS8 DER)
|
|
37
|
+
* @param provenanceId Your agent's Provenance ID
|
|
38
|
+
* @param publicKeyBase64 The public key you generated (base64 SPKI DER)
|
|
39
|
+
* @returns Base64 signature — put in PROVENANCE.yml identity.signature
|
|
40
|
+
*/
|
|
41
|
+
export function signForProvenance(privateKeyBase64: string, provenanceId: string, publicKeyBase64: string): string;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Sign a revocation request — clears your agent's public key and identity_verified status.
|
|
45
|
+
* Use when your private key is compromised or you're rotating keys.
|
|
46
|
+
* Send the result as signed_challenge to POST /api/agents/revoke.
|
|
47
|
+
*/
|
|
48
|
+
export function signRevocation(privateKeyBase64: string, provenanceId: string): string;
|
package/src/keygen.js
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* provenance-protocol — Key generation and signing utilities
|
|
3
|
+
*
|
|
4
|
+
* Agent operators use this to:
|
|
5
|
+
* 1. Generate an Ed25519 keypair once (setup)
|
|
6
|
+
* 2. Put the public key in PROVENANCE.yml under identity.public_key
|
|
7
|
+
* 3. Keep the private key in their environment (never committed, never shared)
|
|
8
|
+
* 4. Sign challenges from receiving systems at runtime
|
|
9
|
+
*
|
|
10
|
+
* Usage (one-time setup):
|
|
11
|
+
* import { generateProvenanceKeyPair } from 'provenance-protocol/keygen';
|
|
12
|
+
* const { publicKey, privateKey } = generateProvenanceKeyPair();
|
|
13
|
+
* // Add publicKey to your PROVENANCE.yml:
|
|
14
|
+
* // identity:
|
|
15
|
+
* // public_key: "<publicKey>"
|
|
16
|
+
* // Store privateKey as an environment variable: PROVENANCE_PRIVATE_KEY=<privateKey>
|
|
17
|
+
*
|
|
18
|
+
* Usage (runtime — signing challenges):
|
|
19
|
+
* import { signChallenge } from 'provenance-protocol/keygen';
|
|
20
|
+
* const signature = signChallenge(process.env.PROVENANCE_PRIVATE_KEY, provenanceId, nonce);
|
|
21
|
+
* // Return signature to the receiving system
|
|
22
|
+
*
|
|
23
|
+
* Note: This module uses Node.js built-in crypto. It is Node-only (not browser).
|
|
24
|
+
* The verification side (in index.js) uses Web Crypto and works everywhere.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
import { generateKeyPairSync, sign, createPrivateKey } from 'crypto';
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Generate a new Ed25519 keypair for use with Provenance identity.
|
|
31
|
+
*
|
|
32
|
+
* Run this once during agent setup. Add the public key to PROVENANCE.yml.
|
|
33
|
+
* Store the private key securely as an environment variable.
|
|
34
|
+
*
|
|
35
|
+
* @returns {{ publicKey: string, privateKey: string }}
|
|
36
|
+
* publicKey — base64-encoded SPKI DER. Goes in PROVENANCE.yml identity.public_key
|
|
37
|
+
* privateKey — base64-encoded PKCS8 DER. Store as PROVENANCE_PRIVATE_KEY env var
|
|
38
|
+
*
|
|
39
|
+
* Example:
|
|
40
|
+
* const { publicKey, privateKey } = generateProvenanceKeyPair();
|
|
41
|
+
* console.log('Add to PROVENANCE.yml:');
|
|
42
|
+
* console.log('identity:');
|
|
43
|
+
* console.log(` public_key: "${publicKey}"`);
|
|
44
|
+
* console.log('\nStore as environment variable:');
|
|
45
|
+
* console.log(`PROVENANCE_PRIVATE_KEY=${privateKey}`);
|
|
46
|
+
*/
|
|
47
|
+
export function generateProvenanceKeyPair() {
|
|
48
|
+
const { publicKey, privateKey } = generateKeyPairSync('ed25519', {
|
|
49
|
+
publicKeyEncoding: { type: 'spki', format: 'der' },
|
|
50
|
+
privateKeyEncoding: { type: 'pkcs8', format: 'der' },
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
return {
|
|
54
|
+
publicKey: Buffer.from(publicKey).toString('base64'),
|
|
55
|
+
privateKey: Buffer.from(privateKey).toString('base64'),
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Sign a challenge from a receiving system.
|
|
61
|
+
*
|
|
62
|
+
* Call this when a receiving system sends you a nonce to prove your identity.
|
|
63
|
+
* The signed message is always `${provenanceId}:${nonce}` — this binds the
|
|
64
|
+
* signature to your specific identity and prevents replay attacks.
|
|
65
|
+
*
|
|
66
|
+
* @param {string} privateKeyBase64 Your PROVENANCE_PRIVATE_KEY (base64 PKCS8 DER)
|
|
67
|
+
* @param {string} provenanceId Your provenance ID, e.g. "provenance:github:alice/agent"
|
|
68
|
+
* @param {string} nonce The nonce sent by the receiving system
|
|
69
|
+
* @returns {string} Base64-encoded signature to return to the receiver
|
|
70
|
+
*
|
|
71
|
+
* Example:
|
|
72
|
+
* app.post('/prove-identity', (req, res) => {
|
|
73
|
+
* const { provenanceId, nonce } = req.body;
|
|
74
|
+
* const signature = signChallenge(
|
|
75
|
+
* process.env.PROVENANCE_PRIVATE_KEY,
|
|
76
|
+
* provenanceId,
|
|
77
|
+
* nonce
|
|
78
|
+
* );
|
|
79
|
+
* res.json({ signature });
|
|
80
|
+
* });
|
|
81
|
+
*/
|
|
82
|
+
export function signChallenge(privateKeyBase64, provenanceId, nonce) {
|
|
83
|
+
const keyBuffer = Buffer.from(privateKeyBase64, 'base64');
|
|
84
|
+
const privateKey = createPrivateKey({ key: keyBuffer, format: 'der', type: 'pkcs8' });
|
|
85
|
+
const message = Buffer.from(`${provenanceId}:${nonce}`, 'utf8');
|
|
86
|
+
return sign(null, message, privateKey).toString('base64');
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Sign your PROVENANCE.yml identity claim.
|
|
91
|
+
*
|
|
92
|
+
* Call this once after generating your keypair to produce the `identity.signature`
|
|
93
|
+
* value that goes into PROVENANCE.yml. The signature proves you control the private
|
|
94
|
+
* key that matches the public key in the file.
|
|
95
|
+
*
|
|
96
|
+
* The signed message is `${provenanceId}:${publicKeyBase64}` — this binds the key
|
|
97
|
+
* pair to your specific Provenance ID, preventing key reuse across identities.
|
|
98
|
+
*
|
|
99
|
+
* @param {string} privateKeyBase64 Your PROVENANCE_PRIVATE_KEY (base64 PKCS8 DER)
|
|
100
|
+
* @param {string} provenanceId Your agent's Provenance ID, e.g. "provenance:github:alice/agent"
|
|
101
|
+
* @param {string} publicKeyBase64 The public key you're registering (base64 SPKI DER)
|
|
102
|
+
* @returns {string} Base64-encoded signature — put this in identity.signature
|
|
103
|
+
*
|
|
104
|
+
* Example (one-time setup):
|
|
105
|
+
* import { generateProvenanceKeyPair, signForProvenance } from 'provenance-protocol/keygen';
|
|
106
|
+
* const { publicKey, privateKey } = generateProvenanceKeyPair();
|
|
107
|
+
* const id = 'provenance:github:your-org/your-agent';
|
|
108
|
+
* const signature = signForProvenance(privateKey, id, publicKey);
|
|
109
|
+
* console.log('Add to PROVENANCE.yml:');
|
|
110
|
+
* console.log('identity:');
|
|
111
|
+
* console.log(` public_key: "${publicKey}"`);
|
|
112
|
+
* console.log(` signature: "${signature}"`);
|
|
113
|
+
*/
|
|
114
|
+
/**
|
|
115
|
+
* Sign a revocation request.
|
|
116
|
+
*
|
|
117
|
+
* Call this when you want to revoke your agent's cryptographic identity —
|
|
118
|
+
* e.g. if your private key was compromised or you're rotating keys.
|
|
119
|
+
*
|
|
120
|
+
* @param {string} privateKeyBase64 Your current PROVENANCE_PRIVATE_KEY
|
|
121
|
+
* @param {string} provenanceId Your agent's Provenance ID
|
|
122
|
+
* @returns {string} Base64 signature — send as signed_challenge to POST /api/agents/revoke
|
|
123
|
+
*
|
|
124
|
+
* Example:
|
|
125
|
+
* import { signRevocation } from 'provenance-protocol/keygen';
|
|
126
|
+
* const signed_challenge = signRevocation(process.env.PROVENANCE_PRIVATE_KEY, provenanceId);
|
|
127
|
+
* await fetch('https://getprovenance.dev/api/agents/revoke', {
|
|
128
|
+
* method: 'POST',
|
|
129
|
+
* headers: { 'Content-Type': 'application/json' },
|
|
130
|
+
* body: JSON.stringify({ provenance_id: provenanceId, signed_challenge }),
|
|
131
|
+
* });
|
|
132
|
+
*/
|
|
133
|
+
export function signRevocation(privateKeyBase64, provenanceId) {
|
|
134
|
+
return signChallenge(privateKeyBase64, provenanceId, 'REVOKE');
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export function signForProvenance(privateKeyBase64, provenanceId, publicKeyBase64) {
|
|
138
|
+
const keyBuffer = Buffer.from(privateKeyBase64, 'base64');
|
|
139
|
+
const privateKey = createPrivateKey({ key: keyBuffer, format: 'der', type: 'pkcs8' });
|
|
140
|
+
const message = Buffer.from(`${provenanceId}:${publicKeyBase64}`, 'utf8');
|
|
141
|
+
return sign(null, message, privateKey).toString('base64');
|
|
142
|
+
}
|