iso-signatures 0.2.0 → 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.
- package/dist/src/signers/ecdsa.d.ts +13 -15
- package/dist/src/signers/ecdsa.d.ts.map +1 -1
- package/dist/src/signers/eddsa.d.ts +11 -12
- package/dist/src/signers/eddsa.d.ts.map +1 -1
- package/dist/src/signers/rsa.d.ts +14 -14
- package/dist/src/signers/rsa.d.ts.map +1 -1
- package/dist/src/types.d.ts +5 -41
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/utils.d.ts +7 -0
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/verifiers/eddsa.d.ts.map +1 -1
- package/dist/src/verifiers/resolver.d.ts +0 -1
- package/dist/src/verifiers/resolver.d.ts.map +1 -1
- package/dist/src/verifiers/rsa.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/signers/ecdsa.js +41 -21
- package/src/signers/eddsa.js +43 -13
- package/src/signers/rsa.js +50 -17
- package/src/types.ts +7 -44
- package/src/utils.js +30 -0
|
@@ -13,31 +13,28 @@ export class ECDSASigner implements ISigner {
|
|
|
13
13
|
/**
|
|
14
14
|
* Import a signer from a JWK
|
|
15
15
|
*
|
|
16
|
-
* @param {import('
|
|
16
|
+
* @param {import('iso-did/types').ECJWKPrivate} jwk
|
|
17
|
+
* @param {import('iso-did/types').VerifiableDID} [did]
|
|
17
18
|
*/
|
|
18
|
-
static importJwk(jwk: import('
|
|
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 {
|
|
27
|
-
* @param {Uint8Array} publicKey
|
|
28
|
+
* @param {import('iso-did/types').VerifiableDID} did
|
|
28
29
|
* @param {CryptoKeyPair} keypair
|
|
29
30
|
*/
|
|
30
|
-
constructor(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
|
|
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":"AAoBA;;;;GAIG;AACH;
|
|
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 {
|
|
26
|
+
* @param {import('iso-did/types').VerifiableDID} did
|
|
29
27
|
* @param {Uint8Array} privateKey
|
|
30
28
|
*/
|
|
31
|
-
constructor(
|
|
32
|
-
|
|
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
|
-
|
|
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":"
|
|
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('
|
|
19
|
+
* @param {import('iso-did/types').RSAJWKPrivate} jwk
|
|
20
|
+
* @param {import('iso-did/types').VerifiableDID} [did]
|
|
23
21
|
*/
|
|
24
|
-
static importJwk(jwk: import('
|
|
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 {
|
|
31
|
+
* @param {import('iso-did/types').VerifiableDID} did
|
|
33
32
|
* @param {CryptoKeyPair} keypair
|
|
34
33
|
*/
|
|
35
|
-
constructor(
|
|
36
|
-
|
|
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
|
-
|
|
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":"
|
|
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"}
|
package/dist/src/types.d.ts
CHANGED
|
@@ -1,23 +1,9 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
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
|
package/dist/src/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
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"}
|
package/dist/src/utils.d.ts
CHANGED
|
@@ -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
|
package/dist/src/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.js"],"names":[],"mappings":"
|
|
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":"eddsa.d.ts","sourceRoot":"","sources":["../../../src/verifiers/eddsa.js"],"names":[],"mappings":"
|
|
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"}
|
|
@@ -12,7 +12,6 @@ export class Resolver implements IResolver {
|
|
|
12
12
|
constructor(registry?: import('../types').VerifierRegistry<import('iso-did/types').SignatureAlgorithm>, options?: import('../types').ResolverOptions);
|
|
13
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,2GAAwB;IACxB,gCACmE;
|
|
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":"
|
|
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,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "iso-signatures",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.3.0",
|
|
5
5
|
"description": "Signatures tooling.",
|
|
6
6
|
"author": "Hugo Dias <hugomrdias@gmail.com> (hugodias.me)",
|
|
7
7
|
"license": "MIT",
|
|
@@ -83,12 +83,12 @@
|
|
|
83
83
|
"dependencies": {
|
|
84
84
|
"@noble/ed25519": "^2.0.0",
|
|
85
85
|
"iso-base": "^2.0.1",
|
|
86
|
-
"iso-did": "^1.
|
|
86
|
+
"iso-did": "^1.5.0"
|
|
87
87
|
},
|
|
88
88
|
"devDependencies": {
|
|
89
89
|
"@types/assert": "^1.5.10",
|
|
90
90
|
"@types/mocha": "^10.0.6",
|
|
91
|
-
"@types/node": "^20.10.
|
|
91
|
+
"@types/node": "^20.10.5",
|
|
92
92
|
"assert": "^2.1.0",
|
|
93
93
|
"mocha": "^10.2.0",
|
|
94
94
|
"playwright-test": "^14.0.0",
|
package/src/signers/ecdsa.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { webcrypto } from 'iso-base/crypto'
|
|
2
2
|
import { u8 } from 'iso-base/utils'
|
|
3
|
-
import { DIDKey, keyTypeToAlg } from 'iso-did/key'
|
|
4
|
-
import { createEcdsaParams } from '../utils.js'
|
|
3
|
+
import { DIDKey, algToKeyType, keyTypeToAlg } from 'iso-did/key'
|
|
4
|
+
import { createEcdsaParams, didKeyOrVerifiableDID } from '../utils.js'
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* @typedef {import('../types.js').ISigner<CryptoKeyPair>} ISigner
|
|
@@ -12,7 +12,7 @@ import { createEcdsaParams } from '../utils.js'
|
|
|
12
12
|
* @param {string} alg
|
|
13
13
|
*/
|
|
14
14
|
function asECDSAAlg(alg) {
|
|
15
|
-
if (
|
|
15
|
+
if (['ES256', 'ES384', 'ES512'].includes(alg)) {
|
|
16
16
|
return /** @type {ECDSAAlg} */ (alg)
|
|
17
17
|
}
|
|
18
18
|
throw new TypeError(`Unsupported algorithm ${alg}`)
|
|
@@ -24,18 +24,24 @@ function asECDSAAlg(alg) {
|
|
|
24
24
|
* @implements {ISigner}
|
|
25
25
|
*/
|
|
26
26
|
export class ECDSASigner {
|
|
27
|
+
/** @type {ReturnType<createEcdsaParams>} */
|
|
28
|
+
#params
|
|
29
|
+
|
|
30
|
+
/** @type {CryptoKeyPair} */
|
|
31
|
+
#keypair
|
|
27
32
|
/**
|
|
28
|
-
* @param {
|
|
29
|
-
* @param {Uint8Array} publicKey
|
|
33
|
+
* @param {import('iso-did/types').VerifiableDID} did
|
|
30
34
|
* @param {CryptoKeyPair} keypair
|
|
31
35
|
*/
|
|
32
|
-
constructor(
|
|
33
|
-
this.
|
|
34
|
-
this.
|
|
35
|
-
this.
|
|
36
|
-
this.
|
|
37
|
-
this.
|
|
38
|
-
this.
|
|
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
|
|
39
45
|
}
|
|
40
46
|
|
|
41
47
|
/**
|
|
@@ -55,17 +61,22 @@ export class ECDSASigner {
|
|
|
55
61
|
cryptoKeyPair.publicKey
|
|
56
62
|
)
|
|
57
63
|
|
|
58
|
-
return new ECDSASigner(
|
|
64
|
+
return new ECDSASigner(
|
|
65
|
+
DIDKey.fromPublicKey(algToKeyType(alg), u8(publicKey)),
|
|
66
|
+
cryptoKeyPair
|
|
67
|
+
)
|
|
59
68
|
}
|
|
60
69
|
|
|
61
70
|
/**
|
|
62
71
|
* Import a signer from a JWK
|
|
63
72
|
*
|
|
64
|
-
* @param {import('
|
|
73
|
+
* @param {import('iso-did/types').ECJWKPrivate} jwk
|
|
74
|
+
* @param {import('iso-did/types').VerifiableDID} [did]
|
|
65
75
|
*/
|
|
66
|
-
static async importJwk(jwk) {
|
|
76
|
+
static async importJwk(jwk, did) {
|
|
67
77
|
const alg = asECDSAAlg(keyTypeToAlg(jwk.crv))
|
|
68
78
|
const params = createEcdsaParams(alg)
|
|
79
|
+
const type = jwk.crv
|
|
69
80
|
const privateKey = await webcrypto.subtle.importKey(
|
|
70
81
|
'jwk',
|
|
71
82
|
jwk,
|
|
@@ -83,7 +94,7 @@ export class ECDSASigner {
|
|
|
83
94
|
|
|
84
95
|
const publicKey = await webcrypto.subtle.exportKey('raw', publicKeyJWK)
|
|
85
96
|
|
|
86
|
-
return new ECDSASigner(
|
|
97
|
+
return new ECDSASigner(didKeyOrVerifiableDID(type, publicKey, did), {
|
|
87
98
|
privateKey,
|
|
88
99
|
publicKey: publicKeyJWK,
|
|
89
100
|
})
|
|
@@ -93,8 +104,9 @@ export class ECDSASigner {
|
|
|
93
104
|
* Import a signer from a CryptoKeyPair
|
|
94
105
|
*
|
|
95
106
|
* @param {CryptoKeyPair} key
|
|
107
|
+
* @param {import('iso-did/types').VerifiableDID} [did]
|
|
96
108
|
*/
|
|
97
|
-
static async import(key) {
|
|
109
|
+
static async import(key, did) {
|
|
98
110
|
const publicKey = await webcrypto.subtle.exportKey('raw', key.publicKey)
|
|
99
111
|
|
|
100
112
|
/** @type { ECDSAAlg } */
|
|
@@ -117,7 +129,11 @@ export class ECDSASigner {
|
|
|
117
129
|
throw new Error('Unsupported key type')
|
|
118
130
|
}
|
|
119
131
|
}
|
|
120
|
-
|
|
132
|
+
|
|
133
|
+
return new ECDSASigner(
|
|
134
|
+
didKeyOrVerifiableDID(algToKeyType(alg), publicKey, did),
|
|
135
|
+
key
|
|
136
|
+
)
|
|
121
137
|
}
|
|
122
138
|
|
|
123
139
|
/**
|
|
@@ -127,8 +143,8 @@ export class ECDSASigner {
|
|
|
127
143
|
*/
|
|
128
144
|
async sign(message) {
|
|
129
145
|
const buf = await webcrypto.subtle.sign(
|
|
130
|
-
this
|
|
131
|
-
this
|
|
146
|
+
this.#params,
|
|
147
|
+
this.#keypair.privateKey,
|
|
132
148
|
message
|
|
133
149
|
)
|
|
134
150
|
|
|
@@ -141,6 +157,10 @@ export class ECDSASigner {
|
|
|
141
157
|
* @returns {CryptoKeyPair}
|
|
142
158
|
*/
|
|
143
159
|
export() {
|
|
144
|
-
return this
|
|
160
|
+
return this.#keypair
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
toString() {
|
|
164
|
+
return this.url.didUrl
|
|
145
165
|
}
|
|
146
166
|
}
|
package/src/signers/eddsa.js
CHANGED
|
@@ -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 {
|
|
47
|
+
* @param {import('iso-did/types').VerifiableDID} did
|
|
31
48
|
* @param {Uint8Array} privateKey
|
|
32
49
|
*/
|
|
33
|
-
constructor(
|
|
34
|
-
|
|
35
|
-
this.
|
|
36
|
-
this.
|
|
37
|
-
this.type =
|
|
38
|
-
this.
|
|
39
|
-
this.
|
|
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(
|
|
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(
|
|
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
|
|
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
|
|
104
|
+
return base64pad.encode(tag(EdDSASigner.code, this.#privateKey))
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
toString() {
|
|
108
|
+
return this.url.didUrl
|
|
79
109
|
}
|
|
80
110
|
}
|
package/src/signers/rsa.js
CHANGED
|
@@ -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 {
|
|
44
|
+
* @param {import('iso-did/types').VerifiableDID} did
|
|
28
45
|
* @param {CryptoKeyPair} keypair
|
|
29
46
|
*/
|
|
30
|
-
constructor(
|
|
31
|
-
|
|
32
|
-
this.
|
|
33
|
-
this.
|
|
34
|
-
this.type =
|
|
35
|
-
this.
|
|
36
|
-
this.
|
|
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
|
-
|
|
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('
|
|
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(
|
|
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
|
-
|
|
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
|
|
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
|
|
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 {
|
|
2
|
-
import type { KeyType, SignatureAlgorithm } from 'iso-did/types'
|
|
1
|
+
import type { SignatureAlgorithm, VerifiableDID } from 'iso-did/types'
|
|
3
2
|
|
|
4
|
-
export interface
|
|
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
|
+
}
|