@prampta/sdk 0.8.0 → 0.8.1
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/dist/index.d.mts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +28 -3
- package/dist/index.mjs +28 -3
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -32,6 +32,8 @@ declare class TrustedRegistryDirectory {
|
|
|
32
32
|
assertEndpoint(subject: string, baseUrl: string): void;
|
|
33
33
|
/** V-10: use only AFTER independently verifying the object's signature. */
|
|
34
34
|
assertSigner(code: string, keyId: string): void;
|
|
35
|
+
/** V-14 */
|
|
36
|
+
private assertNotRevoked;
|
|
35
37
|
assertDecision(subject: string, license: string | null, keyId: string, baseUrl: string): void;
|
|
36
38
|
}
|
|
37
39
|
|
package/dist/index.d.ts
CHANGED
|
@@ -32,6 +32,8 @@ declare class TrustedRegistryDirectory {
|
|
|
32
32
|
assertEndpoint(subject: string, baseUrl: string): void;
|
|
33
33
|
/** V-10: use only AFTER independently verifying the object's signature. */
|
|
34
34
|
assertSigner(code: string, keyId: string): void;
|
|
35
|
+
/** V-14 */
|
|
36
|
+
private assertNotRevoked;
|
|
35
37
|
assertDecision(subject: string, license: string | null, keyId: string, baseUrl: string): void;
|
|
36
38
|
}
|
|
37
39
|
|
package/dist/index.js
CHANGED
|
@@ -140,16 +140,18 @@ function registryNamespace(code) {
|
|
|
140
140
|
return "";
|
|
141
141
|
}
|
|
142
142
|
var TrustedRegistryDirectory = class _TrustedRegistryDirectory {
|
|
143
|
-
constructor(registries, sequence, snapshotHash, seal) {
|
|
143
|
+
constructor(registries, revokedKeys, sequence, snapshotHash, seal) {
|
|
144
144
|
this.sequence = sequence;
|
|
145
145
|
this.snapshotHash = snapshotHash;
|
|
146
146
|
if (seal !== verifiedConstruction) fail("Construct directories through signature verification");
|
|
147
147
|
this.#registries = registries;
|
|
148
|
+
this.#revokedKeys = new Set(revokedKeys);
|
|
148
149
|
Object.freeze(this);
|
|
149
150
|
}
|
|
150
151
|
sequence;
|
|
151
152
|
snapshotHash;
|
|
152
153
|
#registries;
|
|
154
|
+
#revokedKeys;
|
|
153
155
|
static async verify(input, options) {
|
|
154
156
|
const min = options.minSequence ?? 0;
|
|
155
157
|
if (!Number.isSafeInteger(min) || min < 0) fail("minSequence must be a nonnegative safe integer");
|
|
@@ -189,6 +191,16 @@ var TrustedRegistryDirectory = class _TrustedRegistryDirectory {
|
|
|
189
191
|
}
|
|
190
192
|
}
|
|
191
193
|
if (!prefixes.has("")) fail("Missing origin namespace");
|
|
194
|
+
for (const r of d.registries) {
|
|
195
|
+
if (r.revoked !== void 0 && !(r.revoked && typeof r.revoked === "object" && typeof r.revoked.at === "string")) {
|
|
196
|
+
fail("Invalid registry revocation");
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
if (d.revoked_keys !== void 0 && !(Array.isArray(d.revoked_keys) && d.revoked_keys.every(
|
|
200
|
+
(k) => k && /^pg-ed25519:[0-9a-f]{32}$/.test(String(k.key_id)) && typeof k.at === "string"
|
|
201
|
+
))) {
|
|
202
|
+
fail("Invalid revoked key list");
|
|
203
|
+
}
|
|
192
204
|
const publicKey = hexBytes(options.stewardPublicKeyHex, 32);
|
|
193
205
|
const hash = await sha256(publicKey);
|
|
194
206
|
const fp = "pg-ed25519:" + hash.slice(0, 32);
|
|
@@ -206,7 +218,13 @@ var TrustedRegistryDirectory = class _TrustedRegistryDirectory {
|
|
|
206
218
|
if (!valid) fail("Invalid directory signature");
|
|
207
219
|
const snapshotHash = await sha256(message);
|
|
208
220
|
if (previous && previous.sequence === d.sequence && previous.hash !== snapshotHash) fail("Directory equivocation detected");
|
|
209
|
-
return new _TrustedRegistryDirectory(
|
|
221
|
+
return new _TrustedRegistryDirectory(
|
|
222
|
+
d.registries,
|
|
223
|
+
(d.revoked_keys ?? []).map((k) => k.key_id),
|
|
224
|
+
d.sequence,
|
|
225
|
+
snapshotHash,
|
|
226
|
+
verifiedConstruction
|
|
227
|
+
);
|
|
210
228
|
}
|
|
211
229
|
registryFor(code) {
|
|
212
230
|
const prefix = registryNamespace(code);
|
|
@@ -222,7 +240,13 @@ var TrustedRegistryDirectory = class _TrustedRegistryDirectory {
|
|
|
222
240
|
}
|
|
223
241
|
/** V-10: use only AFTER independently verifying the object's signature. */
|
|
224
242
|
assertSigner(code, keyId) {
|
|
225
|
-
|
|
243
|
+
const owner = this.registryFor(code);
|
|
244
|
+
if (!owner.key_fingerprints.includes(keyId)) fail("Registry issuer/key mismatch");
|
|
245
|
+
this.assertNotRevoked(owner, keyId);
|
|
246
|
+
}
|
|
247
|
+
/** V-14 */
|
|
248
|
+
assertNotRevoked(owner, keyId) {
|
|
249
|
+
if (owner.revoked || this.#revokedKeys.has(keyId)) fail("Revoked registry or key");
|
|
226
250
|
}
|
|
227
251
|
assertDecision(subject, license, keyId, baseUrl) {
|
|
228
252
|
this.assertEndpoint(subject, baseUrl);
|
|
@@ -230,6 +254,7 @@ var TrustedRegistryDirectory = class _TrustedRegistryDirectory {
|
|
|
230
254
|
else {
|
|
231
255
|
const owner = this.#registries.find((r) => apiUrl(r.api) === apiUrl(baseUrl));
|
|
232
256
|
if (!owner?.key_fingerprints.includes(keyId)) fail("Registry issuer/key mismatch");
|
|
257
|
+
this.assertNotRevoked(owner, keyId);
|
|
233
258
|
}
|
|
234
259
|
if (license) {
|
|
235
260
|
this.assertEndpoint(license, baseUrl);
|
package/dist/index.mjs
CHANGED
|
@@ -85,16 +85,18 @@ function registryNamespace(code) {
|
|
|
85
85
|
return "";
|
|
86
86
|
}
|
|
87
87
|
var TrustedRegistryDirectory = class _TrustedRegistryDirectory {
|
|
88
|
-
constructor(registries, sequence, snapshotHash, seal) {
|
|
88
|
+
constructor(registries, revokedKeys, sequence, snapshotHash, seal) {
|
|
89
89
|
this.sequence = sequence;
|
|
90
90
|
this.snapshotHash = snapshotHash;
|
|
91
91
|
if (seal !== verifiedConstruction) fail("Construct directories through signature verification");
|
|
92
92
|
this.#registries = registries;
|
|
93
|
+
this.#revokedKeys = new Set(revokedKeys);
|
|
93
94
|
Object.freeze(this);
|
|
94
95
|
}
|
|
95
96
|
sequence;
|
|
96
97
|
snapshotHash;
|
|
97
98
|
#registries;
|
|
99
|
+
#revokedKeys;
|
|
98
100
|
static async verify(input, options) {
|
|
99
101
|
const min = options.minSequence ?? 0;
|
|
100
102
|
if (!Number.isSafeInteger(min) || min < 0) fail("minSequence must be a nonnegative safe integer");
|
|
@@ -134,6 +136,16 @@ var TrustedRegistryDirectory = class _TrustedRegistryDirectory {
|
|
|
134
136
|
}
|
|
135
137
|
}
|
|
136
138
|
if (!prefixes.has("")) fail("Missing origin namespace");
|
|
139
|
+
for (const r of d.registries) {
|
|
140
|
+
if (r.revoked !== void 0 && !(r.revoked && typeof r.revoked === "object" && typeof r.revoked.at === "string")) {
|
|
141
|
+
fail("Invalid registry revocation");
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
if (d.revoked_keys !== void 0 && !(Array.isArray(d.revoked_keys) && d.revoked_keys.every(
|
|
145
|
+
(k) => k && /^pg-ed25519:[0-9a-f]{32}$/.test(String(k.key_id)) && typeof k.at === "string"
|
|
146
|
+
))) {
|
|
147
|
+
fail("Invalid revoked key list");
|
|
148
|
+
}
|
|
137
149
|
const publicKey = hexBytes(options.stewardPublicKeyHex, 32);
|
|
138
150
|
const hash = await sha256(publicKey);
|
|
139
151
|
const fp = "pg-ed25519:" + hash.slice(0, 32);
|
|
@@ -151,7 +163,13 @@ var TrustedRegistryDirectory = class _TrustedRegistryDirectory {
|
|
|
151
163
|
if (!valid) fail("Invalid directory signature");
|
|
152
164
|
const snapshotHash = await sha256(message);
|
|
153
165
|
if (previous && previous.sequence === d.sequence && previous.hash !== snapshotHash) fail("Directory equivocation detected");
|
|
154
|
-
return new _TrustedRegistryDirectory(
|
|
166
|
+
return new _TrustedRegistryDirectory(
|
|
167
|
+
d.registries,
|
|
168
|
+
(d.revoked_keys ?? []).map((k) => k.key_id),
|
|
169
|
+
d.sequence,
|
|
170
|
+
snapshotHash,
|
|
171
|
+
verifiedConstruction
|
|
172
|
+
);
|
|
155
173
|
}
|
|
156
174
|
registryFor(code) {
|
|
157
175
|
const prefix = registryNamespace(code);
|
|
@@ -167,7 +185,13 @@ var TrustedRegistryDirectory = class _TrustedRegistryDirectory {
|
|
|
167
185
|
}
|
|
168
186
|
/** V-10: use only AFTER independently verifying the object's signature. */
|
|
169
187
|
assertSigner(code, keyId) {
|
|
170
|
-
|
|
188
|
+
const owner = this.registryFor(code);
|
|
189
|
+
if (!owner.key_fingerprints.includes(keyId)) fail("Registry issuer/key mismatch");
|
|
190
|
+
this.assertNotRevoked(owner, keyId);
|
|
191
|
+
}
|
|
192
|
+
/** V-14 */
|
|
193
|
+
assertNotRevoked(owner, keyId) {
|
|
194
|
+
if (owner.revoked || this.#revokedKeys.has(keyId)) fail("Revoked registry or key");
|
|
171
195
|
}
|
|
172
196
|
assertDecision(subject, license, keyId, baseUrl) {
|
|
173
197
|
this.assertEndpoint(subject, baseUrl);
|
|
@@ -175,6 +199,7 @@ var TrustedRegistryDirectory = class _TrustedRegistryDirectory {
|
|
|
175
199
|
else {
|
|
176
200
|
const owner = this.#registries.find((r) => apiUrl(r.api) === apiUrl(baseUrl));
|
|
177
201
|
if (!owner?.key_fingerprints.includes(keyId)) fail("Registry issuer/key mismatch");
|
|
202
|
+
this.assertNotRevoked(owner, keyId);
|
|
178
203
|
}
|
|
179
204
|
if (license) {
|
|
180
205
|
this.assertEndpoint(license, baseUrl);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prampta/sdk",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.1",
|
|
4
4
|
"description": "PRAMPTA SDK — authorization before generation",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"@noble/ed25519": "^3.1.0",
|
|
50
|
-
"@pregen/verify": "^0.
|
|
50
|
+
"@pregen/verify": "^0.5.0"
|
|
51
51
|
},
|
|
52
52
|
"repository": {
|
|
53
53
|
"type": "git",
|