@smartledger/keys 1.5.2 → 1.5.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/dist/lumen-keys.js +449 -443
- package/dist/lumen-keys.js.map +4 -4
- package/dist/lumen-keys.min.js +3 -3
- package/dist/lumen-keys.min.js.map +4 -4
- package/package.json +1 -1
package/dist/lumen-keys.js
CHANGED
|
@@ -84,17 +84,17 @@ var LumenKeys = (() => {
|
|
|
84
84
|
});
|
|
85
85
|
|
|
86
86
|
// node_modules/@noble/hashes/utils.js
|
|
87
|
-
function
|
|
87
|
+
function isBytes3(a2) {
|
|
88
88
|
return a2 instanceof Uint8Array || ArrayBuffer.isView(a2) && a2.constructor.name === "Uint8Array";
|
|
89
89
|
}
|
|
90
|
-
function
|
|
90
|
+
function anumber2(n2, title = "") {
|
|
91
91
|
if (!Number.isSafeInteger(n2) || n2 < 0) {
|
|
92
92
|
const prefix = title && `"${title}" `;
|
|
93
93
|
throw new Error(`${prefix}expected integer >= 0, got ${n2}`);
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
|
-
function
|
|
97
|
-
const bytes =
|
|
96
|
+
function abytes3(value, length, title = "") {
|
|
97
|
+
const bytes = isBytes3(value);
|
|
98
98
|
const len = value?.length;
|
|
99
99
|
const needsLen = length !== void 0;
|
|
100
100
|
if (!bytes || needsLen && len !== length) {
|
|
@@ -105,14 +105,14 @@ var LumenKeys = (() => {
|
|
|
105
105
|
}
|
|
106
106
|
return value;
|
|
107
107
|
}
|
|
108
|
-
function
|
|
108
|
+
function aexists2(instance, checkFinished = true) {
|
|
109
109
|
if (instance.destroyed)
|
|
110
110
|
throw new Error("Hash instance has been destroyed");
|
|
111
111
|
if (checkFinished && instance.finished)
|
|
112
112
|
throw new Error("Hash#digest() has already been called");
|
|
113
113
|
}
|
|
114
|
-
function
|
|
115
|
-
|
|
114
|
+
function aoutput2(out, instance) {
|
|
115
|
+
abytes3(out, void 0, "digestInto() output");
|
|
116
116
|
const min = instance.outputLen;
|
|
117
117
|
if (out.length < min) {
|
|
118
118
|
throw new Error('"digestInto() output" expected to be of length >=' + min);
|
|
@@ -121,15 +121,15 @@ var LumenKeys = (() => {
|
|
|
121
121
|
function u32(arr) {
|
|
122
122
|
return new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
|
|
123
123
|
}
|
|
124
|
-
function
|
|
124
|
+
function clean2(...arrays) {
|
|
125
125
|
for (let i2 = 0; i2 < arrays.length; i2++) {
|
|
126
126
|
arrays[i2].fill(0);
|
|
127
127
|
}
|
|
128
128
|
}
|
|
129
|
-
function
|
|
129
|
+
function createView2(arr) {
|
|
130
130
|
return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
131
131
|
}
|
|
132
|
-
function
|
|
132
|
+
function rotr2(word, shift) {
|
|
133
133
|
return word << 32 - shift | word >>> shift;
|
|
134
134
|
}
|
|
135
135
|
function byteSwap(word) {
|
|
@@ -141,7 +141,7 @@ var LumenKeys = (() => {
|
|
|
141
141
|
}
|
|
142
142
|
return arr;
|
|
143
143
|
}
|
|
144
|
-
function
|
|
144
|
+
function createHasher2(hashCons, info = {}) {
|
|
145
145
|
const hashC = (msg, opts) => hashCons(opts).update(msg).digest();
|
|
146
146
|
const tmp = hashCons(void 0);
|
|
147
147
|
hashC.outputLen = tmp.outputLen;
|
|
@@ -163,18 +163,18 @@ var LumenKeys = (() => {
|
|
|
163
163
|
});
|
|
164
164
|
|
|
165
165
|
// node_modules/@noble/hashes/_md.js
|
|
166
|
-
function
|
|
166
|
+
function Chi2(a2, b2, c2) {
|
|
167
167
|
return a2 & b2 ^ ~a2 & c2;
|
|
168
168
|
}
|
|
169
|
-
function
|
|
169
|
+
function Maj2(a2, b2, c2) {
|
|
170
170
|
return a2 & b2 ^ a2 & c2 ^ b2 & c2;
|
|
171
171
|
}
|
|
172
|
-
var
|
|
172
|
+
var HashMD2, SHA256_IV2, SHA512_IV2;
|
|
173
173
|
var init_md = __esm({
|
|
174
174
|
"node_modules/@noble/hashes/_md.js"() {
|
|
175
175
|
init_esbuild_shims();
|
|
176
176
|
init_utils();
|
|
177
|
-
|
|
177
|
+
HashMD2 = class {
|
|
178
178
|
constructor(blockLen, outputLen, padOffset, isLE2) {
|
|
179
179
|
__publicField(this, "blockLen");
|
|
180
180
|
__publicField(this, "outputLen");
|
|
@@ -192,17 +192,17 @@ var LumenKeys = (() => {
|
|
|
192
192
|
this.padOffset = padOffset;
|
|
193
193
|
this.isLE = isLE2;
|
|
194
194
|
this.buffer = new Uint8Array(blockLen);
|
|
195
|
-
this.view =
|
|
195
|
+
this.view = createView2(this.buffer);
|
|
196
196
|
}
|
|
197
197
|
update(data) {
|
|
198
|
-
|
|
199
|
-
|
|
198
|
+
aexists2(this);
|
|
199
|
+
abytes3(data);
|
|
200
200
|
const { view, buffer, blockLen } = this;
|
|
201
201
|
const len = data.length;
|
|
202
202
|
for (let pos = 0; pos < len; ) {
|
|
203
203
|
const take = Math.min(blockLen - this.pos, len - pos);
|
|
204
204
|
if (take === blockLen) {
|
|
205
|
-
const dataView =
|
|
205
|
+
const dataView = createView2(data);
|
|
206
206
|
for (; blockLen <= len - pos; pos += blockLen)
|
|
207
207
|
this.process(dataView, pos);
|
|
208
208
|
continue;
|
|
@@ -220,13 +220,13 @@ var LumenKeys = (() => {
|
|
|
220
220
|
return this;
|
|
221
221
|
}
|
|
222
222
|
digestInto(out) {
|
|
223
|
-
|
|
224
|
-
|
|
223
|
+
aexists2(this);
|
|
224
|
+
aoutput2(out, this);
|
|
225
225
|
this.finished = true;
|
|
226
226
|
const { buffer, view, blockLen, isLE: isLE2 } = this;
|
|
227
227
|
let { pos } = this;
|
|
228
228
|
buffer[pos++] = 128;
|
|
229
|
-
|
|
229
|
+
clean2(this.buffer.subarray(pos));
|
|
230
230
|
if (this.padOffset > blockLen - pos) {
|
|
231
231
|
this.process(view, 0);
|
|
232
232
|
pos = 0;
|
|
@@ -235,7 +235,7 @@ var LumenKeys = (() => {
|
|
|
235
235
|
buffer[i2] = 0;
|
|
236
236
|
view.setBigUint64(blockLen - 8, BigInt(this.length * 8), isLE2);
|
|
237
237
|
this.process(view, 0);
|
|
238
|
-
const oview =
|
|
238
|
+
const oview = createView2(out);
|
|
239
239
|
const len = this.outputLen;
|
|
240
240
|
if (len % 4)
|
|
241
241
|
throw new Error("_sha2: outputLen must be aligned to 32bit");
|
|
@@ -269,7 +269,7 @@ var LumenKeys = (() => {
|
|
|
269
269
|
return this._cloneInto();
|
|
270
270
|
}
|
|
271
271
|
};
|
|
272
|
-
|
|
272
|
+
SHA256_IV2 = /* @__PURE__ */ Uint32Array.from([
|
|
273
273
|
1779033703,
|
|
274
274
|
3144134277,
|
|
275
275
|
1013904242,
|
|
@@ -279,7 +279,7 @@ var LumenKeys = (() => {
|
|
|
279
279
|
528734635,
|
|
280
280
|
1541459225
|
|
281
281
|
]);
|
|
282
|
-
|
|
282
|
+
SHA512_IV2 = /* @__PURE__ */ Uint32Array.from([
|
|
283
283
|
1779033703,
|
|
284
284
|
4089235720,
|
|
285
285
|
3144134277,
|
|
@@ -346,14 +346,14 @@ var LumenKeys = (() => {
|
|
|
346
346
|
});
|
|
347
347
|
|
|
348
348
|
// node_modules/@noble/hashes/sha2.js
|
|
349
|
-
var
|
|
349
|
+
var SHA256_K2, SHA256_W2, SHA2_32B, _SHA256, K512, SHA512_Kh, SHA512_Kl, SHA512_W_H, SHA512_W_L, SHA2_64B, _SHA512, sha2563, sha512;
|
|
350
350
|
var init_sha2 = __esm({
|
|
351
351
|
"node_modules/@noble/hashes/sha2.js"() {
|
|
352
352
|
init_esbuild_shims();
|
|
353
353
|
init_md();
|
|
354
354
|
init_u64();
|
|
355
355
|
init_utils();
|
|
356
|
-
|
|
356
|
+
SHA256_K2 = /* @__PURE__ */ Uint32Array.from([
|
|
357
357
|
1116352408,
|
|
358
358
|
1899447441,
|
|
359
359
|
3049323471,
|
|
@@ -419,8 +419,8 @@ var LumenKeys = (() => {
|
|
|
419
419
|
3204031479,
|
|
420
420
|
3329325298
|
|
421
421
|
]);
|
|
422
|
-
|
|
423
|
-
SHA2_32B = class extends
|
|
422
|
+
SHA256_W2 = /* @__PURE__ */ new Uint32Array(64);
|
|
423
|
+
SHA2_32B = class extends HashMD2 {
|
|
424
424
|
constructor(outputLen) {
|
|
425
425
|
super(64, outputLen, 8, false);
|
|
426
426
|
}
|
|
@@ -441,20 +441,20 @@ var LumenKeys = (() => {
|
|
|
441
441
|
}
|
|
442
442
|
process(view, offset) {
|
|
443
443
|
for (let i2 = 0; i2 < 16; i2++, offset += 4)
|
|
444
|
-
|
|
444
|
+
SHA256_W2[i2] = view.getUint32(offset, false);
|
|
445
445
|
for (let i2 = 16; i2 < 64; i2++) {
|
|
446
|
-
const W15 =
|
|
447
|
-
const W22 =
|
|
448
|
-
const s0 =
|
|
449
|
-
const s1 =
|
|
450
|
-
|
|
446
|
+
const W15 = SHA256_W2[i2 - 15];
|
|
447
|
+
const W22 = SHA256_W2[i2 - 2];
|
|
448
|
+
const s0 = rotr2(W15, 7) ^ rotr2(W15, 18) ^ W15 >>> 3;
|
|
449
|
+
const s1 = rotr2(W22, 17) ^ rotr2(W22, 19) ^ W22 >>> 10;
|
|
450
|
+
SHA256_W2[i2] = s1 + SHA256_W2[i2 - 7] + s0 + SHA256_W2[i2 - 16] | 0;
|
|
451
451
|
}
|
|
452
452
|
let { A: A2, B: B2, C: C3, D: D2, E: E2, F: F2, G: G3, H: H2 } = this;
|
|
453
453
|
for (let i2 = 0; i2 < 64; i2++) {
|
|
454
|
-
const sigma1 =
|
|
455
|
-
const T1 = H2 + sigma1 +
|
|
456
|
-
const sigma0 =
|
|
457
|
-
const T2 = sigma0 +
|
|
454
|
+
const sigma1 = rotr2(E2, 6) ^ rotr2(E2, 11) ^ rotr2(E2, 25);
|
|
455
|
+
const T1 = H2 + sigma1 + Chi2(E2, F2, G3) + SHA256_K2[i2] + SHA256_W2[i2] | 0;
|
|
456
|
+
const sigma0 = rotr2(A2, 2) ^ rotr2(A2, 13) ^ rotr2(A2, 22);
|
|
457
|
+
const T2 = sigma0 + Maj2(A2, B2, C3) | 0;
|
|
458
458
|
H2 = G3;
|
|
459
459
|
G3 = F2;
|
|
460
460
|
F2 = E2;
|
|
@@ -475,11 +475,11 @@ var LumenKeys = (() => {
|
|
|
475
475
|
this.set(A2, B2, C3, D2, E2, F2, G3, H2);
|
|
476
476
|
}
|
|
477
477
|
roundClean() {
|
|
478
|
-
|
|
478
|
+
clean2(SHA256_W2);
|
|
479
479
|
}
|
|
480
480
|
destroy() {
|
|
481
481
|
this.set(0, 0, 0, 0, 0, 0, 0, 0);
|
|
482
|
-
|
|
482
|
+
clean2(this.buffer);
|
|
483
483
|
}
|
|
484
484
|
};
|
|
485
485
|
_SHA256 = class extends SHA2_32B {
|
|
@@ -487,14 +487,14 @@ var LumenKeys = (() => {
|
|
|
487
487
|
super(32);
|
|
488
488
|
// We cannot use array here since array allows indexing by variable
|
|
489
489
|
// which means optimizer/compiler cannot use registers.
|
|
490
|
-
__publicField(this, "A",
|
|
491
|
-
__publicField(this, "B",
|
|
492
|
-
__publicField(this, "C",
|
|
493
|
-
__publicField(this, "D",
|
|
494
|
-
__publicField(this, "E",
|
|
495
|
-
__publicField(this, "F",
|
|
496
|
-
__publicField(this, "G",
|
|
497
|
-
__publicField(this, "H",
|
|
490
|
+
__publicField(this, "A", SHA256_IV2[0] | 0);
|
|
491
|
+
__publicField(this, "B", SHA256_IV2[1] | 0);
|
|
492
|
+
__publicField(this, "C", SHA256_IV2[2] | 0);
|
|
493
|
+
__publicField(this, "D", SHA256_IV2[3] | 0);
|
|
494
|
+
__publicField(this, "E", SHA256_IV2[4] | 0);
|
|
495
|
+
__publicField(this, "F", SHA256_IV2[5] | 0);
|
|
496
|
+
__publicField(this, "G", SHA256_IV2[6] | 0);
|
|
497
|
+
__publicField(this, "H", SHA256_IV2[7] | 0);
|
|
498
498
|
}
|
|
499
499
|
};
|
|
500
500
|
K512 = /* @__PURE__ */ (() => split([
|
|
@@ -583,7 +583,7 @@ var LumenKeys = (() => {
|
|
|
583
583
|
SHA512_Kl = /* @__PURE__ */ (() => K512[1])();
|
|
584
584
|
SHA512_W_H = /* @__PURE__ */ new Uint32Array(80);
|
|
585
585
|
SHA512_W_L = /* @__PURE__ */ new Uint32Array(80);
|
|
586
|
-
SHA2_64B = class extends
|
|
586
|
+
SHA2_64B = class extends HashMD2 {
|
|
587
587
|
constructor(outputLen) {
|
|
588
588
|
super(128, outputLen, 16, false);
|
|
589
589
|
}
|
|
@@ -671,39 +671,39 @@ var LumenKeys = (() => {
|
|
|
671
671
|
this.set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl);
|
|
672
672
|
}
|
|
673
673
|
roundClean() {
|
|
674
|
-
|
|
674
|
+
clean2(SHA512_W_H, SHA512_W_L);
|
|
675
675
|
}
|
|
676
676
|
destroy() {
|
|
677
|
-
|
|
677
|
+
clean2(this.buffer);
|
|
678
678
|
this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
679
679
|
}
|
|
680
680
|
};
|
|
681
681
|
_SHA512 = class extends SHA2_64B {
|
|
682
682
|
constructor() {
|
|
683
683
|
super(64);
|
|
684
|
-
__publicField(this, "Ah",
|
|
685
|
-
__publicField(this, "Al",
|
|
686
|
-
__publicField(this, "Bh",
|
|
687
|
-
__publicField(this, "Bl",
|
|
688
|
-
__publicField(this, "Ch",
|
|
689
|
-
__publicField(this, "Cl",
|
|
690
|
-
__publicField(this, "Dh",
|
|
691
|
-
__publicField(this, "Dl",
|
|
692
|
-
__publicField(this, "Eh",
|
|
693
|
-
__publicField(this, "El",
|
|
694
|
-
__publicField(this, "Fh",
|
|
695
|
-
__publicField(this, "Fl",
|
|
696
|
-
__publicField(this, "Gh",
|
|
697
|
-
__publicField(this, "Gl",
|
|
698
|
-
__publicField(this, "Hh",
|
|
699
|
-
__publicField(this, "Hl",
|
|
684
|
+
__publicField(this, "Ah", SHA512_IV2[0] | 0);
|
|
685
|
+
__publicField(this, "Al", SHA512_IV2[1] | 0);
|
|
686
|
+
__publicField(this, "Bh", SHA512_IV2[2] | 0);
|
|
687
|
+
__publicField(this, "Bl", SHA512_IV2[3] | 0);
|
|
688
|
+
__publicField(this, "Ch", SHA512_IV2[4] | 0);
|
|
689
|
+
__publicField(this, "Cl", SHA512_IV2[5] | 0);
|
|
690
|
+
__publicField(this, "Dh", SHA512_IV2[6] | 0);
|
|
691
|
+
__publicField(this, "Dl", SHA512_IV2[7] | 0);
|
|
692
|
+
__publicField(this, "Eh", SHA512_IV2[8] | 0);
|
|
693
|
+
__publicField(this, "El", SHA512_IV2[9] | 0);
|
|
694
|
+
__publicField(this, "Fh", SHA512_IV2[10] | 0);
|
|
695
|
+
__publicField(this, "Fl", SHA512_IV2[11] | 0);
|
|
696
|
+
__publicField(this, "Gh", SHA512_IV2[12] | 0);
|
|
697
|
+
__publicField(this, "Gl", SHA512_IV2[13] | 0);
|
|
698
|
+
__publicField(this, "Hh", SHA512_IV2[14] | 0);
|
|
699
|
+
__publicField(this, "Hl", SHA512_IV2[15] | 0);
|
|
700
700
|
}
|
|
701
701
|
};
|
|
702
|
-
|
|
702
|
+
sha2563 = /* @__PURE__ */ createHasher2(
|
|
703
703
|
() => new _SHA256(),
|
|
704
704
|
/* @__PURE__ */ oidNist(1)
|
|
705
705
|
);
|
|
706
|
-
sha512 = /* @__PURE__ */
|
|
706
|
+
sha512 = /* @__PURE__ */ createHasher2(
|
|
707
707
|
() => new _SHA512(),
|
|
708
708
|
/* @__PURE__ */ oidNist(3)
|
|
709
709
|
);
|
|
@@ -749,7 +749,7 @@ var LumenKeys = (() => {
|
|
|
749
749
|
s2[0] ^= SHA3_IOTA_H[round];
|
|
750
750
|
s2[1] ^= SHA3_IOTA_L[round];
|
|
751
751
|
}
|
|
752
|
-
|
|
752
|
+
clean2(B2);
|
|
753
753
|
}
|
|
754
754
|
var _0n, _1n, _2n, _7n, _256n, _0x71n, SHA3_PI, SHA3_ROTL, _SHA3_IOTA, IOTAS, SHA3_IOTA_H, SHA3_IOTA_L, rotlH, rotlL, Keccak, genKeccak, sha3_256;
|
|
755
755
|
var init_sha3 = __esm({
|
|
@@ -802,7 +802,7 @@ var LumenKeys = (() => {
|
|
|
802
802
|
this.outputLen = outputLen;
|
|
803
803
|
this.enableXOF = enableXOF;
|
|
804
804
|
this.rounds = rounds;
|
|
805
|
-
|
|
805
|
+
anumber2(outputLen, "outputLen");
|
|
806
806
|
if (!(0 < blockLen && blockLen < 200))
|
|
807
807
|
throw new Error("only keccak-f1600 function is supported");
|
|
808
808
|
this.state = new Uint8Array(200);
|
|
@@ -819,8 +819,8 @@ var LumenKeys = (() => {
|
|
|
819
819
|
this.pos = 0;
|
|
820
820
|
}
|
|
821
821
|
update(data) {
|
|
822
|
-
|
|
823
|
-
|
|
822
|
+
aexists2(this);
|
|
823
|
+
abytes3(data);
|
|
824
824
|
const { blockLen, state } = this;
|
|
825
825
|
const len = data.length;
|
|
826
826
|
for (let pos = 0; pos < len; ) {
|
|
@@ -844,8 +844,8 @@ var LumenKeys = (() => {
|
|
|
844
844
|
this.keccak();
|
|
845
845
|
}
|
|
846
846
|
writeInto(out) {
|
|
847
|
-
|
|
848
|
-
|
|
847
|
+
aexists2(this, false);
|
|
848
|
+
abytes3(out);
|
|
849
849
|
this.finish();
|
|
850
850
|
const bufferOut = this.state;
|
|
851
851
|
const { blockLen } = this;
|
|
@@ -865,11 +865,11 @@ var LumenKeys = (() => {
|
|
|
865
865
|
return this.writeInto(out);
|
|
866
866
|
}
|
|
867
867
|
xof(bytes) {
|
|
868
|
-
|
|
868
|
+
anumber2(bytes);
|
|
869
869
|
return this.xofInto(new Uint8Array(bytes));
|
|
870
870
|
}
|
|
871
871
|
digestInto(out) {
|
|
872
|
-
|
|
872
|
+
aoutput2(out, this);
|
|
873
873
|
if (this.finished)
|
|
874
874
|
throw new Error("digest() was already called");
|
|
875
875
|
this.writeInto(out);
|
|
@@ -881,7 +881,7 @@ var LumenKeys = (() => {
|
|
|
881
881
|
}
|
|
882
882
|
destroy() {
|
|
883
883
|
this.destroyed = true;
|
|
884
|
-
|
|
884
|
+
clean2(this.state);
|
|
885
885
|
}
|
|
886
886
|
_cloneInto(to) {
|
|
887
887
|
const { blockLen, suffix, outputLen, rounds, enableXOF } = this;
|
|
@@ -898,7 +898,7 @@ var LumenKeys = (() => {
|
|
|
898
898
|
return to;
|
|
899
899
|
}
|
|
900
900
|
};
|
|
901
|
-
genKeccak = (suffix, blockLen, outputLen, info = {}) =>
|
|
901
|
+
genKeccak = (suffix, blockLen, outputLen, info = {}) => createHasher2(() => new Keccak(blockLen, suffix, outputLen), info);
|
|
902
902
|
sha3_256 = /* @__PURE__ */ genKeccak(
|
|
903
903
|
6,
|
|
904
904
|
136,
|
|
@@ -920,7 +920,7 @@ var LumenKeys = (() => {
|
|
|
920
920
|
switch (algorithm.toLowerCase()) {
|
|
921
921
|
case "sha256":
|
|
922
922
|
case "sha-256":
|
|
923
|
-
hashFn =
|
|
923
|
+
hashFn = sha2563;
|
|
924
924
|
break;
|
|
925
925
|
case "sha512":
|
|
926
926
|
case "sha-512":
|
|
@@ -2435,286 +2435,6 @@ var LumenKeys = (() => {
|
|
|
2435
2435
|
|
|
2436
2436
|
// ../crypto/dist/esm/registry.js
|
|
2437
2437
|
init_esbuild_shims();
|
|
2438
|
-
var SignatureSuiteRegistry = class {
|
|
2439
|
-
constructor() {
|
|
2440
|
-
__publicField(this, "suites", /* @__PURE__ */ new Map());
|
|
2441
|
-
}
|
|
2442
|
-
/**
|
|
2443
|
-
* Register a signature suite implementation
|
|
2444
|
-
*/
|
|
2445
|
-
register(suite) {
|
|
2446
|
-
if (this.suites.has(suite.suiteId)) {
|
|
2447
|
-
throw new Error(`Signature suite already registered: ${suite.suiteId}`);
|
|
2448
|
-
}
|
|
2449
|
-
this.suites.set(suite.suiteId, suite);
|
|
2450
|
-
}
|
|
2451
|
-
/**
|
|
2452
|
-
* Get a signature suite by ID
|
|
2453
|
-
* @throws Error if suite is not registered
|
|
2454
|
-
*/
|
|
2455
|
-
getSuite(suiteId) {
|
|
2456
|
-
const suite = this.suites.get(suiteId);
|
|
2457
|
-
if (!suite) {
|
|
2458
|
-
throw new Error(`Unknown signature suite: ${suiteId}. Available: ${this.listSuites().join(", ")}`);
|
|
2459
|
-
}
|
|
2460
|
-
return suite;
|
|
2461
|
-
}
|
|
2462
|
-
/**
|
|
2463
|
-
* Check if a suite is registered
|
|
2464
|
-
*/
|
|
2465
|
-
hasSuite(suiteId) {
|
|
2466
|
-
return this.suites.has(suiteId);
|
|
2467
|
-
}
|
|
2468
|
-
/**
|
|
2469
|
-
* List all registered suite IDs
|
|
2470
|
-
*/
|
|
2471
|
-
listSuites() {
|
|
2472
|
-
return [...this.suites.keys()];
|
|
2473
|
-
}
|
|
2474
|
-
/**
|
|
2475
|
-
* Get all registered suite objects
|
|
2476
|
-
*/
|
|
2477
|
-
getAllSuites() {
|
|
2478
|
-
return [...this.suites.values()];
|
|
2479
|
-
}
|
|
2480
|
-
/**
|
|
2481
|
-
* Unregister a suite (primarily for testing)
|
|
2482
|
-
*/
|
|
2483
|
-
unregister(suiteId) {
|
|
2484
|
-
return this.suites.delete(suiteId);
|
|
2485
|
-
}
|
|
2486
|
-
/**
|
|
2487
|
-
* Clear all registered suites (primarily for testing)
|
|
2488
|
-
*/
|
|
2489
|
-
clear() {
|
|
2490
|
-
this.suites.clear();
|
|
2491
|
-
}
|
|
2492
|
-
};
|
|
2493
|
-
var globalRegistry = new SignatureSuiteRegistry();
|
|
2494
|
-
|
|
2495
|
-
// ../crypto/dist/esm/utils.js
|
|
2496
|
-
init_esbuild_shims();
|
|
2497
|
-
function bytesToHex(bytes) {
|
|
2498
|
-
return Array.from(bytes).map((b2) => b2.toString(16).padStart(2, "0")).join("");
|
|
2499
|
-
}
|
|
2500
|
-
function hexToBytes(hex) {
|
|
2501
|
-
if (hex.length % 2 !== 0) {
|
|
2502
|
-
throw new Error("Hex string must have even length");
|
|
2503
|
-
}
|
|
2504
|
-
const bytes = new Uint8Array(hex.length / 2);
|
|
2505
|
-
for (let i2 = 0; i2 < hex.length; i2 += 2) {
|
|
2506
|
-
bytes[i2 / 2] = parseInt(hex.slice(i2, i2 + 2), 16);
|
|
2507
|
-
}
|
|
2508
|
-
return bytes;
|
|
2509
|
-
}
|
|
2510
|
-
async function hashBytes(bytes, algorithm) {
|
|
2511
|
-
if (algorithm === "sha256") {
|
|
2512
|
-
const crypto = await Promise.resolve().then(() => (init_crypto_browser_shim(), crypto_browser_shim_exports));
|
|
2513
|
-
return new Uint8Array(crypto.createHash("sha256").update(bytes).digest());
|
|
2514
|
-
} else if (algorithm === "sha512") {
|
|
2515
|
-
const crypto = await Promise.resolve().then(() => (init_crypto_browser_shim(), crypto_browser_shim_exports));
|
|
2516
|
-
return new Uint8Array(crypto.createHash("sha512").update(bytes).digest());
|
|
2517
|
-
} else if (algorithm === "sha3-256") {
|
|
2518
|
-
const crypto = await Promise.resolve().then(() => (init_crypto_browser_shim(), crypto_browser_shim_exports));
|
|
2519
|
-
return new Uint8Array(crypto.createHash("sha3-256").update(bytes).digest());
|
|
2520
|
-
}
|
|
2521
|
-
throw new Error(`Unsupported hash algorithm: ${algorithm}`);
|
|
2522
|
-
}
|
|
2523
|
-
|
|
2524
|
-
// ../crypto/dist/esm/signing.js
|
|
2525
|
-
init_esbuild_shims();
|
|
2526
|
-
|
|
2527
|
-
// ../crypto/dist/esm/key-registry.js
|
|
2528
|
-
init_esbuild_shims();
|
|
2529
|
-
var InMemoryKeyStorage = class {
|
|
2530
|
-
constructor() {
|
|
2531
|
-
__publicField(this, "keys", /* @__PURE__ */ new Map());
|
|
2532
|
-
}
|
|
2533
|
-
async store(keyId, keypair, meta) {
|
|
2534
|
-
this.keys.set(keyId, { keypair, meta });
|
|
2535
|
-
}
|
|
2536
|
-
async load(keyId) {
|
|
2537
|
-
return this.keys.get(keyId) || null;
|
|
2538
|
-
}
|
|
2539
|
-
async list(filter) {
|
|
2540
|
-
const allMeta = Array.from(this.keys.values()).map((k2) => k2.meta);
|
|
2541
|
-
if (!filter) {
|
|
2542
|
-
return allMeta;
|
|
2543
|
-
}
|
|
2544
|
-
return allMeta.filter((meta) => {
|
|
2545
|
-
return Object.entries(filter).every(([key, value]) => {
|
|
2546
|
-
if (key === "usage" && Array.isArray(value)) {
|
|
2547
|
-
return value.some((u2) => meta.usage.includes(u2));
|
|
2548
|
-
}
|
|
2549
|
-
return meta[key] === value;
|
|
2550
|
-
});
|
|
2551
|
-
});
|
|
2552
|
-
}
|
|
2553
|
-
async delete(keyId) {
|
|
2554
|
-
this.keys.delete(keyId);
|
|
2555
|
-
}
|
|
2556
|
-
async updateMeta(keyId, updates) {
|
|
2557
|
-
const existing = this.keys.get(keyId);
|
|
2558
|
-
if (!existing) {
|
|
2559
|
-
throw new Error(`Key not found: ${keyId}`);
|
|
2560
|
-
}
|
|
2561
|
-
this.keys.set(keyId, {
|
|
2562
|
-
keypair: existing.keypair,
|
|
2563
|
-
meta: { ...existing.meta, ...updates }
|
|
2564
|
-
});
|
|
2565
|
-
}
|
|
2566
|
-
/**
|
|
2567
|
-
* Clear all keys (testing only).
|
|
2568
|
-
*/
|
|
2569
|
-
clear() {
|
|
2570
|
-
this.keys.clear();
|
|
2571
|
-
}
|
|
2572
|
-
};
|
|
2573
|
-
var KeyRegistry = class {
|
|
2574
|
-
constructor(storage = new InMemoryKeyStorage()) {
|
|
2575
|
-
__publicField(this, "storage");
|
|
2576
|
-
this.storage = storage;
|
|
2577
|
-
}
|
|
2578
|
-
/**
|
|
2579
|
-
* Register a new keypair with metadata.
|
|
2580
|
-
*/
|
|
2581
|
-
async registerKey(keyId, keypair, suiteId, options = {}) {
|
|
2582
|
-
const meta = {
|
|
2583
|
-
keyId,
|
|
2584
|
-
suiteId,
|
|
2585
|
-
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2586
|
-
expiresAt: options.expiresAt,
|
|
2587
|
-
usage: options.usage || ["signing"],
|
|
2588
|
-
cryptoProfileVersion: options.cryptoProfileVersion || "1.0.0",
|
|
2589
|
-
status: options.status || "active"
|
|
2590
|
-
};
|
|
2591
|
-
await this.storage.store(keyId, keypair, meta);
|
|
2592
|
-
return meta;
|
|
2593
|
-
}
|
|
2594
|
-
/**
|
|
2595
|
-
* Get a keypair and its metadata.
|
|
2596
|
-
*/
|
|
2597
|
-
async getKey(keyId) {
|
|
2598
|
-
return await this.storage.load(keyId);
|
|
2599
|
-
}
|
|
2600
|
-
/**
|
|
2601
|
-
* Get only the public key (no private key).
|
|
2602
|
-
*/
|
|
2603
|
-
async getPublicKey(keyId) {
|
|
2604
|
-
const result = await this.storage.load(keyId);
|
|
2605
|
-
if (!result)
|
|
2606
|
-
return null;
|
|
2607
|
-
return {
|
|
2608
|
-
publicKey: result.keypair.publicKey,
|
|
2609
|
-
meta: result.meta
|
|
2610
|
-
};
|
|
2611
|
-
}
|
|
2612
|
-
/**
|
|
2613
|
-
* List all keys matching optional filter.
|
|
2614
|
-
*/
|
|
2615
|
-
async listKeys(filter) {
|
|
2616
|
-
return await this.storage.list(filter);
|
|
2617
|
-
}
|
|
2618
|
-
/**
|
|
2619
|
-
* List only active, non-expired keys.
|
|
2620
|
-
*/
|
|
2621
|
-
async listActiveKeys(filter) {
|
|
2622
|
-
const allKeys = await this.storage.list(filter);
|
|
2623
|
-
const now = /* @__PURE__ */ new Date();
|
|
2624
|
-
return allKeys.filter((meta) => {
|
|
2625
|
-
if (meta.status && meta.status !== "active") {
|
|
2626
|
-
return false;
|
|
2627
|
-
}
|
|
2628
|
-
if (meta.expiresAt && new Date(meta.expiresAt) < now) {
|
|
2629
|
-
return false;
|
|
2630
|
-
}
|
|
2631
|
-
return true;
|
|
2632
|
-
});
|
|
2633
|
-
}
|
|
2634
|
-
/**
|
|
2635
|
-
* Rotate a key: generate new keypair, mark old as 'rotated'.
|
|
2636
|
-
*
|
|
2637
|
-
* Returns the new key's metadata.
|
|
2638
|
-
*/
|
|
2639
|
-
async rotateKey(oldKeyId, newKeyId, newKeypair) {
|
|
2640
|
-
const oldKey = await this.storage.load(oldKeyId);
|
|
2641
|
-
if (!oldKey) {
|
|
2642
|
-
throw new Error(`Cannot rotate: key not found: ${oldKeyId}`);
|
|
2643
|
-
}
|
|
2644
|
-
await this.storage.updateMeta(oldKeyId, {
|
|
2645
|
-
status: "rotated"
|
|
2646
|
-
});
|
|
2647
|
-
await this.registerKey(newKeyId, newKeypair, oldKey.meta.suiteId, {
|
|
2648
|
-
usage: oldKey.meta.usage,
|
|
2649
|
-
cryptoProfileVersion: oldKey.meta.cryptoProfileVersion,
|
|
2650
|
-
expiresAt: oldKey.meta.expiresAt,
|
|
2651
|
-
status: "active"
|
|
2652
|
-
});
|
|
2653
|
-
await this.storage.updateMeta(newKeyId, {
|
|
2654
|
-
rotatedFrom: oldKeyId
|
|
2655
|
-
});
|
|
2656
|
-
const result = await this.storage.load(newKeyId);
|
|
2657
|
-
return result.meta;
|
|
2658
|
-
}
|
|
2659
|
-
/**
|
|
2660
|
-
* Revoke a key (marks as unusable, but doesn't delete).
|
|
2661
|
-
*/
|
|
2662
|
-
async revokeKey(keyId, reason) {
|
|
2663
|
-
await this.storage.updateMeta(keyId, {
|
|
2664
|
-
status: "revoked",
|
|
2665
|
-
revokedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
2666
|
-
});
|
|
2667
|
-
}
|
|
2668
|
-
/**
|
|
2669
|
-
* Delete a key permanently (use with caution).
|
|
2670
|
-
*/
|
|
2671
|
-
async deleteKey(keyId) {
|
|
2672
|
-
await this.storage.delete(keyId);
|
|
2673
|
-
}
|
|
2674
|
-
/**
|
|
2675
|
-
* Mark expired keys as 'expired' status.
|
|
2676
|
-
* Returns count of keys marked expired.
|
|
2677
|
-
*/
|
|
2678
|
-
async markExpiredKeys() {
|
|
2679
|
-
const allKeys = await this.storage.list();
|
|
2680
|
-
const now = /* @__PURE__ */ new Date();
|
|
2681
|
-
let count = 0;
|
|
2682
|
-
for (const meta of allKeys) {
|
|
2683
|
-
if (meta.expiresAt && new Date(meta.expiresAt) < now && meta.status === "active") {
|
|
2684
|
-
await this.storage.updateMeta(meta.keyId, {
|
|
2685
|
-
status: "expired"
|
|
2686
|
-
});
|
|
2687
|
-
count++;
|
|
2688
|
-
}
|
|
2689
|
-
}
|
|
2690
|
-
return count;
|
|
2691
|
-
}
|
|
2692
|
-
/**
|
|
2693
|
-
* Cleanup: delete keys that have been revoked/expired for longer than retention period.
|
|
2694
|
-
*
|
|
2695
|
-
* @param retentionDays How many days to keep revoked/expired keys (default: 90)
|
|
2696
|
-
*/
|
|
2697
|
-
async pruneOldKeys(retentionDays = 90) {
|
|
2698
|
-
const allKeys = await this.storage.list();
|
|
2699
|
-
const cutoffDate = /* @__PURE__ */ new Date();
|
|
2700
|
-
cutoffDate.setDate(cutoffDate.getDate() - retentionDays);
|
|
2701
|
-
let count = 0;
|
|
2702
|
-
for (const meta of allKeys) {
|
|
2703
|
-
const shouldPrune = meta.status === "revoked" && meta.revokedAt && new Date(meta.revokedAt) < cutoffDate || meta.status === "expired" && meta.expiresAt && new Date(meta.expiresAt) < cutoffDate;
|
|
2704
|
-
if (shouldPrune) {
|
|
2705
|
-
await this.storage.delete(meta.keyId);
|
|
2706
|
-
count++;
|
|
2707
|
-
}
|
|
2708
|
-
}
|
|
2709
|
-
return count;
|
|
2710
|
-
}
|
|
2711
|
-
};
|
|
2712
|
-
|
|
2713
|
-
// ../crypto/dist/esm/errors.js
|
|
2714
|
-
init_esbuild_shims();
|
|
2715
|
-
|
|
2716
|
-
// ../crypto/dist/esm/stateless.js
|
|
2717
|
-
init_esbuild_shims();
|
|
2718
2438
|
|
|
2719
2439
|
// ../crypto/dist/esm/suites/bsv-ecdsa.js
|
|
2720
2440
|
init_esbuild_shims();
|
|
@@ -2738,12 +2458,12 @@ var LumenKeys = (() => {
|
|
|
2738
2458
|
};
|
|
2739
2459
|
var isBig = (n2) => typeof n2 === "bigint";
|
|
2740
2460
|
var isStr = (s2) => typeof s2 === "string";
|
|
2741
|
-
var
|
|
2742
|
-
var
|
|
2461
|
+
var isBytes = (a2) => a2 instanceof Uint8Array || ArrayBuffer.isView(a2) && a2.constructor.name === "Uint8Array";
|
|
2462
|
+
var abytes = (a2, l2) => !isBytes(a2) || typeof l2 === "number" && l2 > 0 && a2.length !== l2 ? err("Uint8Array expected") : a2;
|
|
2743
2463
|
var u8n = (len) => new Uint8Array(len);
|
|
2744
2464
|
var u8fr = (buf) => Uint8Array.from(buf);
|
|
2745
2465
|
var padh = (n2, pad) => n2.toString(16).padStart(pad, "0");
|
|
2746
|
-
var
|
|
2466
|
+
var bytesToHex = (b2) => Array.from(abytes(b2)).map((e2) => padh(e2, 2)).join("");
|
|
2747
2467
|
var C2 = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 };
|
|
2748
2468
|
var _ch = (ch) => {
|
|
2749
2469
|
if (ch >= C2._0 && ch <= C2._9)
|
|
@@ -2754,7 +2474,7 @@ var LumenKeys = (() => {
|
|
|
2754
2474
|
return ch - (C2.a - 10);
|
|
2755
2475
|
return;
|
|
2756
2476
|
};
|
|
2757
|
-
var
|
|
2477
|
+
var hexToBytes = (hex) => {
|
|
2758
2478
|
const e2 = "hex invalid";
|
|
2759
2479
|
if (!isStr(hex))
|
|
2760
2480
|
return err(e2);
|
|
@@ -2772,11 +2492,11 @@ var LumenKeys = (() => {
|
|
|
2772
2492
|
}
|
|
2773
2493
|
return array;
|
|
2774
2494
|
};
|
|
2775
|
-
var toU8 = (a2, len) =>
|
|
2495
|
+
var toU8 = (a2, len) => abytes(isStr(a2) ? hexToBytes(a2) : u8fr(abytes(a2)), len);
|
|
2776
2496
|
var cr = () => globalThis?.crypto;
|
|
2777
2497
|
var subtle = () => cr()?.subtle ?? err("crypto.subtle must be defined");
|
|
2778
2498
|
var concatBytes = (...arrs) => {
|
|
2779
|
-
const r2 = u8n(arrs.reduce((sum, a2) => sum +
|
|
2499
|
+
const r2 = u8n(arrs.reduce((sum, a2) => sum + abytes(a2).length, 0));
|
|
2780
2500
|
let pad = 0;
|
|
2781
2501
|
arrs.forEach((a2) => {
|
|
2782
2502
|
r2.set(a2, pad);
|
|
@@ -2842,7 +2562,7 @@ var LumenKeys = (() => {
|
|
|
2842
2562
|
}
|
|
2843
2563
|
/** Convert Uint8Array or hex string to Point. */
|
|
2844
2564
|
static fromBytes(bytes) {
|
|
2845
|
-
|
|
2565
|
+
abytes(bytes);
|
|
2846
2566
|
let p2 = void 0;
|
|
2847
2567
|
const head = bytes[0];
|
|
2848
2568
|
const tail = bytes.subarray(1);
|
|
@@ -2991,7 +2711,7 @@ var LumenKeys = (() => {
|
|
|
2991
2711
|
return x2 === 0n && y2 === 0n ? I2 : new _Point(x2, y2, 1n);
|
|
2992
2712
|
}
|
|
2993
2713
|
toHex(isCompressed) {
|
|
2994
|
-
return
|
|
2714
|
+
return bytesToHex(this.toBytes(isCompressed));
|
|
2995
2715
|
}
|
|
2996
2716
|
static fromPrivateKey(k2) {
|
|
2997
2717
|
return G2.multiply(toPrivScalar(k2));
|
|
@@ -3019,10 +2739,10 @@ var LumenKeys = (() => {
|
|
|
3019
2739
|
var doubleScalarMulUns = (R2, u1, u2) => {
|
|
3020
2740
|
return G2.multiply(u1, false).add(R2.multiply(u2, false)).assertValidity();
|
|
3021
2741
|
};
|
|
3022
|
-
var bytesToNumBE = (b2) => big("0x" + (
|
|
2742
|
+
var bytesToNumBE = (b2) => big("0x" + (bytesToHex(b2) || "0"));
|
|
3023
2743
|
var sliceBytesNumBE = (b2, from, to) => bytesToNumBE(b2.subarray(from, to));
|
|
3024
2744
|
var B256 = 2n ** 256n;
|
|
3025
|
-
var numTo32b = (num) =>
|
|
2745
|
+
var numTo32b = (num) => hexToBytes(padh(arange(num, 0n, B256), L22));
|
|
3026
2746
|
var toPrivScalar = (pr) => {
|
|
3027
2747
|
const num = isBig(pr) ? pr : bytesToNumBE(toU8(pr, L2));
|
|
3028
2748
|
return arange(num, 1n, N2, "private key invalid 3");
|
|
@@ -3044,7 +2764,7 @@ var LumenKeys = (() => {
|
|
|
3044
2764
|
}
|
|
3045
2765
|
/** Create signature from 64b compact (r || s) representation. */
|
|
3046
2766
|
static fromBytes(b2) {
|
|
3047
|
-
|
|
2767
|
+
abytes(b2, L22);
|
|
3048
2768
|
const r2 = sliceBytesNumBE(b2, 0, L2);
|
|
3049
2769
|
const s2 = sliceBytesNumBE(b2, L2, L22);
|
|
3050
2770
|
return new _Signature(r2, s2);
|
|
@@ -3064,7 +2784,7 @@ var LumenKeys = (() => {
|
|
|
3064
2784
|
return this.toBytes();
|
|
3065
2785
|
}
|
|
3066
2786
|
toCompactHex() {
|
|
3067
|
-
return
|
|
2787
|
+
return bytesToHex(this.toBytes());
|
|
3068
2788
|
}
|
|
3069
2789
|
recoverPublicKey(msg) {
|
|
3070
2790
|
return recoverPublicKey(this, msg);
|
|
@@ -3087,7 +2807,7 @@ var LumenKeys = (() => {
|
|
|
3087
2807
|
const num = bytesToNumBE(bytes);
|
|
3088
2808
|
return delta > 0 ? num >> big(delta) : num;
|
|
3089
2809
|
};
|
|
3090
|
-
var bits2int_modN = (bytes) => modN(bits2int(
|
|
2810
|
+
var bits2int_modN = (bytes) => modN(bits2int(abytes(bytes)));
|
|
3091
2811
|
var signOpts = { lowS: true };
|
|
3092
2812
|
var veriOpts = { lowS: true };
|
|
3093
2813
|
var prepSig = (msgh, priv, opts = signOpts) => {
|
|
@@ -3247,8 +2967,8 @@ var LumenKeys = (() => {
|
|
|
3247
2967
|
var randomPrivateKey = () => hashToPrivateKey(randomBytes(L2 + 16));
|
|
3248
2968
|
var _sha = "SHA-256";
|
|
3249
2969
|
var etc = {
|
|
3250
|
-
hexToBytes
|
|
3251
|
-
bytesToHex
|
|
2970
|
+
hexToBytes,
|
|
2971
|
+
bytesToHex,
|
|
3252
2972
|
concatBytes,
|
|
3253
2973
|
bytesToNumberBE: bytesToNumBE,
|
|
3254
2974
|
numberToBytesBE: numTo32b,
|
|
@@ -3340,15 +3060,15 @@ var LumenKeys = (() => {
|
|
|
3340
3060
|
|
|
3341
3061
|
// ../../node_modules/@noble/hashes/esm/utils.js
|
|
3342
3062
|
init_esbuild_shims();
|
|
3343
|
-
function
|
|
3063
|
+
function isBytes2(a2) {
|
|
3344
3064
|
return a2 instanceof Uint8Array || ArrayBuffer.isView(a2) && a2.constructor.name === "Uint8Array";
|
|
3345
3065
|
}
|
|
3346
|
-
function
|
|
3066
|
+
function anumber(n2) {
|
|
3347
3067
|
if (!Number.isSafeInteger(n2) || n2 < 0)
|
|
3348
3068
|
throw new Error("positive integer expected, got " + n2);
|
|
3349
3069
|
}
|
|
3350
|
-
function
|
|
3351
|
-
if (!
|
|
3070
|
+
function abytes2(b2, ...lengths) {
|
|
3071
|
+
if (!isBytes2(b2))
|
|
3352
3072
|
throw new Error("Uint8Array expected");
|
|
3353
3073
|
if (lengths.length > 0 && !lengths.includes(b2.length))
|
|
3354
3074
|
throw new Error("Uint8Array expected of length " + lengths + ", got length=" + b2.length);
|
|
@@ -3356,31 +3076,31 @@ var LumenKeys = (() => {
|
|
|
3356
3076
|
function ahash(h2) {
|
|
3357
3077
|
if (typeof h2 !== "function" || typeof h2.create !== "function")
|
|
3358
3078
|
throw new Error("Hash should be wrapped by utils.createHasher");
|
|
3359
|
-
|
|
3360
|
-
|
|
3079
|
+
anumber(h2.outputLen);
|
|
3080
|
+
anumber(h2.blockLen);
|
|
3361
3081
|
}
|
|
3362
|
-
function
|
|
3082
|
+
function aexists(instance, checkFinished = true) {
|
|
3363
3083
|
if (instance.destroyed)
|
|
3364
3084
|
throw new Error("Hash instance has been destroyed");
|
|
3365
3085
|
if (checkFinished && instance.finished)
|
|
3366
3086
|
throw new Error("Hash#digest() has already been called");
|
|
3367
3087
|
}
|
|
3368
|
-
function
|
|
3369
|
-
|
|
3088
|
+
function aoutput(out, instance) {
|
|
3089
|
+
abytes2(out);
|
|
3370
3090
|
const min = instance.outputLen;
|
|
3371
3091
|
if (out.length < min) {
|
|
3372
3092
|
throw new Error("digestInto() expects output buffer of length at least " + min);
|
|
3373
3093
|
}
|
|
3374
3094
|
}
|
|
3375
|
-
function
|
|
3095
|
+
function clean(...arrays) {
|
|
3376
3096
|
for (let i2 = 0; i2 < arrays.length; i2++) {
|
|
3377
3097
|
arrays[i2].fill(0);
|
|
3378
3098
|
}
|
|
3379
3099
|
}
|
|
3380
|
-
function
|
|
3100
|
+
function createView(arr) {
|
|
3381
3101
|
return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
3382
3102
|
}
|
|
3383
|
-
function
|
|
3103
|
+
function rotr(word, shift) {
|
|
3384
3104
|
return word << 32 - shift | word >>> shift;
|
|
3385
3105
|
}
|
|
3386
3106
|
function utf8ToBytes(str) {
|
|
@@ -3391,12 +3111,12 @@ var LumenKeys = (() => {
|
|
|
3391
3111
|
function toBytes(data) {
|
|
3392
3112
|
if (typeof data === "string")
|
|
3393
3113
|
data = utf8ToBytes(data);
|
|
3394
|
-
|
|
3114
|
+
abytes2(data);
|
|
3395
3115
|
return data;
|
|
3396
3116
|
}
|
|
3397
3117
|
var Hash = class {
|
|
3398
3118
|
};
|
|
3399
|
-
function
|
|
3119
|
+
function createHasher(hashCons) {
|
|
3400
3120
|
const hashC = (msg) => hashCons().update(toBytes(msg)).digest();
|
|
3401
3121
|
const tmp = hashCons();
|
|
3402
3122
|
hashC.outputLen = tmp.outputLen;
|
|
@@ -3428,16 +3148,16 @@ var LumenKeys = (() => {
|
|
|
3428
3148
|
for (let i2 = 0; i2 < pad.length; i2++)
|
|
3429
3149
|
pad[i2] ^= 54 ^ 92;
|
|
3430
3150
|
this.oHash.update(pad);
|
|
3431
|
-
|
|
3151
|
+
clean(pad);
|
|
3432
3152
|
}
|
|
3433
3153
|
update(buf) {
|
|
3434
|
-
|
|
3154
|
+
aexists(this);
|
|
3435
3155
|
this.iHash.update(buf);
|
|
3436
3156
|
return this;
|
|
3437
3157
|
}
|
|
3438
3158
|
digestInto(out) {
|
|
3439
|
-
|
|
3440
|
-
|
|
3159
|
+
aexists(this);
|
|
3160
|
+
abytes2(out, this.outputLen);
|
|
3441
3161
|
this.finished = true;
|
|
3442
3162
|
this.iHash.digestInto(out);
|
|
3443
3163
|
this.oHash.update(out);
|
|
@@ -3493,13 +3213,13 @@ var LumenKeys = (() => {
|
|
|
3493
3213
|
view.setUint32(byteOffset + h2, wh, isLE2);
|
|
3494
3214
|
view.setUint32(byteOffset + l2, wl, isLE2);
|
|
3495
3215
|
}
|
|
3496
|
-
function
|
|
3216
|
+
function Chi(a2, b2, c2) {
|
|
3497
3217
|
return a2 & b2 ^ ~a2 & c2;
|
|
3498
3218
|
}
|
|
3499
|
-
function
|
|
3219
|
+
function Maj(a2, b2, c2) {
|
|
3500
3220
|
return a2 & b2 ^ a2 & c2 ^ b2 & c2;
|
|
3501
3221
|
}
|
|
3502
|
-
var
|
|
3222
|
+
var HashMD = class extends Hash {
|
|
3503
3223
|
constructor(blockLen, outputLen, padOffset, isLE2) {
|
|
3504
3224
|
super();
|
|
3505
3225
|
this.finished = false;
|
|
@@ -3511,18 +3231,18 @@ var LumenKeys = (() => {
|
|
|
3511
3231
|
this.padOffset = padOffset;
|
|
3512
3232
|
this.isLE = isLE2;
|
|
3513
3233
|
this.buffer = new Uint8Array(blockLen);
|
|
3514
|
-
this.view =
|
|
3234
|
+
this.view = createView(this.buffer);
|
|
3515
3235
|
}
|
|
3516
3236
|
update(data) {
|
|
3517
|
-
|
|
3237
|
+
aexists(this);
|
|
3518
3238
|
data = toBytes(data);
|
|
3519
|
-
|
|
3239
|
+
abytes2(data);
|
|
3520
3240
|
const { view, buffer, blockLen } = this;
|
|
3521
3241
|
const len = data.length;
|
|
3522
3242
|
for (let pos = 0; pos < len; ) {
|
|
3523
3243
|
const take = Math.min(blockLen - this.pos, len - pos);
|
|
3524
3244
|
if (take === blockLen) {
|
|
3525
|
-
const dataView =
|
|
3245
|
+
const dataView = createView(data);
|
|
3526
3246
|
for (; blockLen <= len - pos; pos += blockLen)
|
|
3527
3247
|
this.process(dataView, pos);
|
|
3528
3248
|
continue;
|
|
@@ -3540,13 +3260,13 @@ var LumenKeys = (() => {
|
|
|
3540
3260
|
return this;
|
|
3541
3261
|
}
|
|
3542
3262
|
digestInto(out) {
|
|
3543
|
-
|
|
3544
|
-
|
|
3263
|
+
aexists(this);
|
|
3264
|
+
aoutput(out, this);
|
|
3545
3265
|
this.finished = true;
|
|
3546
3266
|
const { buffer, view, blockLen, isLE: isLE2 } = this;
|
|
3547
3267
|
let { pos } = this;
|
|
3548
3268
|
buffer[pos++] = 128;
|
|
3549
|
-
|
|
3269
|
+
clean(this.buffer.subarray(pos));
|
|
3550
3270
|
if (this.padOffset > blockLen - pos) {
|
|
3551
3271
|
this.process(view, 0);
|
|
3552
3272
|
pos = 0;
|
|
@@ -3555,7 +3275,7 @@ var LumenKeys = (() => {
|
|
|
3555
3275
|
buffer[i2] = 0;
|
|
3556
3276
|
setBigUint64(view, blockLen - 8, BigInt(this.length * 8), isLE2);
|
|
3557
3277
|
this.process(view, 0);
|
|
3558
|
-
const oview =
|
|
3278
|
+
const oview = createView(out);
|
|
3559
3279
|
const len = this.outputLen;
|
|
3560
3280
|
if (len % 4)
|
|
3561
3281
|
throw new Error("_sha2: outputLen should be aligned to 32bit");
|
|
@@ -3589,7 +3309,7 @@ var LumenKeys = (() => {
|
|
|
3589
3309
|
return this._cloneInto();
|
|
3590
3310
|
}
|
|
3591
3311
|
};
|
|
3592
|
-
var
|
|
3312
|
+
var SHA256_IV = /* @__PURE__ */ Uint32Array.from([
|
|
3593
3313
|
1779033703,
|
|
3594
3314
|
3144134277,
|
|
3595
3315
|
1013904242,
|
|
@@ -3601,7 +3321,7 @@ var LumenKeys = (() => {
|
|
|
3601
3321
|
]);
|
|
3602
3322
|
|
|
3603
3323
|
// ../../node_modules/@noble/hashes/esm/sha2.js
|
|
3604
|
-
var
|
|
3324
|
+
var SHA256_K = /* @__PURE__ */ Uint32Array.from([
|
|
3605
3325
|
1116352408,
|
|
3606
3326
|
1899447441,
|
|
3607
3327
|
3049323471,
|
|
@@ -3667,18 +3387,18 @@ var LumenKeys = (() => {
|
|
|
3667
3387
|
3204031479,
|
|
3668
3388
|
3329325298
|
|
3669
3389
|
]);
|
|
3670
|
-
var
|
|
3671
|
-
var SHA256 = class extends
|
|
3390
|
+
var SHA256_W = /* @__PURE__ */ new Uint32Array(64);
|
|
3391
|
+
var SHA256 = class extends HashMD {
|
|
3672
3392
|
constructor(outputLen = 32) {
|
|
3673
3393
|
super(64, outputLen, 8, false);
|
|
3674
|
-
this.A =
|
|
3675
|
-
this.B =
|
|
3676
|
-
this.C =
|
|
3677
|
-
this.D =
|
|
3678
|
-
this.E =
|
|
3679
|
-
this.F =
|
|
3680
|
-
this.G =
|
|
3681
|
-
this.H =
|
|
3394
|
+
this.A = SHA256_IV[0] | 0;
|
|
3395
|
+
this.B = SHA256_IV[1] | 0;
|
|
3396
|
+
this.C = SHA256_IV[2] | 0;
|
|
3397
|
+
this.D = SHA256_IV[3] | 0;
|
|
3398
|
+
this.E = SHA256_IV[4] | 0;
|
|
3399
|
+
this.F = SHA256_IV[5] | 0;
|
|
3400
|
+
this.G = SHA256_IV[6] | 0;
|
|
3401
|
+
this.H = SHA256_IV[7] | 0;
|
|
3682
3402
|
}
|
|
3683
3403
|
get() {
|
|
3684
3404
|
const { A: A2, B: B2, C: C3, D: D2, E: E2, F: F2, G: G3, H: H2 } = this;
|
|
@@ -3697,20 +3417,20 @@ var LumenKeys = (() => {
|
|
|
3697
3417
|
}
|
|
3698
3418
|
process(view, offset) {
|
|
3699
3419
|
for (let i2 = 0; i2 < 16; i2++, offset += 4)
|
|
3700
|
-
|
|
3420
|
+
SHA256_W[i2] = view.getUint32(offset, false);
|
|
3701
3421
|
for (let i2 = 16; i2 < 64; i2++) {
|
|
3702
|
-
const W15 =
|
|
3703
|
-
const W22 =
|
|
3704
|
-
const s0 =
|
|
3705
|
-
const s1 =
|
|
3706
|
-
|
|
3422
|
+
const W15 = SHA256_W[i2 - 15];
|
|
3423
|
+
const W22 = SHA256_W[i2 - 2];
|
|
3424
|
+
const s0 = rotr(W15, 7) ^ rotr(W15, 18) ^ W15 >>> 3;
|
|
3425
|
+
const s1 = rotr(W22, 17) ^ rotr(W22, 19) ^ W22 >>> 10;
|
|
3426
|
+
SHA256_W[i2] = s1 + SHA256_W[i2 - 7] + s0 + SHA256_W[i2 - 16] | 0;
|
|
3707
3427
|
}
|
|
3708
3428
|
let { A: A2, B: B2, C: C3, D: D2, E: E2, F: F2, G: G3, H: H2 } = this;
|
|
3709
3429
|
for (let i2 = 0; i2 < 64; i2++) {
|
|
3710
|
-
const sigma1 =
|
|
3711
|
-
const T1 = H2 + sigma1 +
|
|
3712
|
-
const sigma0 =
|
|
3713
|
-
const T2 = sigma0 +
|
|
3430
|
+
const sigma1 = rotr(E2, 6) ^ rotr(E2, 11) ^ rotr(E2, 25);
|
|
3431
|
+
const T1 = H2 + sigma1 + Chi(E2, F2, G3) + SHA256_K[i2] + SHA256_W[i2] | 0;
|
|
3432
|
+
const sigma0 = rotr(A2, 2) ^ rotr(A2, 13) ^ rotr(A2, 22);
|
|
3433
|
+
const T2 = sigma0 + Maj(A2, B2, C3) | 0;
|
|
3714
3434
|
H2 = G3;
|
|
3715
3435
|
G3 = F2;
|
|
3716
3436
|
F2 = E2;
|
|
@@ -3731,17 +3451,46 @@ var LumenKeys = (() => {
|
|
|
3731
3451
|
this.set(A2, B2, C3, D2, E2, F2, G3, H2);
|
|
3732
3452
|
}
|
|
3733
3453
|
roundClean() {
|
|
3734
|
-
|
|
3454
|
+
clean(SHA256_W);
|
|
3735
3455
|
}
|
|
3736
3456
|
destroy() {
|
|
3737
3457
|
this.set(0, 0, 0, 0, 0, 0, 0, 0);
|
|
3738
|
-
|
|
3458
|
+
clean(this.buffer);
|
|
3739
3459
|
}
|
|
3740
3460
|
};
|
|
3741
|
-
var
|
|
3461
|
+
var sha256 = /* @__PURE__ */ createHasher(() => new SHA256());
|
|
3742
3462
|
|
|
3743
3463
|
// ../../node_modules/@noble/hashes/esm/sha256.js
|
|
3744
|
-
var
|
|
3464
|
+
var sha2562 = sha256;
|
|
3465
|
+
|
|
3466
|
+
// ../crypto/dist/esm/utils.js
|
|
3467
|
+
init_esbuild_shims();
|
|
3468
|
+
function bytesToHex2(bytes) {
|
|
3469
|
+
return Array.from(bytes).map((b2) => b2.toString(16).padStart(2, "0")).join("");
|
|
3470
|
+
}
|
|
3471
|
+
function hexToBytes2(hex) {
|
|
3472
|
+
if (hex.length % 2 !== 0) {
|
|
3473
|
+
throw new Error("Hex string must have even length");
|
|
3474
|
+
}
|
|
3475
|
+
const bytes = new Uint8Array(hex.length / 2);
|
|
3476
|
+
for (let i2 = 0; i2 < hex.length; i2 += 2) {
|
|
3477
|
+
bytes[i2 / 2] = parseInt(hex.slice(i2, i2 + 2), 16);
|
|
3478
|
+
}
|
|
3479
|
+
return bytes;
|
|
3480
|
+
}
|
|
3481
|
+
async function hashBytes(bytes, algorithm) {
|
|
3482
|
+
if (algorithm === "sha256") {
|
|
3483
|
+
const crypto = await Promise.resolve().then(() => (init_crypto_browser_shim(), crypto_browser_shim_exports));
|
|
3484
|
+
return new Uint8Array(crypto.createHash("sha256").update(bytes).digest());
|
|
3485
|
+
} else if (algorithm === "sha512") {
|
|
3486
|
+
const crypto = await Promise.resolve().then(() => (init_crypto_browser_shim(), crypto_browser_shim_exports));
|
|
3487
|
+
return new Uint8Array(crypto.createHash("sha512").update(bytes).digest());
|
|
3488
|
+
} else if (algorithm === "sha3-256") {
|
|
3489
|
+
const crypto = await Promise.resolve().then(() => (init_crypto_browser_shim(), crypto_browser_shim_exports));
|
|
3490
|
+
return new Uint8Array(crypto.createHash("sha3-256").update(bytes).digest());
|
|
3491
|
+
}
|
|
3492
|
+
throw new Error(`Unsupported hash algorithm: ${algorithm}`);
|
|
3493
|
+
}
|
|
3745
3494
|
|
|
3746
3495
|
// ../crypto/dist/esm/derivation/bip32.js
|
|
3747
3496
|
init_esbuild_shims();
|
|
@@ -10208,8 +9957,8 @@ zoo`.split("\n");
|
|
|
10208
9957
|
if (compressed) {
|
|
10209
9958
|
payload[33] = 1;
|
|
10210
9959
|
}
|
|
10211
|
-
const hash1 =
|
|
10212
|
-
const hash2 =
|
|
9960
|
+
const hash1 = sha2562(payload);
|
|
9961
|
+
const hash2 = sha2562(hash1);
|
|
10213
9962
|
const checksum2 = hash2.slice(0, 4);
|
|
10214
9963
|
const data = new Uint8Array(payload.length + 4);
|
|
10215
9964
|
data.set(payload);
|
|
@@ -10223,8 +9972,8 @@ zoo`.split("\n");
|
|
|
10223
9972
|
}
|
|
10224
9973
|
const payload = data.slice(0, -4);
|
|
10225
9974
|
const checksum2 = data.slice(-4);
|
|
10226
|
-
const hash1 =
|
|
10227
|
-
const hash2 =
|
|
9975
|
+
const hash1 = sha2562(payload);
|
|
9976
|
+
const hash2 = sha2562(hash1);
|
|
10228
9977
|
const expectedChecksum = hash2.slice(0, 4);
|
|
10229
9978
|
if (!checksum2.every((byte, i2) => byte === expectedChecksum[i2])) {
|
|
10230
9979
|
throw new Error("Invalid WIF checksum");
|
|
@@ -10244,7 +9993,7 @@ zoo`.split("\n");
|
|
|
10244
9993
|
}
|
|
10245
9994
|
|
|
10246
9995
|
// ../crypto/dist/esm/suites/bsv-ecdsa.js
|
|
10247
|
-
etc.hmacSha256Sync = (key, ...msgs) => hmac(
|
|
9996
|
+
etc.hmacSha256Sync = (key, ...msgs) => hmac(sha2562, key, etc.concatBytes(...msgs));
|
|
10248
9997
|
var BsvEcdsaSuite = class {
|
|
10249
9998
|
constructor() {
|
|
10250
9999
|
__publicField(this, "suiteId", "bsv-ecdsa-secp256k1");
|
|
@@ -10277,17 +10026,17 @@ zoo`.split("\n");
|
|
|
10277
10026
|
}
|
|
10278
10027
|
}
|
|
10279
10028
|
exportPublicKey(pub) {
|
|
10280
|
-
return
|
|
10029
|
+
return bytesToHex2(pub);
|
|
10281
10030
|
}
|
|
10282
10031
|
importPublicKey(encoded) {
|
|
10283
|
-
return
|
|
10032
|
+
return hexToBytes2(encoded);
|
|
10284
10033
|
}
|
|
10285
10034
|
exportPrivateKey(priv) {
|
|
10286
10035
|
return encodeWIF(priv, true, "mainnet");
|
|
10287
10036
|
}
|
|
10288
10037
|
importPrivateKey(encoded) {
|
|
10289
10038
|
if (encoded.length === 64) {
|
|
10290
|
-
const bytes =
|
|
10039
|
+
const bytes = hexToBytes2(encoded);
|
|
10291
10040
|
if (bytes.length !== 32) {
|
|
10292
10041
|
throw new Error("Private key must be 32 bytes");
|
|
10293
10042
|
}
|
|
@@ -10353,20 +10102,20 @@ zoo`.split("\n");
|
|
|
10353
10102
|
}
|
|
10354
10103
|
}
|
|
10355
10104
|
exportPublicKey(pub) {
|
|
10356
|
-
return
|
|
10105
|
+
return bytesToHex2(pub);
|
|
10357
10106
|
}
|
|
10358
10107
|
importPublicKey(encoded) {
|
|
10359
|
-
const bytes =
|
|
10108
|
+
const bytes = hexToBytes2(encoded);
|
|
10360
10109
|
if (bytes.length !== this.sizes.publicKey) {
|
|
10361
10110
|
throw new Error(`${this.suiteId} public key must be ${this.sizes.publicKey} bytes, got ${bytes.length}`);
|
|
10362
10111
|
}
|
|
10363
10112
|
return bytes;
|
|
10364
10113
|
}
|
|
10365
10114
|
exportPrivateKey(priv) {
|
|
10366
|
-
return
|
|
10115
|
+
return bytesToHex2(priv);
|
|
10367
10116
|
}
|
|
10368
10117
|
importPrivateKey(encoded) {
|
|
10369
|
-
const bytes =
|
|
10118
|
+
const bytes = hexToBytes2(encoded);
|
|
10370
10119
|
if (bytes.length !== this.sizes.privateKey) {
|
|
10371
10120
|
throw new Error(`${this.suiteId} private key must be ${this.sizes.privateKey} bytes, got ${bytes.length}`);
|
|
10372
10121
|
}
|
|
@@ -10401,6 +10150,263 @@ zoo`.split("\n");
|
|
|
10401
10150
|
}
|
|
10402
10151
|
};
|
|
10403
10152
|
|
|
10153
|
+
// ../crypto/dist/esm/registry.js
|
|
10154
|
+
var SignatureSuiteRegistry = class {
|
|
10155
|
+
constructor() {
|
|
10156
|
+
__publicField(this, "suites", /* @__PURE__ */ new Map());
|
|
10157
|
+
}
|
|
10158
|
+
/**
|
|
10159
|
+
* Register a signature suite implementation
|
|
10160
|
+
*/
|
|
10161
|
+
register(suite) {
|
|
10162
|
+
if (this.suites.has(suite.suiteId)) {
|
|
10163
|
+
throw new Error(`Signature suite already registered: ${suite.suiteId}`);
|
|
10164
|
+
}
|
|
10165
|
+
this.suites.set(suite.suiteId, suite);
|
|
10166
|
+
}
|
|
10167
|
+
/**
|
|
10168
|
+
* Get a signature suite by ID
|
|
10169
|
+
* @throws Error if suite is not registered
|
|
10170
|
+
*/
|
|
10171
|
+
getSuite(suiteId) {
|
|
10172
|
+
const suite = this.suites.get(suiteId);
|
|
10173
|
+
if (!suite) {
|
|
10174
|
+
throw new Error(`Unknown signature suite: ${suiteId}. Available: ${this.listSuites().join(", ")}`);
|
|
10175
|
+
}
|
|
10176
|
+
return suite;
|
|
10177
|
+
}
|
|
10178
|
+
/**
|
|
10179
|
+
* Check if a suite is registered
|
|
10180
|
+
*/
|
|
10181
|
+
hasSuite(suiteId) {
|
|
10182
|
+
return this.suites.has(suiteId);
|
|
10183
|
+
}
|
|
10184
|
+
/**
|
|
10185
|
+
* List all registered suite IDs
|
|
10186
|
+
*/
|
|
10187
|
+
listSuites() {
|
|
10188
|
+
return [...this.suites.keys()];
|
|
10189
|
+
}
|
|
10190
|
+
/**
|
|
10191
|
+
* Get all registered suite objects
|
|
10192
|
+
*/
|
|
10193
|
+
getAllSuites() {
|
|
10194
|
+
return [...this.suites.values()];
|
|
10195
|
+
}
|
|
10196
|
+
/**
|
|
10197
|
+
* Unregister a suite (primarily for testing)
|
|
10198
|
+
*/
|
|
10199
|
+
unregister(suiteId) {
|
|
10200
|
+
return this.suites.delete(suiteId);
|
|
10201
|
+
}
|
|
10202
|
+
/**
|
|
10203
|
+
* Clear all registered suites (primarily for testing)
|
|
10204
|
+
*/
|
|
10205
|
+
clear() {
|
|
10206
|
+
this.suites.clear();
|
|
10207
|
+
}
|
|
10208
|
+
};
|
|
10209
|
+
var globalRegistry = new SignatureSuiteRegistry();
|
|
10210
|
+
globalRegistry.register(new BsvEcdsaSuite());
|
|
10211
|
+
globalRegistry.register(new MlDsa44Suite());
|
|
10212
|
+
globalRegistry.register(new MlDsa65Suite());
|
|
10213
|
+
globalRegistry.register(new MlDsa87Suite());
|
|
10214
|
+
|
|
10215
|
+
// ../crypto/dist/esm/signing.js
|
|
10216
|
+
init_esbuild_shims();
|
|
10217
|
+
|
|
10218
|
+
// ../crypto/dist/esm/key-registry.js
|
|
10219
|
+
init_esbuild_shims();
|
|
10220
|
+
var InMemoryKeyStorage = class {
|
|
10221
|
+
constructor() {
|
|
10222
|
+
__publicField(this, "keys", /* @__PURE__ */ new Map());
|
|
10223
|
+
}
|
|
10224
|
+
async store(keyId, keypair, meta) {
|
|
10225
|
+
this.keys.set(keyId, { keypair, meta });
|
|
10226
|
+
}
|
|
10227
|
+
async load(keyId) {
|
|
10228
|
+
return this.keys.get(keyId) || null;
|
|
10229
|
+
}
|
|
10230
|
+
async list(filter) {
|
|
10231
|
+
const allMeta = Array.from(this.keys.values()).map((k2) => k2.meta);
|
|
10232
|
+
if (!filter) {
|
|
10233
|
+
return allMeta;
|
|
10234
|
+
}
|
|
10235
|
+
return allMeta.filter((meta) => {
|
|
10236
|
+
return Object.entries(filter).every(([key, value]) => {
|
|
10237
|
+
if (key === "usage" && Array.isArray(value)) {
|
|
10238
|
+
return value.some((u2) => meta.usage.includes(u2));
|
|
10239
|
+
}
|
|
10240
|
+
return meta[key] === value;
|
|
10241
|
+
});
|
|
10242
|
+
});
|
|
10243
|
+
}
|
|
10244
|
+
async delete(keyId) {
|
|
10245
|
+
this.keys.delete(keyId);
|
|
10246
|
+
}
|
|
10247
|
+
async updateMeta(keyId, updates) {
|
|
10248
|
+
const existing = this.keys.get(keyId);
|
|
10249
|
+
if (!existing) {
|
|
10250
|
+
throw new Error(`Key not found: ${keyId}`);
|
|
10251
|
+
}
|
|
10252
|
+
this.keys.set(keyId, {
|
|
10253
|
+
keypair: existing.keypair,
|
|
10254
|
+
meta: { ...existing.meta, ...updates }
|
|
10255
|
+
});
|
|
10256
|
+
}
|
|
10257
|
+
/**
|
|
10258
|
+
* Clear all keys (testing only).
|
|
10259
|
+
*/
|
|
10260
|
+
clear() {
|
|
10261
|
+
this.keys.clear();
|
|
10262
|
+
}
|
|
10263
|
+
};
|
|
10264
|
+
var KeyRegistry = class {
|
|
10265
|
+
constructor(storage = new InMemoryKeyStorage()) {
|
|
10266
|
+
__publicField(this, "storage");
|
|
10267
|
+
this.storage = storage;
|
|
10268
|
+
}
|
|
10269
|
+
/**
|
|
10270
|
+
* Register a new keypair with metadata.
|
|
10271
|
+
*/
|
|
10272
|
+
async registerKey(keyId, keypair, suiteId, options = {}) {
|
|
10273
|
+
const meta = {
|
|
10274
|
+
keyId,
|
|
10275
|
+
suiteId,
|
|
10276
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
10277
|
+
expiresAt: options.expiresAt,
|
|
10278
|
+
usage: options.usage || ["signing"],
|
|
10279
|
+
cryptoProfileVersion: options.cryptoProfileVersion || "1.0.0",
|
|
10280
|
+
status: options.status || "active"
|
|
10281
|
+
};
|
|
10282
|
+
await this.storage.store(keyId, keypair, meta);
|
|
10283
|
+
return meta;
|
|
10284
|
+
}
|
|
10285
|
+
/**
|
|
10286
|
+
* Get a keypair and its metadata.
|
|
10287
|
+
*/
|
|
10288
|
+
async getKey(keyId) {
|
|
10289
|
+
return await this.storage.load(keyId);
|
|
10290
|
+
}
|
|
10291
|
+
/**
|
|
10292
|
+
* Get only the public key (no private key).
|
|
10293
|
+
*/
|
|
10294
|
+
async getPublicKey(keyId) {
|
|
10295
|
+
const result = await this.storage.load(keyId);
|
|
10296
|
+
if (!result)
|
|
10297
|
+
return null;
|
|
10298
|
+
return {
|
|
10299
|
+
publicKey: result.keypair.publicKey,
|
|
10300
|
+
meta: result.meta
|
|
10301
|
+
};
|
|
10302
|
+
}
|
|
10303
|
+
/**
|
|
10304
|
+
* List all keys matching optional filter.
|
|
10305
|
+
*/
|
|
10306
|
+
async listKeys(filter) {
|
|
10307
|
+
return await this.storage.list(filter);
|
|
10308
|
+
}
|
|
10309
|
+
/**
|
|
10310
|
+
* List only active, non-expired keys.
|
|
10311
|
+
*/
|
|
10312
|
+
async listActiveKeys(filter) {
|
|
10313
|
+
const allKeys = await this.storage.list(filter);
|
|
10314
|
+
const now = /* @__PURE__ */ new Date();
|
|
10315
|
+
return allKeys.filter((meta) => {
|
|
10316
|
+
if (meta.status && meta.status !== "active") {
|
|
10317
|
+
return false;
|
|
10318
|
+
}
|
|
10319
|
+
if (meta.expiresAt && new Date(meta.expiresAt) < now) {
|
|
10320
|
+
return false;
|
|
10321
|
+
}
|
|
10322
|
+
return true;
|
|
10323
|
+
});
|
|
10324
|
+
}
|
|
10325
|
+
/**
|
|
10326
|
+
* Rotate a key: generate new keypair, mark old as 'rotated'.
|
|
10327
|
+
*
|
|
10328
|
+
* Returns the new key's metadata.
|
|
10329
|
+
*/
|
|
10330
|
+
async rotateKey(oldKeyId, newKeyId, newKeypair) {
|
|
10331
|
+
const oldKey = await this.storage.load(oldKeyId);
|
|
10332
|
+
if (!oldKey) {
|
|
10333
|
+
throw new Error(`Cannot rotate: key not found: ${oldKeyId}`);
|
|
10334
|
+
}
|
|
10335
|
+
await this.storage.updateMeta(oldKeyId, {
|
|
10336
|
+
status: "rotated"
|
|
10337
|
+
});
|
|
10338
|
+
await this.registerKey(newKeyId, newKeypair, oldKey.meta.suiteId, {
|
|
10339
|
+
usage: oldKey.meta.usage,
|
|
10340
|
+
cryptoProfileVersion: oldKey.meta.cryptoProfileVersion,
|
|
10341
|
+
expiresAt: oldKey.meta.expiresAt,
|
|
10342
|
+
status: "active"
|
|
10343
|
+
});
|
|
10344
|
+
await this.storage.updateMeta(newKeyId, {
|
|
10345
|
+
rotatedFrom: oldKeyId
|
|
10346
|
+
});
|
|
10347
|
+
const result = await this.storage.load(newKeyId);
|
|
10348
|
+
return result.meta;
|
|
10349
|
+
}
|
|
10350
|
+
/**
|
|
10351
|
+
* Revoke a key (marks as unusable, but doesn't delete).
|
|
10352
|
+
*/
|
|
10353
|
+
async revokeKey(keyId, reason) {
|
|
10354
|
+
await this.storage.updateMeta(keyId, {
|
|
10355
|
+
status: "revoked",
|
|
10356
|
+
revokedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
10357
|
+
});
|
|
10358
|
+
}
|
|
10359
|
+
/**
|
|
10360
|
+
* Delete a key permanently (use with caution).
|
|
10361
|
+
*/
|
|
10362
|
+
async deleteKey(keyId) {
|
|
10363
|
+
await this.storage.delete(keyId);
|
|
10364
|
+
}
|
|
10365
|
+
/**
|
|
10366
|
+
* Mark expired keys as 'expired' status.
|
|
10367
|
+
* Returns count of keys marked expired.
|
|
10368
|
+
*/
|
|
10369
|
+
async markExpiredKeys() {
|
|
10370
|
+
const allKeys = await this.storage.list();
|
|
10371
|
+
const now = /* @__PURE__ */ new Date();
|
|
10372
|
+
let count = 0;
|
|
10373
|
+
for (const meta of allKeys) {
|
|
10374
|
+
if (meta.expiresAt && new Date(meta.expiresAt) < now && meta.status === "active") {
|
|
10375
|
+
await this.storage.updateMeta(meta.keyId, {
|
|
10376
|
+
status: "expired"
|
|
10377
|
+
});
|
|
10378
|
+
count++;
|
|
10379
|
+
}
|
|
10380
|
+
}
|
|
10381
|
+
return count;
|
|
10382
|
+
}
|
|
10383
|
+
/**
|
|
10384
|
+
* Cleanup: delete keys that have been revoked/expired for longer than retention period.
|
|
10385
|
+
*
|
|
10386
|
+
* @param retentionDays How many days to keep revoked/expired keys (default: 90)
|
|
10387
|
+
*/
|
|
10388
|
+
async pruneOldKeys(retentionDays = 90) {
|
|
10389
|
+
const allKeys = await this.storage.list();
|
|
10390
|
+
const cutoffDate = /* @__PURE__ */ new Date();
|
|
10391
|
+
cutoffDate.setDate(cutoffDate.getDate() - retentionDays);
|
|
10392
|
+
let count = 0;
|
|
10393
|
+
for (const meta of allKeys) {
|
|
10394
|
+
const shouldPrune = meta.status === "revoked" && meta.revokedAt && new Date(meta.revokedAt) < cutoffDate || meta.status === "expired" && meta.expiresAt && new Date(meta.expiresAt) < cutoffDate;
|
|
10395
|
+
if (shouldPrune) {
|
|
10396
|
+
await this.storage.delete(meta.keyId);
|
|
10397
|
+
count++;
|
|
10398
|
+
}
|
|
10399
|
+
}
|
|
10400
|
+
return count;
|
|
10401
|
+
}
|
|
10402
|
+
};
|
|
10403
|
+
|
|
10404
|
+
// ../crypto/dist/esm/errors.js
|
|
10405
|
+
init_esbuild_shims();
|
|
10406
|
+
|
|
10407
|
+
// ../crypto/dist/esm/stateless.js
|
|
10408
|
+
init_esbuild_shims();
|
|
10409
|
+
|
|
10404
10410
|
// src/sdk.ts
|
|
10405
10411
|
var DefaultKeySDK = class {
|
|
10406
10412
|
constructor(config) {
|