iso-signatures 0.1.10 → 0.3.0

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.
@@ -1 +1,2 @@
1
+ export {};
1
2
  //# sourceMappingURL=index.d.ts.map
@@ -13,31 +13,28 @@ export class ECDSASigner implements ISigner {
13
13
  /**
14
14
  * Import a signer from a JWK
15
15
  *
16
- * @param {import('../types.js').PrivateKeyJwk} jwk
16
+ * @param {import('iso-did/types').ECJWKPrivate} jwk
17
+ * @param {import('iso-did/types').VerifiableDID} [did]
17
18
  */
18
- static importJwk(jwk: import('../types.js').PrivateKeyJwk): Promise<ECDSASigner>;
19
+ static importJwk(jwk: import('iso-did/types').ECJWKPrivate, did?: import("iso-did/types").VerifiableDID | undefined): Promise<ECDSASigner>;
19
20
  /**
20
21
  * Import a signer from a CryptoKeyPair
21
22
  *
22
23
  * @param {CryptoKeyPair} key
24
+ * @param {import('iso-did/types').VerifiableDID} [did]
23
25
  */
24
- static import(key: CryptoKeyPair): Promise<ECDSASigner>;
26
+ static import(key: CryptoKeyPair, did?: import("iso-did/types").VerifiableDID | undefined): Promise<ECDSASigner>;
25
27
  /**
26
- * @param {ECDSAAlg} alg
27
- * @param {Uint8Array} publicKey
28
+ * @param {import('iso-did/types').VerifiableDID} did
28
29
  * @param {CryptoKeyPair} keypair
29
30
  */
30
- constructor(alg: ECDSAAlg, publicKey: Uint8Array, keypair: CryptoKeyPair);
31
- params: {
32
- name: "ECDSA";
33
- namedCurve: "P-256" | "P-384" | "P-521";
34
- hash: "SHA-256" | "SHA-384" | "SHA-512";
35
- };
36
- keypair: CryptoKeyPair;
31
+ constructor(did: import('iso-did/types').VerifiableDID, keypair: CryptoKeyPair);
32
+ did: `did:${string}:${string}`;
33
+ url: import("iso-did/types").DIDURLObject;
34
+ type: "P-256" | "P-384" | "P-521" | "Ed25519" | "secp256k1" | "RSA";
37
35
  publicKey: Uint8Array;
38
36
  alg: "ES256" | "ES384" | "ES512";
39
- type: "P-256" | "P-384" | "P-521";
40
- did: DIDKey;
37
+ document: import("iso-did/types").DIDDocument;
41
38
  /**
42
39
  * Sign a message
43
40
  *
@@ -50,8 +47,9 @@ export class ECDSASigner implements ISigner {
50
47
  * @returns {CryptoKeyPair}
51
48
  */
52
49
  export(): CryptoKeyPair;
50
+ toString(): string;
51
+ #private;
53
52
  }
54
53
  export type ISigner = import('../types.js').ISigner<CryptoKeyPair>;
55
54
  export type ECDSAAlg = Extract<import('iso-did/types').SignatureAlgorithm, 'ES256' | 'ES384' | 'ES512'>;
56
- import { DIDKey } from 'iso-did/key';
57
55
  //# sourceMappingURL=ecdsa.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ecdsa.d.ts","sourceRoot":"","sources":["../../../src/signers/ecdsa.js"],"names":[],"mappings":"AAqBA;;;;GAIG;AACH;IAeE;;;;OAIG;IACH,qBAFW,QAAQ,wBAelB;IAED;;;;OAIG;IACH,sBAFW,OAAO,aAAa,EAAE,aAAa,wBA0B7C;IAED;;;;OAIG;IACH,mBAFW,aAAa,wBA0BvB;IA9FD;;;;OAIG;IACH,iBAJW,QAAQ,aACR,UAAU,WACV,aAAa,EASvB;IANC;;;;MAAoC;IACpC,uBAAsB;IACtB,sBAA0B;IAC1B,iCAAc;IACd,kCAAkC;IAClC,YAA0D;IAqF5D;;;;OAIG;IACH,cAFW,UAAU,uBAUpB;IAED;;;;OAIG;IACH,UAFa,aAAa,CAIzB;CACF;sBA3IY,OAAO,aAAa,EAAE,OAAO,CAAC,aAAa,CAAC;uBAC5C,QAAQ,OAAO,eAAe,EAAE,kBAAkB,EAAE,OAAO,GAAG,OAAO,GAAG,OAAO,CAAC;uBALxD,aAAa"}
1
+ {"version":3,"file":"ecdsa.d.ts","sourceRoot":"","sources":["../../../src/signers/ecdsa.js"],"names":[],"mappings":"AAoBA;;;;GAIG;AACH;IAqBE;;;;OAIG;IACH,qBAFW,QAAQ,wBAkBlB;IAED;;;;;OAKG;IACH,sBAHW,OAAO,eAAe,EAAE,YAAY,iFA4B9C;IAED;;;;;OAKG;IACH,mBAHW,aAAa,iFA+BvB;IAzGD;;;OAGG;IACH,iBAHW,OAAO,eAAe,EAAE,aAAa,WACrC,aAAa,EAWvB;IARC,+BAAkB;IAClB,0CAAkB;IAClB,oEAAoB;IACpB,sBAA8B;IAC9B,iCAA8B;IAC9B,8CAA4B;IAiG9B;;;;OAIG;IACH,cAFW,UAAU,uBAUpB;IAED;;;;OAIG;IACH,UAFa,aAAa,CAIzB;IAED,mBAEC;;CACF;sBA/JY,OAAO,aAAa,EAAE,OAAO,CAAC,aAAa,CAAC;uBAC5C,QAAQ,OAAO,eAAe,EAAE,kBAAkB,EAAE,OAAO,GAAG,OAAO,GAAG,OAAO,CAAC"}
@@ -1,6 +1,3 @@
1
- /**
2
- * @typedef {import('../types.js').ISigner<string>} ISigner
3
- */
4
1
  /**
5
2
  * EdDSA signer
6
3
  *
@@ -22,19 +19,20 @@ export class EdDSASigner implements ISigner {
22
19
  * Import a signer from a encoded string
23
20
  *
24
21
  * @param {string} encoded
22
+ * @param {import('iso-did/types').VerifiableDID} [did]
25
23
  */
26
- static import(encoded: string): Promise<EdDSASigner>;
24
+ static import(encoded: string, did?: import("iso-did/types").VerifiableDID | undefined): Promise<EdDSASigner>;
27
25
  /**
28
- * @param {Uint8Array} publicKey
26
+ * @param {import('iso-did/types').VerifiableDID} did
29
27
  * @param {Uint8Array} privateKey
30
28
  */
31
- constructor(publicKey: Uint8Array, privateKey: Uint8Array);
32
- privateKey: Uint8Array;
29
+ constructor(did: import('iso-did/types').VerifiableDID, privateKey: Uint8Array);
30
+ did: `did:${string}:${string}`;
31
+ url: import("iso-did/types").DIDURLObject;
32
+ type: "P-256" | "P-384" | "P-521" | "Ed25519" | "secp256k1" | "RSA";
33
33
  publicKey: Uint8Array;
34
- alg: "EdDSA";
35
- type: "Ed25519";
36
- code: number;
37
- did: DIDKey;
34
+ alg: "EdDSA" | "ES256" | "ES384" | "ES512" | "ES256K" | "RS256";
35
+ document: import("iso-did/types").DIDDocument;
38
36
  /**
39
37
  * Sign a message
40
38
  *
@@ -45,7 +43,8 @@ export class EdDSASigner implements ISigner {
45
43
  * Export the signer as a encoded string
46
44
  */
47
45
  export(): string;
46
+ toString(): string;
47
+ #private;
48
48
  }
49
49
  export type ISigner = import('../types.js').ISigner<string>;
50
- import { DIDKey } from 'iso-did/key';
51
50
  //# sourceMappingURL=eddsa.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"eddsa.d.ts","sourceRoot":"","sources":["../../../src/signers/eddsa.js"],"names":[],"mappings":"AAUA;;GAEG;AAEH;;;;GAIG;AACH;IACE,2EAA2E;IAC3E,YADW,QAAQ,OAAO,eAAe,EAAE,kBAAkB,EAAE,OAAO,CAAC,CACnD;IAEpB,kEAAkE;IAClE,aADW,QAAQ,OAAO,eAAe,EAAE,OAAO,EAAE,SAAS,CAAC,CACvC;IAEvB,oBAAoB;IAepB;;;;OAIG;IACH,sEAIC;IAED;;;;OAIG;IACH,uBAFW,MAAM,wBAOhB;IAlCD;;;OAGG;IACH,uBAHW,UAAU,cACV,UAAU,EASpB;IANC,uBAA4B;IAC5B,sBAA0B;IAC1B,aAA0B;IAC1B,gBAA4B;IAC5B,aAA4B;IAC5B,YAAiE;IA0BnE;;;;OAIG;IACH,cAFW,UAAU,uBAIpB;IAED;;OAEG;IACH,iBAEC;CACF;sBApEY,OAAO,aAAa,EAAE,OAAO,CAAC,MAAM,CAAC;uBAN3B,aAAa"}
1
+ {"version":3,"file":"eddsa.d.ts","sourceRoot":"","sources":["../../../src/signers/eddsa.js"],"names":[],"mappings":"AA4BA;;;;GAIG;AACH;IACE,2EAA2E;IAC3E,YADW,QAAQ,OAAO,eAAe,EAAE,kBAAkB,EAAE,OAAO,CAAC,CACnD;IAEpB,kEAAkE;IAClE,aADW,QAAQ,OAAO,eAAe,EAAE,OAAO,EAAE,SAAS,CAAC,CACvC;IAEvB,oBAAoB;IAoBpB;;;;OAIG;IACH,sEAOC;IAED;;;;;OAKG;IACH,uBAHW,MAAM,iFAWhB;IA3CD;;;OAGG;IACH,iBAHW,OAAO,eAAe,EAAE,aAAa,cACrC,UAAU,EAWpB;IAPC,+BAAkB;IAClB,0CAAkB;IAClB,oEAAoB;IACpB,sBAA8B;IAC9B,gEAAkB;IAClB,8CAA4B;IAkC9B;;;;OAIG;IACH,cAFW,UAAU,uBAIpB;IAED;;OAEG;IACH,iBAEC;IAED,mBAEC;;CACF;sBAjGY,OAAO,aAAa,EAAE,OAAO,CAAC,MAAM,CAAC"}
@@ -1,6 +1,3 @@
1
- /**
2
- * @typedef {import('../types.js').ISigner<CryptoKeyPair>} ISigner
3
- */
4
1
  /**
5
2
  * RSA signer
6
3
  *
@@ -19,26 +16,28 @@ export class RSASigner implements ISigner {
19
16
  /**
20
17
  * Import a signer from a JWK
21
18
  *
22
- * @param {import('../types.js').PrivateKeyRSAJwk} jwk
19
+ * @param {import('iso-did/types').RSAJWKPrivate} jwk
20
+ * @param {import('iso-did/types').VerifiableDID} [did]
23
21
  */
24
- static importJwk(jwk: import('../types.js').PrivateKeyRSAJwk): Promise<RSASigner>;
22
+ static importJwk(jwk: import('iso-did/types').RSAJWKPrivate, did?: import("iso-did/types").VerifiableDID | undefined): Promise<RSASigner>;
25
23
  /**
26
24
  * Import a signer from a keypair
27
25
  *
28
26
  * @param {CryptoKeyPair} keypair
27
+ * @param {import('iso-did/types').VerifiableDID} [did]
29
28
  */
30
- static import(keypair: CryptoKeyPair): Promise<RSASigner>;
29
+ static import(keypair: CryptoKeyPair, did?: import("iso-did/types").VerifiableDID | undefined): Promise<RSASigner>;
31
30
  /**
32
- * @param {Uint8Array} publicKey
31
+ * @param {import('iso-did/types').VerifiableDID} did
33
32
  * @param {CryptoKeyPair} keypair
34
33
  */
35
- constructor(publicKey: Uint8Array, keypair: CryptoKeyPair);
36
- keypair: CryptoKeyPair;
34
+ constructor(did: import('iso-did/types').VerifiableDID, keypair: CryptoKeyPair);
35
+ did: `did:${string}:${string}`;
36
+ url: import("iso-did/types").DIDURLObject;
37
+ type: "P-256" | "P-384" | "P-521" | "Ed25519" | "secp256k1" | "RSA";
37
38
  publicKey: Uint8Array;
38
- alg: "RS256";
39
- type: "RSA";
40
- code: number;
41
- did: DIDKey;
39
+ alg: "EdDSA" | "ES256" | "ES384" | "ES512" | "ES256K" | "RS256";
40
+ document: import("iso-did/types").DIDDocument;
42
41
  /**
43
42
  * Sign a message
44
43
  *
@@ -49,7 +48,8 @@ export class RSASigner implements ISigner {
49
48
  * Export the signer as a crypto key pair
50
49
  */
51
50
  export(): CryptoKeyPair;
51
+ toString(): string;
52
+ #private;
52
53
  }
53
54
  export type ISigner = import('../types.js').ISigner<CryptoKeyPair>;
54
- import { DIDKey } from 'iso-did/key';
55
55
  //# sourceMappingURL=rsa.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"rsa.d.ts","sourceRoot":"","sources":["../../../src/signers/rsa.js"],"names":[],"mappings":"AAMA;;GAEG;AAEH;;;;GAIG;AACH;IACE,2EAA2E;IAC3E,YADW,QAAQ,OAAO,eAAe,EAAE,kBAAkB,EAAE,OAAO,CAAC,CACnD;IAEpB,8DAA8D;IAC9D,aADW,QAAQ,OAAO,eAAe,EAAE,OAAO,EAAE,KAAK,CAAC,CACvC;IAGnB,oBAAoB;IAepB;;OAEG;IACH,sCAmBC;IAED;;;;OAIG;IACH,sBAFW,OAAO,aAAa,EAAE,gBAAgB,sBA8BhD;IAED;;;;OAIG;IACH,uBAFW,aAAa,sBASvB;IApFD;;;OAGG;IACH,uBAHW,UAAU,WACV,aAAa,EASvB;IANC,uBAAsB;IACtB,sBAA0B;IAC1B,aAAwB;IACxB,YAA0B;IAC1B,aAA0B;IAC1B,YAA+D;IA4EjE;;;;OAIG;IACH,cAFW,UAAU,uBAUpB;IAED;;OAEG;IACH,wBAEC;CACF;sBA7HY,OAAO,aAAa,EAAE,OAAO,CAAC,aAAa,CAAC;uBAJlC,aAAa"}
1
+ {"version":3,"file":"rsa.d.ts","sourceRoot":"","sources":["../../../src/signers/rsa.js"],"names":[],"mappings":"AAwBA;;;;GAIG;AACH;IACE,2EAA2E;IAC3E,YADW,QAAQ,OAAO,eAAe,EAAE,kBAAkB,EAAE,OAAO,CAAC,CACnD;IAEpB,8DAA8D;IAC9D,aADW,QAAQ,OAAO,eAAe,EAAE,OAAO,EAAE,KAAK,CAAC,CACvC;IAGnB,oBAAoB;IAoBpB;;OAEG;IACH,sCAqBC;IAED;;;;;OAKG;IACH,sBAHW,OAAO,eAAe,EAAE,aAAa,+EAgC/C;IAED;;;;;OAKG;IACH,uBAHW,aAAa,+EAevB;IAhGD;;;OAGG;IACH,iBAHW,OAAO,eAAe,EAAE,aAAa,WACrC,aAAa,EAWvB;IAPC,+BAAkB;IAClB,0CAAkB;IAClB,oEAAoB;IACpB,sBAA8B;IAC9B,gEAAkB;IAClB,8CAA4B;IAuF9B;;;;OAIG;IACH,cAFW,UAAU,uBAUpB;IAED;;OAEG;IACH,wBAEC;IAED,mBAEC;;CACF;sBA7JY,OAAO,aAAa,EAAE,OAAO,CAAC,aAAa,CAAC"}
@@ -1,23 +1,9 @@
1
- import type { DIDKey } from 'iso-did/key';
2
- import type { SignatureAlgorithm, KeyType } from 'iso-did/types';
3
- export interface ISigner<Export extends CryptoKeyPair | string> {
4
- /**
5
- * JWT signing algorithm
6
- */
7
- alg: SignatureAlgorithm;
8
- /**
9
- * Keypair type
10
- */
11
- type: KeyType;
12
- /**
13
- * Multicodec identifier for the private key
14
- */
15
- code?: number;
16
- did: DIDKey;
17
- /**
18
- * Sign a message
19
- */
1
+ import type { SignatureAlgorithm, VerifiableDID } from 'iso-did/types';
2
+ export interface Sign {
20
3
  sign: (message: Uint8Array) => Promise<Uint8Array>;
4
+ }
5
+ export interface ISigner<Export extends CryptoKeyPair | string> extends VerifiableDID, Sign {
6
+ code?: number;
21
7
  export: () => Export;
22
8
  }
23
9
  export interface VerifyInput {
@@ -38,26 +24,4 @@ export interface IResolver {
38
24
  export interface ResolverOptions {
39
25
  cache?: Cache | boolean | undefined;
40
26
  }
41
- export interface PublicKeyJwk {
42
- kty: string;
43
- crv: string;
44
- x: string;
45
- y: string;
46
- }
47
- export interface PublicKeyRSAJwk {
48
- kty: string;
49
- n: string;
50
- e: string;
51
- }
52
- export interface PrivateKeyRSAJwk extends PublicKeyRSAJwk {
53
- d: string;
54
- p: string;
55
- q: string;
56
- dp: string;
57
- dq: string;
58
- qi: string;
59
- }
60
- export type PrivateKeyJwk = PublicKeyJwk & {
61
- d: string;
62
- };
63
27
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,KAAK,EAAE,kBAAkB,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAEhE,MAAM,WAAW,OAAO,CAAC,MAAM,SAAS,aAAa,GAAG,MAAM;IAC5D;;OAEG;IACH,GAAG,EAAE,kBAAkB,CAAA;IACvB;;OAEG;IACH,IAAI,EAAE,OAAO,CAAA;IACb;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAA;IAEb,GAAG,EAAE,MAAM,CAAA;IACX;;OAEG;IACH,IAAI,EAAE,CAAC,OAAO,EAAE,UAAU,KAAK,OAAO,CAAC,UAAU,CAAC,CAAA;IAElD,MAAM,EAAE,MAAM,MAAM,CAAA;CACrB;AAED,MAAM,WAAW,WAAW;IAC1B,SAAS,EAAE,UAAU,CAAA;IACrB,OAAO,EAAE,UAAU,CAAA;IACnB,SAAS,EAAE,UAAU,CAAA;CACtB;AACD,MAAM,MAAM,MAAM,GAAG,CAAC,KAAK,EAAE,WAAW,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;AAE7D,MAAM,MAAM,QAAQ,CAAC,CAAC,SAAS,kBAAkB,IAAI,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,CAAA;AAEtE,MAAM,MAAM,gBAAgB,CAAC,CAAC,SAAS,kBAAkB,IAAI,OAAO,CAClE,QAAQ,CAAC,CAAC,CAAC,CACZ,CAAA;AAED,MAAM,WAAW,mBAAoB,SAAQ,WAAW;IACtD,GAAG,EAAE,kBAAkB,CAAA;CACxB;AACD,MAAM,MAAM,KAAK,GAAG,CAAC,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;AAE7E,MAAM,WAAW,SAAS;IACxB,MAAM,EAAE,CAAC,KAAK,EAAE,mBAAmB,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;CACzD;AAED,MAAM,WAAW,eAAe;IAC9B,KAAK,CAAC,EAAE,KAAK,GAAG,OAAO,GAAG,SAAS,CAAA;CACpC;AAED,MAAM,WAAW,YAAY;IAC3B,GAAG,EAAE,MAAM,CAAA;IACX,GAAG,EAAE,MAAM,CAAA;IACX,CAAC,EAAE,MAAM,CAAA;IACT,CAAC,EAAE,MAAM,CAAA;CACV;AAED,MAAM,WAAW,eAAe;IAC9B,GAAG,EAAE,MAAM,CAAA;IACX,CAAC,EAAE,MAAM,CAAA;IACT,CAAC,EAAE,MAAM,CAAA;CACV;AAED,MAAM,WAAW,gBAAiB,SAAQ,eAAe;IACvD,CAAC,EAAE,MAAM,CAAA;IACT,CAAC,EAAE,MAAM,CAAA;IACT,CAAC,EAAE,MAAM,CAAA;IACT,EAAE,EAAE,MAAM,CAAA;IACV,EAAE,EAAE,MAAM,CAAA;IACV,EAAE,EAAE,MAAM,CAAA;CACX;AAED,MAAM,MAAM,aAAa,GAAG,YAAY,GAAG;IAAE,CAAC,EAAE,MAAM,CAAA;CAAE,CAAA"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAEtE,MAAM,WAAW,IAAI;IACnB,IAAI,EAAE,CAAC,OAAO,EAAE,UAAU,KAAK,OAAO,CAAC,UAAU,CAAC,CAAA;CACnD;AAED,MAAM,WAAW,OAAO,CAAC,MAAM,SAAS,aAAa,GAAG,MAAM,CAC5D,SAAQ,aAAa,EACnB,IAAI;IACN,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,MAAM,CAAA;CACrB;AAED,MAAM,WAAW,WAAW;IAC1B,SAAS,EAAE,UAAU,CAAA;IACrB,OAAO,EAAE,UAAU,CAAA;IACnB,SAAS,EAAE,UAAU,CAAA;CACtB;AACD,MAAM,MAAM,MAAM,GAAG,CAAC,KAAK,EAAE,WAAW,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;AAE7D,MAAM,MAAM,QAAQ,CAAC,CAAC,SAAS,kBAAkB,IAAI,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,CAAA;AAEtE,MAAM,MAAM,gBAAgB,CAAC,CAAC,SAAS,kBAAkB,IAAI,OAAO,CAClE,QAAQ,CAAC,CAAC,CAAC,CACZ,CAAA;AAED,MAAM,WAAW,mBAAoB,SAAQ,WAAW;IACtD,GAAG,EAAE,kBAAkB,CAAA;CACxB;AACD,MAAM,MAAM,KAAK,GAAG,CAAC,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;AAE7E,MAAM,WAAW,SAAS;IACxB,MAAM,EAAE,CAAC,KAAK,EAAE,mBAAmB,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;CACzD;AAED,MAAM,WAAW,eAAe;IAC9B,KAAK,CAAC,EAAE,KAAK,GAAG,OAAO,GAAG,SAAS,CAAA;CACpC"}
@@ -9,4 +9,11 @@ export function createEcdsaParams(alg: import("iso-did/types").SignatureAlgorith
9
9
  namedCurve: 'P-256' | 'P-384' | 'P-521';
10
10
  hash: 'SHA-256' | 'SHA-384' | 'SHA-512';
11
11
  };
12
+ /**
13
+ *
14
+ * @param {import('iso-did/types').KeyType} type
15
+ * @param {BufferSource} publicKey
16
+ * @param {import('iso-did/types').VerifiableDID} [did]
17
+ */
18
+ export function didKeyOrVerifiableDID(type: import('iso-did/types').KeyType, publicKey: BufferSource, did?: import("iso-did/types").VerifiableDID | undefined): import("iso-did/types").VerifiableDID;
12
19
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.js"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,uCAHW,OAAO,eAAe,EAAE,kBAAkB,GACxC;IAAC,MAAM,OAAO,CAAC;IAAC,UAAU,EAAE,OAAO,GAAG,OAAO,GAAG,OAAO,CAAC;IAAC,IAAI,EAAE,SAAS,GAAG,SAAS,GAAG,SAAS,CAAA;CAAC,CA8B7G"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.js"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,uCAHW,OAAO,eAAe,EAAE,kBAAkB,GACxC;IAAC,MAAM,OAAO,CAAC;IAAC,UAAU,EAAE,OAAO,GAAG,OAAO,GAAG,OAAO,CAAC;IAAC,IAAI,EAAE,SAAS,GAAG,SAAS,GAAG,SAAS,CAAA;CAAC,CA8B7G;AAED;;;;;GAKG;AACH,4CAJW,OAAO,eAAe,EAAE,OAAO,aAC/B,YAAY,kGAsBtB"}
@@ -1 +1 @@
1
- {"version":3,"file":"ecdsa.d.ts","sourceRoot":"","sources":["../../../src/verifiers/ecdsa.js"],"names":[],"mappings":"AA+CA;;;;;GAKG;AACH,6BAJW,OAAO,GAAG,OAAO,GAAG,OAAO,qCAC3B,OAAO,aAAa,EAAE,WAAW,oBAK3C;AAfD,0EAA0E;AAC1E,uBADW,OAAO,aAAa,EAAE,QAAQ,CAAC,OAAO,GAAG,OAAO,GAAG,OAAO,CAAC,CAKrE"}
1
+ {"version":3,"file":"ecdsa.d.ts","sourceRoot":"","sources":["../../../src/verifiers/ecdsa.js"],"names":[],"mappings":"AA8CA;;;;;GAKG;AACH,6BAJW,OAAO,GAAG,OAAO,GAAG,OAAO,qCAC3B,OAAO,aAAa,EAAE,WAAW,oBAK3C;AAfD,0EAA0E;AAC1E,uBADW,OAAO,aAAa,EAAE,QAAQ,CAAC,OAAO,GAAG,OAAO,GAAG,OAAO,CAAC,CAKrE"}
@@ -1 +1 @@
1
- {"version":3,"file":"eddsa.d.ts","sourceRoot":"","sources":["../../../src/verifiers/eddsa.js"],"names":[],"mappings":"AAYiQ,gFAAyC;AAJ1S,mDAAmD;AACnD,uBADW,OAAO,UAAU,EAAE,QAAQ,CAAC,OAAO,CAAC,CAG9C"}
1
+ {"version":3,"file":"eddsa.d.ts","sourceRoot":"","sources":["../../../src/verifiers/eddsa.js"],"names":[],"mappings":"AAWsH,gFAAyC;AAJ/J,mDAAmD;AACnD,uBADW,OAAO,UAAU,EAAE,QAAQ,CAAC,OAAO,CAAC,CAG9C"}
@@ -10,9 +10,8 @@ export class Resolver implements IResolver {
10
10
  * @param {import('../types').ResolverOptions} options
11
11
  */
12
12
  constructor(registry?: import('../types').VerifierRegistry<import('iso-did/types').SignatureAlgorithm>, options?: import('../types').ResolverOptions);
13
- registry: Partial<import("../types").Verifier<"EdDSA" | "ES256" | "ES384" | "ES512" | "ES256K" | "RS256" | "RS256_OLD">>;
13
+ registry: Partial<import("../types").Verifier<"EdDSA" | "ES256" | "ES384" | "ES512" | "ES256K" | "RS256">>;
14
14
  cache: import("../types").Cache;
15
- /** @type {IResolver['verify']} */
16
15
  verify(input: import("../types").ResolverVerifyInput): Promise<boolean>;
17
16
  }
18
17
  export type IResolver = import('../types').IResolver;
@@ -1 +1 @@
1
- {"version":3,"file":"resolver.d.ts","sourceRoot":"","sources":["../../../src/verifiers/resolver.js"],"names":[],"mappings":"AAoCA;;;;GAIG;AACH;IACE;;;;OAIG;IACH,uBAHW,OAAO,UAAU,EAAE,gBAAgB,CAAC,OAAO,eAAe,EAAE,kBAAkB,CAAC,YAC/E,OAAO,UAAU,EAAE,eAAe,EAM5C;IAHC,yHAAwB;IACxB,gCACmE;IAGrE,kCAAkC;IAClC,wEAAS;CAQV;wBA7DY,OAAO,UAAU,EAAE,SAAS"}
1
+ {"version":3,"file":"resolver.d.ts","sourceRoot":"","sources":["../../../src/verifiers/resolver.js"],"names":[],"mappings":"AAoCA;;;;GAIG;AACH;IACE;;;;OAIG;IACH,uBAHW,OAAO,UAAU,EAAE,gBAAgB,CAAC,OAAO,eAAe,EAAE,kBAAkB,CAAC,YAC/E,OAAO,UAAU,EAAE,eAAe,EAM5C;IAHC,2GAAwB;IACxB,gCACmE;IALlC,wEAEd;CAetB;wBA7DY,OAAO,UAAU,EAAE,SAAS"}
@@ -1 +1 @@
1
- {"version":3,"file":"rsa.d.ts","sourceRoot":"","sources":["../../../src/verifiers/rsa.js"],"names":[],"mappings":"AAsBoD,mFAExC;AAFZ,sDAAsD;AACtD,uBADW,OAAO,aAAa,EAAE,QAAQ,CAAC,OAAO,CAAC,CAGjD"}
1
+ {"version":3,"file":"rsa.d.ts","sourceRoot":"","sources":["../../../src/verifiers/rsa.js"],"names":[],"mappings":"AAcQ,mFAAyC;AAOjD,sDAAsD;AACtD,uBADW,OAAO,aAAa,EAAE,QAAQ,CAAC,OAAO,CAAC,CAGjD"}
package/package.json CHANGED
@@ -1,14 +1,15 @@
1
1
  {
2
2
  "name": "iso-signatures",
3
- "version": "0.1.10",
3
+ "type": "module",
4
+ "version": "0.3.0",
4
5
  "description": "Signatures tooling.",
5
6
  "author": "Hugo Dias <hugomrdias@gmail.com> (hugodias.me)",
6
7
  "license": "MIT",
8
+ "homepage": "https://github.com/hugomrdias/iso-repo/tree/main/packages/iso-signatures",
7
9
  "repository": {
8
10
  "url": "hugomrdias/iso-repo",
9
11
  "directory": "packages/iso-signatures"
10
12
  },
11
- "homepage": "https://github.com/hugomrdias/iso-repo/tree/main/packages/iso-signatures",
12
13
  "keywords": [
13
14
  "elliptic",
14
15
  "curve",
@@ -25,49 +26,21 @@
25
26
  "rsa",
26
27
  "signatures"
27
28
  ],
28
- "type": "module",
29
- "main": "src/index.js",
30
- "types": "dist/src/index.d.ts",
31
29
  "exports": {
32
30
  ".": {
33
31
  "types": "./dist/src/index.d.ts",
34
32
  "import": "./src/index.js"
35
33
  },
36
- "./signers/ecdsa": {
37
- "types": "./dist/src/signers/ecdsa.d.ts",
38
- "import": "./src/signers/ecdsa.js"
39
- },
40
- "./signers/eddsa": {
41
- "types": "./dist/src/signers/eddsa.d.ts",
42
- "import": "./src/signers/eddsa.js"
43
- },
44
- "./signers/rsa-old": {
45
- "types": "./dist/src/signers/rsa-old.d.ts",
46
- "import": "./src/signers/rsa-old.js"
34
+ "./types": {
35
+ "types": "./dist/src/types.d.ts"
47
36
  },
48
- "./signers/rsa": {
49
- "types": "./dist/src/signers/rsa.d.ts",
50
- "import": "./src/signers/rsa.js"
37
+ "./signers/*": {
38
+ "types": "./dist/src/signers/*",
39
+ "default": "./src/signers/*"
51
40
  },
52
- "./verifiers/ecdsa": {
53
- "types": "./dist/src/verifiers/ecdsa.d.ts",
54
- "import": "./src/verifiers/ecdsa.js"
55
- },
56
- "./verifiers/eddsa": {
57
- "types": "./dist/src/verifiers/eddsa.d.ts",
58
- "import": "./src/verifiers/eddsa.js"
59
- },
60
- "./verifiers/rsa-old": {
61
- "types": "./dist/src/verifiers/rsa-old.d.ts",
62
- "import": "./src/verifiers/rsa-old.js"
63
- },
64
- "./verifiers/rsa": {
65
- "types": "./dist/src/verifiers/rsa.d.ts",
66
- "import": "./src/verifiers/rsa.js"
67
- },
68
- "./verifiers/resolver": {
69
- "types": "./dist/src/verifiers/resolver.d.ts",
70
- "import": "./src/verifiers/resolver.js"
41
+ "./verifiers/*": {
42
+ "types": "./dist/src/verifiers/*",
43
+ "import": "./src/verifiers/*"
71
44
  },
72
45
  "./asn1": {
73
46
  "types": "./dist/src/asn1.d.ts",
@@ -78,11 +51,16 @@
78
51
  "import": "./src/spki.js"
79
52
  }
80
53
  },
54
+ "main": "src/index.js",
55
+ "types": "dist/src/index.d.ts",
81
56
  "typesVersions": {
82
57
  "*": {
83
58
  ".": [
84
59
  "dist/src/index"
85
60
  ],
61
+ "types": [
62
+ "dist/src/types"
63
+ ],
86
64
  "signers/*": [
87
65
  "dist/src/signers/*"
88
66
  ],
@@ -105,18 +83,17 @@
105
83
  "dependencies": {
106
84
  "@noble/ed25519": "^2.0.0",
107
85
  "iso-base": "^2.0.1",
108
- "iso-did": "^1.3.3"
86
+ "iso-did": "^1.5.0"
109
87
  },
110
88
  "devDependencies": {
111
- "@types/assert": "^1.5.6",
112
- "@types/mocha": "^10.0.1",
113
- "@types/node": "^20.5.9",
114
- "assert": "^2.0.0",
115
- "hd-scripts": "^8.0.0",
89
+ "@types/assert": "^1.5.10",
90
+ "@types/mocha": "^10.0.6",
91
+ "@types/node": "^20.10.5",
92
+ "assert": "^2.1.0",
116
93
  "mocha": "^10.2.0",
117
- "playwright-test": "^12.2.0",
118
- "type-fest": "^4.3.1",
119
- "typescript": "5.2.2"
94
+ "playwright-test": "^14.0.0",
95
+ "type-fest": "^4.8.3",
96
+ "typescript": "5.3.3"
120
97
  },
121
98
  "publishConfig": {
122
99
  "provenance": true
@@ -125,9 +102,6 @@
125
102
  "extends": [
126
103
  "../../node_modules/hd-scripts/eslint/index.js"
127
104
  ],
128
- "parserOptions": {
129
- "project": "./tsconfig.json"
130
- },
131
105
  "env": {
132
106
  "mocha": true
133
107
  },
@@ -143,13 +117,14 @@
143
117
  "@types/*",
144
118
  "hd-scripts",
145
119
  "assert",
146
- "type-fest"
120
+ "type-fest",
121
+ "mocha"
147
122
  ]
148
123
  },
149
124
  "scripts": {
150
- "lint": "tsc --build && eslint '**/*.{js,ts}' && prettier --check '**/*.{js,ts,yml,json}' --ignore-path ../../.gitignore",
125
+ "lint": "tsc --build && eslint . && prettier --check '**/*.{js,ts,yml,json}' --ignore-path ../../.gitignore",
151
126
  "test": "tsc --build && pnpm run test:node && pnpm run test:browser",
152
- "test:node": "mocha 'test/**/!(*.browser).test.js'",
153
- "test:browser": "playwright-test 'test/**/!(*.node).test.js'"
127
+ "test:node": "pw-test 'test/**/!(*.browser).test.js' --mode node",
128
+ "test:browser": "pw-test 'test/**/!(*.node).test.js'"
154
129
  }
155
130
  }
package/readme.md CHANGED
@@ -13,6 +13,7 @@ pnpm install iso-signatures
13
13
  ```js
14
14
  import { EdDSASigner } from 'iso-signatures/signers/eddsa'
15
15
  import * as EdDSA from 'iso-signatures/verifiers/eddsa'
16
+ import { Resolver } from 'iso-signatures/verifiers/resolver'
16
17
 
17
18
  const message = new TextEncoder().encode('hello world')
18
19
  const resolver = new Resolver({
@@ -32,6 +33,7 @@ import { EdDSASigner } from 'iso-signatures/signers/eddsa'
32
33
  import * as EdDSA from 'iso-signatures/verifiers/eddsa'
33
34
  import * as ECDSA from 'iso-signatures/verifiers/ecdsa'
34
35
  import * as RSA from 'iso-signatures/verifiers/rsa'
36
+ import { Resolver } from 'iso-signatures/verifiers/resolver'
35
37
 
36
38
  const message = new TextEncoder().encode('hello world')
37
39
  const resolver = new Resolver(
@@ -1,8 +1,7 @@
1
- /* eslint-disable unicorn/numeric-separators-style */
2
1
  import { webcrypto } from 'iso-base/crypto'
3
2
  import { u8 } from 'iso-base/utils'
4
- import { DIDKey, keyTypeToAlg } from 'iso-did/key'
5
- import { createEcdsaParams } from '../utils.js'
3
+ import { DIDKey, algToKeyType, keyTypeToAlg } from 'iso-did/key'
4
+ import { createEcdsaParams, didKeyOrVerifiableDID } from '../utils.js'
6
5
 
7
6
  /**
8
7
  * @typedef {import('../types.js').ISigner<CryptoKeyPair>} ISigner
@@ -13,7 +12,7 @@ import { createEcdsaParams } from '../utils.js'
13
12
  * @param {string} alg
14
13
  */
15
14
  function asECDSAAlg(alg) {
16
- if (alg.startsWith('ES')) {
15
+ if (['ES256', 'ES384', 'ES512'].includes(alg)) {
17
16
  return /** @type {ECDSAAlg} */ (alg)
18
17
  }
19
18
  throw new TypeError(`Unsupported algorithm ${alg}`)
@@ -25,18 +24,24 @@ function asECDSAAlg(alg) {
25
24
  * @implements {ISigner}
26
25
  */
27
26
  export class ECDSASigner {
27
+ /** @type {ReturnType<createEcdsaParams>} */
28
+ #params
29
+
30
+ /** @type {CryptoKeyPair} */
31
+ #keypair
28
32
  /**
29
- * @param {ECDSAAlg} alg
30
- * @param {Uint8Array} publicKey
33
+ * @param {import('iso-did/types').VerifiableDID} did
31
34
  * @param {CryptoKeyPair} keypair
32
35
  */
33
- constructor(alg, publicKey, keypair) {
34
- this.params = createEcdsaParams(alg)
35
- this.keypair = keypair
36
- this.publicKey = publicKey
37
- this.alg = alg
38
- this.type = this.params.namedCurve
39
- this.did = DIDKey.fromPublicKey(this.type, this.publicKey)
36
+ constructor(did, keypair) {
37
+ this.did = did.did
38
+ this.url = did.url
39
+ this.type = did.type
40
+ this.publicKey = did.publicKey
41
+ this.alg = asECDSAAlg(did.alg)
42
+ this.document = did.document
43
+ this.#params = createEcdsaParams(this.alg)
44
+ this.#keypair = keypair
40
45
  }
41
46
 
42
47
  /**
@@ -56,17 +61,22 @@ export class ECDSASigner {
56
61
  cryptoKeyPair.publicKey
57
62
  )
58
63
 
59
- return new ECDSASigner(alg, u8(publicKey), cryptoKeyPair)
64
+ return new ECDSASigner(
65
+ DIDKey.fromPublicKey(algToKeyType(alg), u8(publicKey)),
66
+ cryptoKeyPair
67
+ )
60
68
  }
61
69
 
62
70
  /**
63
71
  * Import a signer from a JWK
64
72
  *
65
- * @param {import('../types.js').PrivateKeyJwk} jwk
73
+ * @param {import('iso-did/types').ECJWKPrivate} jwk
74
+ * @param {import('iso-did/types').VerifiableDID} [did]
66
75
  */
67
- static async importJwk(jwk) {
76
+ static async importJwk(jwk, did) {
68
77
  const alg = asECDSAAlg(keyTypeToAlg(jwk.crv))
69
78
  const params = createEcdsaParams(alg)
79
+ const type = jwk.crv
70
80
  const privateKey = await webcrypto.subtle.importKey(
71
81
  'jwk',
72
82
  jwk,
@@ -84,7 +94,7 @@ export class ECDSASigner {
84
94
 
85
95
  const publicKey = await webcrypto.subtle.exportKey('raw', publicKeyJWK)
86
96
 
87
- return new ECDSASigner(alg, u8(publicKey), {
97
+ return new ECDSASigner(didKeyOrVerifiableDID(type, publicKey, did), {
88
98
  privateKey,
89
99
  publicKey: publicKeyJWK,
90
100
  })
@@ -94,8 +104,9 @@ export class ECDSASigner {
94
104
  * Import a signer from a CryptoKeyPair
95
105
  *
96
106
  * @param {CryptoKeyPair} key
107
+ * @param {import('iso-did/types').VerifiableDID} [did]
97
108
  */
98
- static async import(key) {
109
+ static async import(key, did) {
99
110
  const publicKey = await webcrypto.subtle.exportKey('raw', key.publicKey)
100
111
 
101
112
  /** @type { ECDSAAlg } */
@@ -118,7 +129,11 @@ export class ECDSASigner {
118
129
  throw new Error('Unsupported key type')
119
130
  }
120
131
  }
121
- return new ECDSASigner(alg, u8(publicKey), key)
132
+
133
+ return new ECDSASigner(
134
+ didKeyOrVerifiableDID(algToKeyType(alg), publicKey, did),
135
+ key
136
+ )
122
137
  }
123
138
 
124
139
  /**
@@ -128,8 +143,8 @@ export class ECDSASigner {
128
143
  */
129
144
  async sign(message) {
130
145
  const buf = await webcrypto.subtle.sign(
131
- this.params,
132
- this.keypair.privateKey,
146
+ this.#params,
147
+ this.#keypair.privateKey,
133
148
  message
134
149
  )
135
150
 
@@ -142,6 +157,10 @@ export class ECDSASigner {
142
157
  * @returns {CryptoKeyPair}
143
158
  */
144
159
  export() {
145
- return this.keypair
160
+ return this.#keypair
161
+ }
162
+
163
+ toString() {
164
+ return this.url.didUrl
146
165
  }
147
166
  }
@@ -4,6 +4,7 @@ import { webcrypto } from 'iso-base/crypto'
4
4
  import { base64pad } from 'iso-base/rfc4648'
5
5
  import { tag, untag } from 'iso-base/varint'
6
6
  import { DIDKey } from 'iso-did/key'
7
+ import { didKeyOrVerifiableDID } from '../utils.js'
7
8
 
8
9
  // @ts-ignore
9
10
  if (!globalThis.crypto) globalThis.crypto = webcrypto
@@ -12,6 +13,19 @@ if (!globalThis.crypto) globalThis.crypto = webcrypto
12
13
  * @typedef {import('../types.js').ISigner<string>} ISigner
13
14
  */
14
15
 
16
+ /**
17
+ *
18
+ * @param {import('iso-did/types').VerifiableDID} did
19
+ */
20
+ function checkDid(did) {
21
+ if (did.type !== 'Ed25519') {
22
+ throw new TypeError(`Unsupported key type ${did.type}`)
23
+ }
24
+ if (did.alg !== 'EdDSA') {
25
+ throw new TypeError(`Unsupported algorithm ${did.alg}`)
26
+ }
27
+ }
28
+
15
29
  /**
16
30
  * EdDSA signer
17
31
  *
@@ -26,17 +40,22 @@ export class EdDSASigner {
26
40
 
27
41
  static code = 0x1300
28
42
 
43
+ /** @type {Uint8Array} */
44
+ #privateKey
45
+
29
46
  /**
30
- * @param {Uint8Array} publicKey
47
+ * @param {import('iso-did/types').VerifiableDID} did
31
48
  * @param {Uint8Array} privateKey
32
49
  */
33
- constructor(publicKey, privateKey) {
34
- this.privateKey = privateKey
35
- this.publicKey = publicKey
36
- this.alg = EdDSASigner.alg
37
- this.type = EdDSASigner.type
38
- this.code = EdDSASigner.code
39
- this.did = DIDKey.fromPublicKey(EdDSASigner.type, this.publicKey)
50
+ constructor(did, privateKey) {
51
+ checkDid(did)
52
+ this.did = did.did
53
+ this.url = did.url
54
+ this.type = did.type
55
+ this.publicKey = did.publicKey
56
+ this.alg = did.alg
57
+ this.document = did.document
58
+ this.#privateKey = privateKey
40
59
  }
41
60
 
42
61
  /**
@@ -47,19 +66,26 @@ export class EdDSASigner {
47
66
  static async generate(bytes) {
48
67
  const privateKey = bytes || utils.randomPrivateKey()
49
68
  const publicKey = await getPublicKeyAsync(privateKey)
50
- return new EdDSASigner(publicKey, privateKey)
69
+ return new EdDSASigner(
70
+ DIDKey.fromPublicKey('Ed25519', publicKey),
71
+ privateKey
72
+ )
51
73
  }
52
74
 
53
75
  /**
54
76
  * Import a signer from a encoded string
55
77
  *
56
78
  * @param {string} encoded
79
+ * @param {import('iso-did/types').VerifiableDID} [did]
57
80
  */
58
- static async import(encoded) {
81
+ static async import(encoded, did) {
59
82
  const privateKey = untag(EdDSASigner.code, base64pad.decode(encoded))
60
83
  const publicKey = await getPublicKeyAsync(privateKey)
61
84
 
62
- return new EdDSASigner(publicKey, privateKey)
85
+ return new EdDSASigner(
86
+ didKeyOrVerifiableDID('Ed25519', publicKey, did),
87
+ privateKey
88
+ )
63
89
  }
64
90
 
65
91
  /**
@@ -68,13 +94,17 @@ export class EdDSASigner {
68
94
  * @param {Uint8Array} message
69
95
  */
70
96
  async sign(message) {
71
- return signAsync(message, this.privateKey)
97
+ return signAsync(message, this.#privateKey)
72
98
  }
73
99
 
74
100
  /**
75
101
  * Export the signer as a encoded string
76
102
  */
77
103
  export() {
78
- return base64pad.encode(tag(EdDSASigner.code, this.privateKey))
104
+ return base64pad.encode(tag(EdDSASigner.code, this.#privateKey))
105
+ }
106
+
107
+ toString() {
108
+ return this.url.didUrl
79
109
  }
80
110
  }
@@ -3,11 +3,25 @@ import { webcrypto } from 'iso-base/crypto'
3
3
  import { u8 } from 'iso-base/utils'
4
4
  import { DIDKey } from 'iso-did/key'
5
5
  import { spki } from '../spki.js'
6
+ import { didKeyOrVerifiableDID } from '../utils.js'
6
7
 
7
8
  /**
8
9
  * @typedef {import('../types.js').ISigner<CryptoKeyPair>} ISigner
9
10
  */
10
11
 
12
+ /**
13
+ *
14
+ * @param {import('iso-did/types').VerifiableDID} did
15
+ */
16
+ function checkDid(did) {
17
+ if (did.type !== RSASigner.type) {
18
+ throw new TypeError(`Unsupported key type ${did.type}`)
19
+ }
20
+ if (did.alg !== RSASigner.alg) {
21
+ throw new TypeError(`Unsupported algorithm ${did.alg}`)
22
+ }
23
+ }
24
+
11
25
  /**
12
26
  * RSA signer
13
27
  *
@@ -23,17 +37,22 @@ export class RSASigner {
23
37
  // multicodec code for RSA private key
24
38
  static code = 0x1305
25
39
 
40
+ /** @type {CryptoKeyPair} */
41
+ #keypair
42
+
26
43
  /**
27
- * @param {Uint8Array} publicKey
44
+ * @param {import('iso-did/types').VerifiableDID} did
28
45
  * @param {CryptoKeyPair} keypair
29
46
  */
30
- constructor(publicKey, keypair) {
31
- this.keypair = keypair
32
- this.publicKey = publicKey
33
- this.alg = RSASigner.alg
34
- this.type = RSASigner.type
35
- this.code = RSASigner.code
36
- this.did = DIDKey.fromPublicKey(RSASigner.type, this.publicKey)
47
+ constructor(did, keypair) {
48
+ checkDid(did)
49
+ this.did = did.did
50
+ this.url = did.url
51
+ this.type = did.type
52
+ this.publicKey = did.publicKey
53
+ this.alg = did.alg
54
+ this.document = did.document
55
+ this.#keypair = keypair
37
56
  }
38
57
 
39
58
  /**
@@ -56,16 +75,19 @@ export class RSASigner {
56
75
  'spki',
57
76
  cryptoKeyPair.publicKey
58
77
  )
59
-
60
- return new RSASigner(spki.decode(u8(publicKey)), cryptoKeyPair)
78
+ return new RSASigner(
79
+ DIDKey.fromPublicKey('RSA', spki.decode(u8(publicKey))),
80
+ cryptoKeyPair
81
+ )
61
82
  }
62
83
 
63
84
  /**
64
85
  * Import a signer from a JWK
65
86
  *
66
- * @param {import('../types.js').PrivateKeyRSAJwk} jwk
87
+ * @param {import('iso-did/types').RSAJWKPrivate} jwk
88
+ * @param {import('iso-did/types').VerifiableDID} [did]
67
89
  */
68
- static async importJwk(jwk) {
90
+ static async importJwk(jwk, did) {
69
91
  const privateKey = await webcrypto.subtle.importKey(
70
92
  'jwk',
71
93
  jwk,
@@ -88,8 +110,9 @@ export class RSASigner {
88
110
  )
89
111
 
90
112
  const publicKey = await webcrypto.subtle.exportKey('spki', publicKeyJWK)
113
+ const decodedPublicKey = spki.decode(u8(publicKey))
91
114
 
92
- return new RSASigner(spki.decode(u8(publicKey)), {
115
+ return new RSASigner(didKeyOrVerifiableDID('RSA', decodedPublicKey, did), {
93
116
  privateKey,
94
117
  publicKey: publicKeyJWK,
95
118
  })
@@ -99,14 +122,20 @@ export class RSASigner {
99
122
  * Import a signer from a keypair
100
123
  *
101
124
  * @param {CryptoKeyPair} keypair
125
+ * @param {import('iso-did/types').VerifiableDID} [did]
102
126
  */
103
- static async import(keypair) {
127
+ static async import(keypair, did) {
104
128
  const publicKey = await webcrypto.subtle.exportKey(
105
129
  'spki',
106
130
  keypair.publicKey
107
131
  )
108
132
 
109
- return new RSASigner(spki.decode(u8(publicKey)), keypair)
133
+ const decodedPublicKey = spki.decode(u8(publicKey))
134
+
135
+ return new RSASigner(
136
+ didKeyOrVerifiableDID('RSA', decodedPublicKey, did),
137
+ keypair
138
+ )
110
139
  }
111
140
 
112
141
  /**
@@ -117,7 +146,7 @@ export class RSASigner {
117
146
  async sign(message) {
118
147
  const buf = await webcrypto.subtle.sign(
119
148
  { name: 'RSASSA-PKCS1-v1_5', saltLength: 128 },
120
- this.keypair.privateKey,
149
+ this.#keypair.privateKey,
121
150
  message
122
151
  )
123
152
 
@@ -128,6 +157,10 @@ export class RSASigner {
128
157
  * Export the signer as a crypto key pair
129
158
  */
130
159
  export() {
131
- return this.keypair
160
+ return this.#keypair
161
+ }
162
+
163
+ toString() {
164
+ return this.url.didUrl
132
165
  }
133
166
  }
package/src/types.ts CHANGED
@@ -1,26 +1,13 @@
1
- import type { DIDKey } from 'iso-did/key'
2
- import type { SignatureAlgorithm, KeyType } from 'iso-did/types'
1
+ import type { SignatureAlgorithm, VerifiableDID } from 'iso-did/types'
3
2
 
4
- export interface ISigner<Export extends CryptoKeyPair | string> {
5
- /**
6
- * JWT signing algorithm
7
- */
8
- alg: SignatureAlgorithm
9
- /**
10
- * Keypair type
11
- */
12
- type: KeyType
13
- /**
14
- * Multicodec identifier for the private key
15
- */
16
- code?: number
17
-
18
- did: DIDKey
19
- /**
20
- * Sign a message
21
- */
3
+ export interface Sign {
22
4
  sign: (message: Uint8Array) => Promise<Uint8Array>
5
+ }
23
6
 
7
+ export interface ISigner<Export extends CryptoKeyPair | string>
8
+ extends VerifiableDID,
9
+ Sign {
10
+ code?: number
24
11
  export: () => Export
25
12
  }
26
13
 
@@ -49,27 +36,3 @@ export interface IResolver {
49
36
  export interface ResolverOptions {
50
37
  cache?: Cache | boolean | undefined
51
38
  }
52
-
53
- export interface PublicKeyJwk {
54
- kty: string
55
- crv: string
56
- x: string
57
- y: string
58
- }
59
-
60
- export interface PublicKeyRSAJwk {
61
- kty: string
62
- n: string
63
- e: string
64
- }
65
-
66
- export interface PrivateKeyRSAJwk extends PublicKeyRSAJwk {
67
- d: string
68
- p: string
69
- q: string
70
- dp: string
71
- dq: string
72
- qi: string
73
- }
74
-
75
- export type PrivateKeyJwk = PublicKeyJwk & { d: string }
package/src/utils.js CHANGED
@@ -1,3 +1,6 @@
1
+ import { DIDKey } from 'iso-did/key'
2
+ import { equals, u8 } from 'iso-base/utils'
3
+
1
4
  /**
2
5
  * Create web crypto params for ECDSA.
3
6
  *
@@ -33,3 +36,30 @@ export function createEcdsaParams(alg) {
33
36
  }
34
37
  }
35
38
  }
39
+
40
+ /**
41
+ *
42
+ * @param {import('iso-did/types').KeyType} type
43
+ * @param {BufferSource} publicKey
44
+ * @param {import('iso-did/types').VerifiableDID} [did]
45
+ */
46
+ export function didKeyOrVerifiableDID(type, publicKey, did) {
47
+ /** @type {import('iso-did/types').VerifiableDID} */
48
+ let _did = DIDKey.fromPublicKey(type, u8(publicKey))
49
+ if (did) {
50
+ if (!equals(did.publicKey, _did.publicKey)) {
51
+ throw new Error('Public key mismatch')
52
+ }
53
+
54
+ if (did.alg !== _did.alg) {
55
+ throw new Error('Algorithm mismatch')
56
+ }
57
+
58
+ if (did.type !== _did.type) {
59
+ throw new Error('Key type mismatch')
60
+ }
61
+ _did = did
62
+ }
63
+
64
+ return _did
65
+ }
@@ -1,4 +1,3 @@
1
- /* eslint-disable unicorn/numeric-separators-style */
2
1
  import { webcrypto } from 'iso-base/crypto'
3
2
  import { decompress, isCompressed } from 'iso-base/ec-compression'
4
3
  import { createEcdsaParams } from '../utils.js'
@@ -1,4 +1,3 @@
1
- /* eslint-disable unicorn/numeric-separators-style */
2
1
  import { verifyAsync } from '@noble/ed25519'
3
2
 
4
3
  /** @type {import('../types').Verify} */
@@ -1,4 +1,3 @@
1
- /* eslint-disable unicorn/numeric-separators-style */
2
1
  import { webcrypto } from 'iso-base/crypto'
3
2
  import { spki } from '../spki.js'
4
3
 
@@ -1,53 +0,0 @@
1
- /**
2
- * @typedef {import('../types.js').ISigner<CryptoKeyPair>} ISigner
3
- */
4
- /**
5
- * RSA Old fission format signer
6
- *
7
- * @implements {ISigner}
8
- */
9
- export class RSAOldSigner implements ISigner {
10
- /** @type {Extract<import('iso-did/types').SignatureAlgorithm, "RS256_OLD">} */
11
- static alg: Extract<import('iso-did/types').SignatureAlgorithm, "RS256_OLD">;
12
- /** @type {Extract<import('iso-did/types').KeyType, "RSA_OLD">} */
13
- static type: Extract<import('iso-did/types').KeyType, "RSA_OLD">;
14
- /**
15
- * Generate a new signer
16
- */
17
- static generate(): Promise<RSAOldSigner>;
18
- /**
19
- * Import a signer from a JWK
20
- *
21
- * @param {import('../types.js').PrivateKeyRSAJwk} jwk
22
- */
23
- static importJwk(jwk: import('../types.js').PrivateKeyRSAJwk): Promise<RSAOldSigner>;
24
- /**
25
- * Import a signer from a keypair
26
- *
27
- * @param {CryptoKeyPair} keypair
28
- */
29
- static import(keypair: CryptoKeyPair): Promise<RSAOldSigner>;
30
- /**
31
- * @param {Uint8Array} publicKey
32
- * @param {CryptoKeyPair} keypair
33
- */
34
- constructor(publicKey: Uint8Array, keypair: CryptoKeyPair);
35
- keypair: CryptoKeyPair;
36
- publicKey: Uint8Array;
37
- alg: "RS256_OLD";
38
- type: "RSA_OLD";
39
- did: DIDKey;
40
- /**
41
- * Sign a message
42
- *
43
- * @param {Uint8Array} message
44
- */
45
- sign(message: Uint8Array): Promise<Uint8Array>;
46
- /**
47
- * Export the signer as a crypto key pair
48
- */
49
- export(): CryptoKeyPair;
50
- }
51
- export type ISigner = import('../types.js').ISigner<CryptoKeyPair>;
52
- import { DIDKey } from 'iso-did/key';
53
- //# sourceMappingURL=rsa-old.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"rsa-old.d.ts","sourceRoot":"","sources":["../../../src/signers/rsa-old.js"],"names":[],"mappings":"AAKA;;GAEG;AAEH;;;;GAIG;AACH;IACE,+EAA+E;IAC/E,YADW,QAAQ,OAAO,eAAe,EAAE,kBAAkB,EAAE,WAAW,CAAC,CACnD;IAExB,kEAAkE;IAClE,aADW,QAAQ,OAAO,eAAe,EAAE,OAAO,EAAE,SAAS,CAAC,CACvC;IAcvB;;OAEG;IACH,yCAmBC;IAED;;;;OAIG;IACH,sBAFW,OAAO,aAAa,EAAE,gBAAgB,yBA8BhD;IAED;;;;OAIG;IACH,uBAFW,aAAa,yBASvB;IAnFD;;;OAGG;IACH,uBAHW,UAAU,WACV,aAAa,EAQvB;IALC,uBAAsB;IACtB,sBAA0B;IAC1B,iBAA2B;IAC3B,gBAA6B;IAC7B,YAAkE;IA4EpE;;;;OAIG;IACH,cAFW,UAAU,uBAUpB;IAED;;OAEG;IACH,wBAEC;CACF;sBAzHY,OAAO,aAAa,EAAE,OAAO,CAAC,aAAa,CAAC;uBAHlC,aAAa"}
@@ -1,4 +0,0 @@
1
- export function verify(input: import("../types.js").VerifyInput): Promise<boolean>;
2
- /** @type {import('../types.js').Verifier<'RS256_OLD'>} */
3
- export const verifier: import('../types.js').Verifier<'RS256_OLD'>;
4
- //# sourceMappingURL=rsa-old.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"rsa-old.d.ts","sourceRoot":"","sources":["../../../src/verifiers/rsa-old.js"],"names":[],"mappings":"AAuBc,mFAEkB;AAJhC,0DAA0D;AAC1D,uBADW,OAAO,aAAa,EAAE,QAAQ,CAAC,WAAW,CAAC,CAGrD"}
@@ -1,128 +0,0 @@
1
- /* eslint-disable unicorn/numeric-separators-style */
2
- import { webcrypto } from 'iso-base/crypto'
3
- import { u8 } from 'iso-base/utils'
4
- import { DIDKey } from 'iso-did/key'
5
-
6
- /**
7
- * @typedef {import('../types.js').ISigner<CryptoKeyPair>} ISigner
8
- */
9
-
10
- /**
11
- * RSA Old fission format signer
12
- *
13
- * @implements {ISigner}
14
- */
15
- export class RSAOldSigner {
16
- /** @type {Extract<import('iso-did/types').SignatureAlgorithm, "RS256_OLD">} */
17
- static alg = 'RS256_OLD'
18
-
19
- /** @type {Extract<import('iso-did/types').KeyType, "RSA_OLD">} */
20
- static type = 'RSA_OLD'
21
-
22
- /**
23
- * @param {Uint8Array} publicKey
24
- * @param {CryptoKeyPair} keypair
25
- */
26
- constructor(publicKey, keypair) {
27
- this.keypair = keypair
28
- this.publicKey = publicKey
29
- this.alg = RSAOldSigner.alg
30
- this.type = RSAOldSigner.type
31
- this.did = DIDKey.fromPublicKey(RSAOldSigner.type, this.publicKey)
32
- }
33
-
34
- /**
35
- * Generate a new signer
36
- */
37
- static async generate() {
38
- const cryptoKeyPair = await webcrypto.subtle.generateKey(
39
- {
40
- name: 'RSASSA-PKCS1-v1_5',
41
- modulusLength: 2048,
42
- publicExponent: new Uint8Array([0x01, 0x00, 0x01]),
43
- hash: { name: 'SHA-256' },
44
- },
45
-
46
- false,
47
- ['sign', 'verify']
48
- )
49
-
50
- const publicKey = await webcrypto.subtle.exportKey(
51
- 'spki',
52
- cryptoKeyPair.publicKey
53
- )
54
-
55
- return new RSAOldSigner(u8(publicKey), cryptoKeyPair)
56
- }
57
-
58
- /**
59
- * Import a signer from a JWK
60
- *
61
- * @param {import('../types.js').PrivateKeyRSAJwk} jwk
62
- */
63
- static async importJwk(jwk) {
64
- const privateKey = await webcrypto.subtle.importKey(
65
- 'jwk',
66
- jwk,
67
- {
68
- name: 'RSASSA-PKCS1-v1_5',
69
- hash: 'SHA-256',
70
- },
71
- false,
72
- ['sign']
73
- )
74
- const publicKeyJWK = await webcrypto.subtle.importKey(
75
- 'jwk',
76
- { ...jwk, d: undefined },
77
- {
78
- name: 'RSASSA-PKCS1-v1_5',
79
- hash: 'SHA-256',
80
- },
81
- true,
82
- ['verify']
83
- )
84
-
85
- const publicKey = await webcrypto.subtle.exportKey('spki', publicKeyJWK)
86
-
87
- return new RSAOldSigner(u8(publicKey), {
88
- privateKey,
89
- publicKey: publicKeyJWK,
90
- })
91
- }
92
-
93
- /**
94
- * Import a signer from a keypair
95
- *
96
- * @param {CryptoKeyPair} keypair
97
- */
98
- static async import(keypair) {
99
- const publicKey = await webcrypto.subtle.exportKey(
100
- 'spki',
101
- keypair.publicKey
102
- )
103
-
104
- return new RSAOldSigner(u8(publicKey), keypair)
105
- }
106
-
107
- /**
108
- * Sign a message
109
- *
110
- * @param {Uint8Array} message
111
- */
112
- async sign(message) {
113
- const buf = await webcrypto.subtle.sign(
114
- { name: 'RSASSA-PKCS1-v1_5', saltLength: 128 },
115
- this.keypair.privateKey,
116
- message
117
- )
118
-
119
- return u8(buf)
120
- }
121
-
122
- /**
123
- * Export the signer as a crypto key pair
124
- */
125
- export() {
126
- return this.keypair
127
- }
128
- }
@@ -1,25 +0,0 @@
1
- /* eslint-disable unicorn/numeric-separators-style */
2
- import { webcrypto } from 'iso-base/crypto'
3
-
4
- /** @type {import('../types.js').Verify} */
5
- export async function verify({ signature, message, publicKey }) {
6
- const key = await webcrypto.subtle.importKey(
7
- 'spki',
8
- publicKey,
9
- { name: 'RSASSA-PKCS1-v1_5', hash: { name: 'SHA-256' } },
10
- true,
11
- ['verify']
12
- )
13
-
14
- return await webcrypto.subtle.verify(
15
- { name: 'RSASSA-PKCS1-v1_5', saltLength: 128 },
16
- key,
17
- signature,
18
- message
19
- )
20
- }
21
-
22
- /** @type {import('../types.js').Verifier<'RS256_OLD'>} */
23
- export const verifier = {
24
- RS256_OLD: verify,
25
- }