iso-signatures 0.4.0 → 0.5.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/src/asn1.d.ts +4 -4
- package/dist/src/asn1.d.ts.map +1 -1
- package/dist/src/signers/ecdsa.d.ts.map +1 -1
- package/dist/src/signers/eddsa.d.ts.map +1 -1
- package/dist/src/signers/es256k.d.ts.map +1 -1
- package/dist/src/utils.d.ts +2 -2
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/verifiers/ecdsa.d.ts.map +1 -1
- package/dist/src/verifiers/eip191.d.ts +2 -3
- package/dist/src/verifiers/eip191.d.ts.map +1 -1
- package/package.json +13 -13
- package/src/asn1.js +0 -11
- package/src/signers/ecdsa.js +6 -3
- package/src/signers/eddsa.js +11 -4
- package/src/signers/es256k.js +3 -5
- package/src/signers/rsa.js +1 -1
- package/src/utils.js +3 -3
- package/src/verifiers/ecdsa.js +5 -8
- package/src/verifiers/eip191.js +14 -15
- package/src/verifiers/rsa.js +2 -2
package/dist/src/asn1.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export const NULL_TAG: 5;
|
|
|
5
5
|
export const OBJECT_TAG: 6;
|
|
6
6
|
export const SEQUENCE_TAG: 48;
|
|
7
7
|
export const UNUSED_BIT_PAD: 0;
|
|
8
|
-
export function encodeDERLength(length: number): Uint8Array
|
|
8
|
+
export function encodeDERLength(length: number): Uint8Array<ArrayBuffer>;
|
|
9
9
|
export function readDERLength(bytes: Uint8Array, offset?: number): {
|
|
10
10
|
number: number;
|
|
11
11
|
consumed: number;
|
|
@@ -23,9 +23,9 @@ export function encodeInt(input: Uint8Array): Uint8Array<ArrayBuffer>;
|
|
|
23
23
|
export function enterSequence(bytes: Uint8Array, offset?: number): number;
|
|
24
24
|
export function skipSequence(bytes: Uint8Array, offset?: number): number;
|
|
25
25
|
export function skipInt(bytes: Uint8Array, offset?: number): number;
|
|
26
|
-
export function readBitString(bytes: Uint8Array, offset?: number): Uint8Array
|
|
27
|
-
export function readInt(bytes: Uint8Array, byteOffset?: number): Uint8Array
|
|
28
|
-
export function readOctetString(bytes: Uint8Array, offset?: number): Uint8Array
|
|
26
|
+
export function readBitString(bytes: Uint8Array, offset?: number): Uint8Array<ArrayBufferLike>;
|
|
27
|
+
export function readInt(bytes: Uint8Array, byteOffset?: number): Uint8Array<ArrayBufferLike>;
|
|
28
|
+
export function readOctetString(bytes: Uint8Array, offset?: number): Uint8Array<ArrayBufferLike>;
|
|
29
29
|
export function readSequenceWith(readers: [Reader, ...Reader[]], source: Uint8Array, byteOffset?: number): Uint8Array<ArrayBufferLike>[];
|
|
30
30
|
export type Reader = (bytes: Uint8Array, offset: number) => Uint8Array;
|
|
31
31
|
//# sourceMappingURL=asn1.d.ts.map
|
package/dist/src/asn1.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asn1.d.ts","sourceRoot":"","sources":["../../src/asn1.js"],"names":[],"mappings":"AAIA,sBAAuB,CAAI,CAAA;AAC3B,4BAA6B,CAAI,CAAA;AACjC,+BAAgC,CAAI,CAAA;AACpC,uBAAwB,CAAI,CAAA;AAC5B,yBAA0B,CAAI,CAAA;AAC9B,2BAA4B,EAAI,CAAA;AAEhC,6BAA8B,CAAI,CAAA;
|
|
1
|
+
{"version":3,"file":"asn1.d.ts","sourceRoot":"","sources":["../../src/asn1.js"],"names":[],"mappings":"AAIA,sBAAuB,CAAI,CAAA;AAC3B,4BAA6B,CAAI,CAAA;AACjC,+BAAgC,CAAI,CAAA;AACpC,uBAAwB,CAAI,CAAA;AAC5B,yBAA0B,CAAI,CAAA;AAC9B,2BAA4B,EAAI,CAAA;AAEhC,6BAA8B,CAAI,CAAA;AAK3B,wCAFI,MAAM,2BAehB;AAMM,qCAHI,UAAU,WACV,MAAM;;;EAsBhB;AAOM,4BAJI,UAAU,eACV,MAAM,YACN,MAAM,UAKhB;AAOM,4BAJI,UAAU,eACV,MAAM,UACN,MAAM;;;EAmBhB;AAKM,uCAFI,UAAU,2BA8BpB;AAKM,yCAFI,UAAU,2BAqBpB;AAKM,yCAFI,UAAU,EAAE,2BAgCtB;AAMM,oCAHI,UAAU,WACV,MAAM,+BAMhB;AAKM,iCAFI,UAAU,2BAkCpB;AAOM,qCAJI,UAAU,WACV,MAAM,UAI2B;AAMrC,oCAHI,UAAU,WACV,MAAM,UAGkB;AAM5B,+BAHI,UAAU,WACV,MAAM,UAEyD;AAKnE,qCAFI,UAAU,gDAiBpB;AAMM,+BAHI,UAAU,eACV,MAAM,+BAgBhB;AAMM,uCAHI,UAAU,WACV,MAAM,+BAMhB;AAQM,0CAJI,CAAC,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC,UACrB,UAAU,eACV,MAAM,iCAYhB;qBAfY,CAAC,KAAK,EAAC,UAAU,EAAE,MAAM,EAAC,MAAM,KAAK,UAAU"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ecdsa.d.ts","sourceRoot":"","sources":["../../../src/signers/ecdsa.js"],"names":[],"mappings":"AAwCA;;;;;GAKG;AACH,yCAHW,MAAM,GACJ;IAAC,IAAI,EAAE,OAAO,CAAC;IAAC,UAAU,EAAE,OAAO,GAAG,OAAO,GAAG,OAAO,CAAC;IAAC,IAAI,EAAE,SAAS,GAAG,SAAS,GAAG,SAAS,CAAA;CAAC,CA8B7G;AAED;;;;GAIG;AACH,gDAFgB,OAAO;IAuBrB;;;;OAIG;IACH,uBAFW,MAAM,wBAkBhB;IAED;;;;;OAKG;IACH,sBAHW,OAAO,eAAe,EAAE,YAAY,QACpC,OAAO,eAAe,EAAE,aAAa,wBA2B/C;IAED;;;;;OAKG;IACH,mBAHW,aAAa,QACb,OAAO,eAAe,EAAE,aAAa,
|
|
1
|
+
{"version":3,"file":"ecdsa.d.ts","sourceRoot":"","sources":["../../../src/signers/ecdsa.js"],"names":[],"mappings":"AAwCA;;;;;GAKG;AACH,yCAHW,MAAM,GACJ;IAAC,IAAI,EAAE,OAAO,CAAC;IAAC,UAAU,EAAE,OAAO,GAAG,OAAO,GAAG,OAAO,CAAC;IAAC,IAAI,EAAE,SAAS,GAAG,SAAS,GAAG,SAAS,CAAA;CAAC,CA8B7G;AAED;;;;GAIG;AACH,gDAFgB,OAAO;IAuBrB;;;;OAIG;IACH,uBAFW,MAAM,wBAkBhB;IAED;;;;;OAKG;IACH,sBAHW,OAAO,eAAe,EAAE,YAAY,QACpC,OAAO,eAAe,EAAE,aAAa,wBA2B/C;IAED;;;;;OAKG;IACH,mBAHW,aAAa,QACb,OAAO,eAAe,EAAE,aAAa,wBA8B/C;IAtGD;;;OAGG;IACH,iBAHW,OAAO,eAAe,EAAE,aAAa,WACrC,aAAa,EAQvB;IAZD,kDAAkD;IAClD,eADW,OAAO,aAAa,EAAE,aAAa,CACjC;IAOX,mCAA+C;IAkGjD;;;;OAIG;IACH,cAFW,UAAU,wCAUpB;IAED;;;;OAIG;IACH,UAFa,aAAa,CAIzB;;CAKF;sBAtNY,OAAO,aAAa,EAAE,OAAO,CAAC,aAAa,CAAC;qBAC5C,OAAO,CAAC,OAAO,eAAe,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,GAAG,OAAO,CAAC;6BACrE,OAAO,CAAC,OAAO,aAAa,EAAE,aAAa,EAAE,OAAO,GAAG,OAAO,GAAG,OAAO,CAAC;oBAPlE,SAAS"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eddsa.d.ts","sourceRoot":"","sources":["../../../src/signers/eddsa.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"eddsa.d.ts","sourceRoot":"","sources":["../../../src/signers/eddsa.js"],"names":[],"mappings":"AAyBA;;;;GAIG;AACH,gDAFgB,OAAO;IAGrB;;;;OAIG;IACH,aAFU,MAAM,CAEI;IAmBpB;;;;OAIG;IACH,wBAFW,UAAU,wBAiBpB;IAED;;;;;OAKG;IACH,uBAHW,MAAM,QACN,OAAO,eAAe,EAAE,aAAa,wBAU/C;IAED;;;;;OAKG;IACH,sBAHW,OAAO,eAAe,EAAE,aAAa,QACrC,OAAO,eAAe,EAAE,aAAa,eAU/C;IA/DD;;;OAGG;IACH,iBAHW,OAAO,eAAe,EAAE,aAAa,cACrC,UAAU,EAOpB;IAZD,kDAAkD;IAClD,eADW,OAAO,aAAa,EAAE,aAAa,CACjC;IAmEb;;;;OAIG;IACH,cAFW,UAAU,2CAIpB;IAED;;OAEG;IACH,iBAEC;;CAKF;sBApHY,OAAO,aAAa,EAAE,OAAO,CAAC,MAAM,CAAC;oBAP9B,SAAS"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"es256k.d.ts","sourceRoot":"","sources":["../../../src/signers/es256k.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"es256k.d.ts","sourceRoot":"","sources":["../../../src/signers/es256k.js"],"names":[],"mappings":"AAoBA;;;;GAIG;AACH,iDAFgB,OAAO;IAGrB;;;;OAIG;IACH,aAFU,MAAM,CAEI;IAoBpB;;;;OAIG;IACH,wBAFW,UAAU,gBAUpB;IAED;;;;;OAKG;IACH,sBAHW,OAAO,eAAe,EAAE,YAAY,QACpC,OAAO,eAAe,EAAE,aAAa,gBAU/C;IAED;;;;;OAKG;IACH,uBAHW,MAAM,QACN,OAAO,eAAe,EAAE,aAAa,gBAU/C;IAzDD;;;;OAIG;IACH,iBAHW,OAAO,eAAe,EAAE,aAAa,cACrC,UAAU,EAOpB;IAhBD,kDAAkD;IAClD,eADW,OAAO,aAAa,EAAE,aAAa,CACjC;IAgEb;;;;OAIG;IACH,cAFW,UAAU,6CAKpB;IAED;;OAEG;IACH,iBAEC;;CAKF;sBA9GY,OAAO,aAAa,EAAE,OAAO,CAAC,MAAM,CAAC;oBAL9B,SAAS"}
|
package/dist/src/utils.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
*
|
|
3
3
|
* @param {import('iso-did/types').KeyType} type
|
|
4
|
-
* @param {
|
|
4
|
+
* @param {Uint8Array} publicKey
|
|
5
5
|
* @param {import('iso-did/types').VerifiableDID} [did]
|
|
6
6
|
*/
|
|
7
|
-
export function didKeyOrVerifiableDID(type: import("iso-did/types").KeyType, publicKey:
|
|
7
|
+
export function didKeyOrVerifiableDID(type: import("iso-did/types").KeyType, publicKey: Uint8Array, did?: import("iso-did/types").VerifiableDID): import("iso-did/types").VerifiableDID;
|
|
8
8
|
//# sourceMappingURL=utils.d.ts.map
|
package/dist/src/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.js"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,4CAJW,OAAO,eAAe,EAAE,OAAO,aAC/B,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.js"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,4CAJW,OAAO,eAAe,EAAE,OAAO,aAC/B,UAAU,QACV,OAAO,eAAe,EAAE,aAAa,yCAqB/C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ecdsa.d.ts","sourceRoot":"","sources":["../../../src/verifiers/ecdsa.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ecdsa.d.ts","sourceRoot":"","sources":["../../../src/verifiers/ecdsa.js"],"names":[],"mappings":"AAyDA;;;;;GAKG;AACH,6BAJW,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,QAAQ,+BACtC,OAAO,aAAa,EAAE,WAAW,oBAK3C;AAhBD,qFAAqF;AACrF,uBADW,OAAO,aAAa,EAAE,QAAQ,CAAC,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,QAAQ,CAAC,CAMhF"}
|
|
@@ -2,11 +2,10 @@
|
|
|
2
2
|
* Convert a 0x signature to a Uint8Array
|
|
3
3
|
*
|
|
4
4
|
* @param {`0x${string}`} signature
|
|
5
|
-
* @returns {Uint8Array}
|
|
6
5
|
*/
|
|
7
|
-
export function hexToBytes(signature: `0x${string}`): Uint8Array
|
|
6
|
+
export function hexToBytes(signature: `0x${string}`): Uint8Array<ArrayBufferLike>;
|
|
8
7
|
/**
|
|
9
|
-
* @param {
|
|
8
|
+
* @param {Uint8Array} data
|
|
10
9
|
*/
|
|
11
10
|
export function getSignPayload(data: Uint8Array): Uint8Array<ArrayBufferLike>;
|
|
12
11
|
export function verify(input: import("../types.js").VerifyInput): Promise<boolean>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eip191.d.ts","sourceRoot":"","sources":["../../../src/verifiers/eip191.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"eip191.d.ts","sourceRoot":"","sources":["../../../src/verifiers/eip191.js"],"names":[],"mappings":"AASA;;;;GAIG;AACH,sCAFW,KAAK,MAAM,EAAE,+BAIvB;AAED;;GAEG;AACH,qCAFW,UAAU,+BAKpB;;AAkBD,oDAAoD;AACpD,uBADW,OAAO,UAAU,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAG/C"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "iso-signatures",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.5.1",
|
|
5
5
|
"description": "Signatures tooling.",
|
|
6
6
|
"author": "Hugo Dias <hugomrdias@gmail.com> (hugodias.me)",
|
|
7
7
|
"license": "MIT",
|
|
@@ -81,23 +81,23 @@
|
|
|
81
81
|
"dist/src/**/*.d.ts.map"
|
|
82
82
|
],
|
|
83
83
|
"dependencies": {
|
|
84
|
-
"@noble/ed25519": "^
|
|
85
|
-
"@noble/hashes": "^
|
|
86
|
-
"@noble/secp256k1": "^
|
|
87
|
-
"ox": "^0.
|
|
88
|
-
"iso-base": "^4.1
|
|
89
|
-
"iso-did": "^2.
|
|
84
|
+
"@noble/ed25519": "^3.0.0",
|
|
85
|
+
"@noble/hashes": "^2.0.0",
|
|
86
|
+
"@noble/secp256k1": "^3.0.0",
|
|
87
|
+
"ox": "^0.9.6",
|
|
88
|
+
"iso-base": "^4.2.1",
|
|
89
|
+
"iso-did": "^2.1.1"
|
|
90
90
|
},
|
|
91
91
|
"devDependencies": {
|
|
92
92
|
"@types/assert": "^1.5.11",
|
|
93
93
|
"@types/mocha": "^10.0.10",
|
|
94
|
-
"@types/node": "^24.
|
|
94
|
+
"@types/node": "^24.5.2",
|
|
95
95
|
"assert": "^2.1.0",
|
|
96
|
-
"mocha": "^11.7.
|
|
97
|
-
"playwright-test": "^14.1.
|
|
98
|
-
"type-fest": "^
|
|
99
|
-
"typescript": "5.
|
|
100
|
-
"viem": "^2.
|
|
96
|
+
"mocha": "^11.7.2",
|
|
97
|
+
"playwright-test": "^14.1.12",
|
|
98
|
+
"type-fest": "^5.0.1",
|
|
99
|
+
"typescript": "5.9.2",
|
|
100
|
+
"viem": "^2.37.6"
|
|
101
101
|
},
|
|
102
102
|
"publishConfig": {
|
|
103
103
|
"provenance": true
|
package/src/asn1.js
CHANGED
|
@@ -13,7 +13,6 @@ export const UNUSED_BIT_PAD = 0x00
|
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* @param {number} length
|
|
16
|
-
* @returns {Uint8Array}
|
|
17
16
|
*/
|
|
18
17
|
export const encodeDERLength = (length) => {
|
|
19
18
|
if (length <= 127) {
|
|
@@ -33,7 +32,6 @@ export const encodeDERLength = (length) => {
|
|
|
33
32
|
/**
|
|
34
33
|
* @param {Uint8Array} bytes
|
|
35
34
|
* @param {number} offset
|
|
36
|
-
* @returns {{number: number, consumed: number}}
|
|
37
35
|
*/
|
|
38
36
|
export const readDERLength = (bytes, offset = 0) => {
|
|
39
37
|
if ((bytes[offset] & 0x80) === 0) {
|
|
@@ -61,7 +59,6 @@ export const readDERLength = (bytes, offset = 0) => {
|
|
|
61
59
|
* @param {Uint8Array} input
|
|
62
60
|
* @param {number} expectedTag
|
|
63
61
|
* @param {number} position
|
|
64
|
-
* @returns {number}
|
|
65
62
|
*/
|
|
66
63
|
export const skip = (input, expectedTag, position) => {
|
|
67
64
|
const parsed = into(input, expectedTag, position)
|
|
@@ -72,7 +69,6 @@ export const skip = (input, expectedTag, position) => {
|
|
|
72
69
|
* @param {Uint8Array} input
|
|
73
70
|
* @param {number} expectedTag
|
|
74
71
|
* @param {number} offset
|
|
75
|
-
* @returns {{ position: number, length: number }}
|
|
76
72
|
*/
|
|
77
73
|
export const into = (input, expectedTag, offset) => {
|
|
78
74
|
const actualTag = input[offset]
|
|
@@ -235,7 +231,6 @@ export const encodeInt = (input) => {
|
|
|
235
231
|
/**
|
|
236
232
|
* @param {Uint8Array} bytes
|
|
237
233
|
* @param {number} offset
|
|
238
|
-
* @returns {number}
|
|
239
234
|
*/
|
|
240
235
|
|
|
241
236
|
export const enterSequence = (bytes, offset = 0) =>
|
|
@@ -244,7 +239,6 @@ export const enterSequence = (bytes, offset = 0) =>
|
|
|
244
239
|
/**
|
|
245
240
|
* @param {Uint8Array} bytes
|
|
246
241
|
* @param {number} offset
|
|
247
|
-
* @returns {number}
|
|
248
242
|
*/
|
|
249
243
|
export const skipSequence = (bytes, offset = 0) =>
|
|
250
244
|
skip(bytes, SEQUENCE_TAG, offset)
|
|
@@ -252,14 +246,11 @@ export const skipSequence = (bytes, offset = 0) =>
|
|
|
252
246
|
/**
|
|
253
247
|
* @param {Uint8Array} bytes
|
|
254
248
|
* @param {number} offset
|
|
255
|
-
* @returns {number}
|
|
256
249
|
*/
|
|
257
250
|
export const skipInt = (bytes, offset = 0) => skip(bytes, INT_TAG, offset)
|
|
258
251
|
|
|
259
252
|
/**
|
|
260
253
|
* @param {Uint8Array} bytes
|
|
261
|
-
* @param {number} offset
|
|
262
|
-
* @returns {Uint8Array}
|
|
263
254
|
*/
|
|
264
255
|
export const readBitString = (bytes, offset = 0) => {
|
|
265
256
|
const { position, length } = into(bytes, BITSTRING_TAG, offset)
|
|
@@ -281,7 +272,6 @@ export const readBitString = (bytes, offset = 0) => {
|
|
|
281
272
|
/**
|
|
282
273
|
* @param {Uint8Array} bytes
|
|
283
274
|
* @param {number} byteOffset
|
|
284
|
-
* @returns {Uint8Array}
|
|
285
275
|
*/
|
|
286
276
|
export const readInt = (bytes, byteOffset = 0) => {
|
|
287
277
|
const { position, length } = into(bytes, INT_TAG, byteOffset)
|
|
@@ -302,7 +292,6 @@ export const readInt = (bytes, byteOffset = 0) => {
|
|
|
302
292
|
/**
|
|
303
293
|
* @param {Uint8Array} bytes
|
|
304
294
|
* @param {number} offset
|
|
305
|
-
* @returns {Uint8Array}
|
|
306
295
|
*/
|
|
307
296
|
export const readOctetString = (bytes, offset = 0) => {
|
|
308
297
|
const { position, length } = into(bytes, OCTET_STRING_TAG, offset)
|
package/src/signers/ecdsa.js
CHANGED
|
@@ -150,7 +150,7 @@ export class ECDSASigner extends DID {
|
|
|
150
150
|
|
|
151
151
|
const publicKey = await webcrypto.subtle.exportKey('raw', publicKeyJWK)
|
|
152
152
|
|
|
153
|
-
return new ECDSASigner(didKeyOrVerifiableDID(type, publicKey, did), {
|
|
153
|
+
return new ECDSASigner(didKeyOrVerifiableDID(type, u8(publicKey), did), {
|
|
154
154
|
privateKey,
|
|
155
155
|
publicKey: publicKeyJWK,
|
|
156
156
|
})
|
|
@@ -186,7 +186,10 @@ export class ECDSASigner extends DID {
|
|
|
186
186
|
}
|
|
187
187
|
}
|
|
188
188
|
|
|
189
|
-
return new ECDSASigner(
|
|
189
|
+
return new ECDSASigner(
|
|
190
|
+
didKeyOrVerifiableDID(curve, u8(publicKey), did),
|
|
191
|
+
key
|
|
192
|
+
)
|
|
190
193
|
}
|
|
191
194
|
|
|
192
195
|
/**
|
|
@@ -198,7 +201,7 @@ export class ECDSASigner extends DID {
|
|
|
198
201
|
const buf = await webcrypto.subtle.sign(
|
|
199
202
|
this.#params,
|
|
200
203
|
this.#keypair.privateKey,
|
|
201
|
-
message
|
|
204
|
+
/** @type {BufferSource} */ (message)
|
|
202
205
|
)
|
|
203
206
|
|
|
204
207
|
return u8(buf)
|
package/src/signers/eddsa.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* eslint-disable unicorn/numeric-separators-style */
|
|
2
|
-
import { getPublicKeyAsync,
|
|
2
|
+
import { getPublicKeyAsync, keygenAsync, signAsync } from '@noble/ed25519'
|
|
3
3
|
import { webcrypto } from 'iso-base/crypto'
|
|
4
4
|
import { base64pad, base64url } from 'iso-base/rfc4648'
|
|
5
5
|
import { tag, untag } from 'iso-base/varint'
|
|
@@ -7,7 +7,6 @@ import { DID } from 'iso-did'
|
|
|
7
7
|
import { DIDKey } from 'iso-did/key'
|
|
8
8
|
import { didKeyOrVerifiableDID } from '../utils.js'
|
|
9
9
|
|
|
10
|
-
// @ts-ignore
|
|
11
10
|
if (!globalThis.crypto) globalThis.crypto = webcrypto
|
|
12
11
|
|
|
13
12
|
/**
|
|
@@ -60,8 +59,16 @@ export class EdDSASigner extends DID {
|
|
|
60
59
|
* @param {Uint8Array} [bytes]
|
|
61
60
|
*/
|
|
62
61
|
static async generate(bytes) {
|
|
63
|
-
|
|
64
|
-
|
|
62
|
+
let privateKey
|
|
63
|
+
let publicKey
|
|
64
|
+
if (bytes) {
|
|
65
|
+
privateKey = bytes
|
|
66
|
+
publicKey = await getPublicKeyAsync(privateKey)
|
|
67
|
+
} else {
|
|
68
|
+
const key = await keygenAsync()
|
|
69
|
+
privateKey = key.secretKey
|
|
70
|
+
publicKey = key.publicKey
|
|
71
|
+
}
|
|
65
72
|
return new EdDSASigner(
|
|
66
73
|
DIDKey.fromPublicKey('Ed25519', publicKey),
|
|
67
74
|
privateKey
|
package/src/signers/es256k.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { getPublicKey, signAsync, utils } from '@noble/secp256k1'
|
|
2
2
|
import { base64pad, base64url } from 'iso-base/rfc4648'
|
|
3
|
-
import { u8 } from 'iso-base/utils'
|
|
4
3
|
import { tag, untag } from 'iso-base/varint'
|
|
5
4
|
import { DID } from 'iso-did'
|
|
6
5
|
import { DIDKey } from 'iso-did/key'
|
|
@@ -56,7 +55,7 @@ export class ES256KSigner extends DID {
|
|
|
56
55
|
* @param {Uint8Array} [bytes]
|
|
57
56
|
*/
|
|
58
57
|
static generate(bytes) {
|
|
59
|
-
const privateKey = bytes || utils.
|
|
58
|
+
const privateKey = bytes || utils.randomSecretKey()
|
|
60
59
|
const publicKey = getPublicKey(privateKey)
|
|
61
60
|
|
|
62
61
|
return new ES256KSigner(
|
|
@@ -103,9 +102,8 @@ export class ES256KSigner extends DID {
|
|
|
103
102
|
* @param {Uint8Array} message
|
|
104
103
|
*/
|
|
105
104
|
async sign(message) {
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
return sig.toCompactRawBytes()
|
|
105
|
+
const sig = await signAsync(message, this.#privateKey)
|
|
106
|
+
return sig
|
|
109
107
|
}
|
|
110
108
|
|
|
111
109
|
/**
|
package/src/signers/rsa.js
CHANGED
package/src/utils.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { equals
|
|
1
|
+
import { equals } from 'iso-base/utils'
|
|
2
2
|
import { DIDKey } from 'iso-did/key'
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
*
|
|
6
6
|
* @param {import('iso-did/types').KeyType} type
|
|
7
|
-
* @param {
|
|
7
|
+
* @param {Uint8Array} publicKey
|
|
8
8
|
* @param {import('iso-did/types').VerifiableDID} [did]
|
|
9
9
|
*/
|
|
10
10
|
export function didKeyOrVerifiableDID(type, publicKey, did) {
|
|
11
11
|
/** @type {import('iso-did/types').VerifiableDID} */
|
|
12
|
-
let _did = DIDKey.fromPublicKey(type,
|
|
12
|
+
let _did = DIDKey.fromPublicKey(type, publicKey)
|
|
13
13
|
if (did) {
|
|
14
14
|
if (!equals(did.verifiableDid.publicKey, _did.verifiableDid.publicKey)) {
|
|
15
15
|
throw new Error('Public key mismatch')
|
package/src/verifiers/ecdsa.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { verifyAsync as secpVerify } from '@noble/secp256k1'
|
|
2
2
|
import { webcrypto } from 'iso-base/crypto'
|
|
3
3
|
import { decompress, isCompressed } from 'iso-base/ec-compression'
|
|
4
|
-
import { u8 } from 'iso-base/utils'
|
|
5
4
|
import { createEcdsaParams } from '../signers/ecdsa.js'
|
|
6
5
|
|
|
7
6
|
/**
|
|
@@ -20,7 +19,7 @@ function createVerifier(curve) {
|
|
|
20
19
|
|
|
21
20
|
const key = await webcrypto.subtle.importKey(
|
|
22
21
|
'raw',
|
|
23
|
-
publicKey,
|
|
22
|
+
/** @type {BufferSource} */ (publicKey),
|
|
24
23
|
{ name: params.name, namedCurve: params.namedCurve },
|
|
25
24
|
true,
|
|
26
25
|
['verify']
|
|
@@ -32,8 +31,8 @@ function createVerifier(curve) {
|
|
|
32
31
|
hash: { name: params.hash },
|
|
33
32
|
},
|
|
34
33
|
key,
|
|
35
|
-
signature,
|
|
36
|
-
message
|
|
34
|
+
/** @type {BufferSource} */ (signature),
|
|
35
|
+
/** @type {BufferSource} */ (message)
|
|
37
36
|
)
|
|
38
37
|
}
|
|
39
38
|
|
|
@@ -45,9 +44,7 @@ async function es256kVerify({ signature, message, did }) {
|
|
|
45
44
|
throw new Error('Invalid signature length')
|
|
46
45
|
}
|
|
47
46
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
return secpVerify(signature, u8(hash), did.verifiableDid.publicKey)
|
|
47
|
+
return await secpVerify(signature, message, did.verifiableDid.publicKey)
|
|
51
48
|
}
|
|
52
49
|
|
|
53
50
|
/** @type {import('../types.js').Verifier<'ES256' | 'ES384' | 'ES512' | 'ES256K'>} */
|
package/src/verifiers/eip191.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import { keccak_256 } from '@noble/hashes/sha3'
|
|
2
|
-
import { Signature } from '@noble/secp256k1'
|
|
1
|
+
import { keccak_256 } from '@noble/hashes/sha3.js'
|
|
2
|
+
import { recoverPublicKeyAsync, Signature, verifyAsync } from '@noble/secp256k1'
|
|
3
3
|
import { hex } from 'iso-base/rfc4648'
|
|
4
4
|
import { utf8 } from 'iso-base/utf8'
|
|
5
5
|
import { concat } from 'iso-base/utils'
|
|
6
|
-
import { DIDPkh } from 'iso-did/pkh'
|
|
7
|
-
import * as Address from 'ox/Address'
|
|
8
|
-
import * as PublicKey from 'ox/PublicKey'
|
|
9
6
|
import * as SignatureOx from 'ox/Signature'
|
|
10
7
|
|
|
11
8
|
const PREFIX = '\x19Ethereum Signed Message:\n'
|
|
@@ -14,14 +11,13 @@ const PREFIX = '\x19Ethereum Signed Message:\n'
|
|
|
14
11
|
* Convert a 0x signature to a Uint8Array
|
|
15
12
|
*
|
|
16
13
|
* @param {`0x${string}`} signature
|
|
17
|
-
* @returns {Uint8Array}
|
|
18
14
|
*/
|
|
19
15
|
export function hexToBytes(signature) {
|
|
20
16
|
return hex.decode(signature.slice(2))
|
|
21
17
|
}
|
|
22
18
|
|
|
23
19
|
/**
|
|
24
|
-
* @param {
|
|
20
|
+
* @param {Uint8Array} data
|
|
25
21
|
*/
|
|
26
22
|
export function getSignPayload(data) {
|
|
27
23
|
const prefixBytes = utf8.decode(`${PREFIX}${data.length}`)
|
|
@@ -29,16 +25,19 @@ export function getSignPayload(data) {
|
|
|
29
25
|
}
|
|
30
26
|
|
|
31
27
|
/** @type {import('../types.js').Verify} */
|
|
32
|
-
export function verify({ signature, message
|
|
33
|
-
const
|
|
34
|
-
const
|
|
28
|
+
export async function verify({ signature, message }) {
|
|
29
|
+
const msgHash = getSignPayload(message)
|
|
30
|
+
const sigRecovered = Signature.fromBytes(signature.slice(0, 64))
|
|
35
31
|
.addRecoveryBit(SignatureOx.vToYParity(signature[64]))
|
|
36
|
-
.
|
|
37
|
-
|
|
32
|
+
.toBytes('recovered')
|
|
33
|
+
const pubKey = await recoverPublicKeyAsync(sigRecovered, msgHash, {
|
|
34
|
+
prehash: false,
|
|
35
|
+
})
|
|
38
36
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
37
|
+
return await verifyAsync(sigRecovered, msgHash, pubKey, {
|
|
38
|
+
prehash: false,
|
|
39
|
+
format: 'recovered',
|
|
40
|
+
})
|
|
42
41
|
}
|
|
43
42
|
|
|
44
43
|
/** @type {import('../types').Verifier<'EIP191'>} */
|
package/src/verifiers/rsa.js
CHANGED
|
@@ -14,8 +14,8 @@ export async function verify({ signature, message, did }) {
|
|
|
14
14
|
return await webcrypto.subtle.verify(
|
|
15
15
|
{ name: 'RSASSA-PKCS1-v1_5', saltLength: 128 },
|
|
16
16
|
key,
|
|
17
|
-
signature,
|
|
18
|
-
message
|
|
17
|
+
/** @type {BufferSource} */ (signature),
|
|
18
|
+
/** @type {BufferSource} */ (message)
|
|
19
19
|
)
|
|
20
20
|
}
|
|
21
21
|
|