@sphereon/ssi-sdk-ext.did-provider-key 0.28.1-feature.esm.cjs.9 → 0.28.1-feature.oyd.cmsm.improv.16
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/KeyDidResolver.d.ts +5 -0
- package/dist/KeyDidResolver.d.ts.map +1 -0
- package/dist/KeyDidResolver.js +22 -0
- package/dist/KeyDidResolver.js.map +1 -0
- package/dist/{index.d.cts → SphereonKeyDidProvider.d.ts} +4 -10
- package/dist/SphereonKeyDidProvider.d.ts.map +1 -0
- package/dist/SphereonKeyDidProvider.js +140 -0
- package/dist/SphereonKeyDidProvider.js.map +1 -0
- package/dist/index.d.ts +3 -58
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -117
- package/dist/index.js.map +1 -1
- package/dist/ssi-sdk-ext.did-provider-key.d.ts +63 -0
- package/dist/tsdoc-metadata.json +11 -0
- package/package.json +14 -26
- package/src/SphereonKeyDidProvider.ts +11 -12
- package/dist/index.cjs +0 -118
- package/dist/index.cjs.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"KeyDidResolver.d.ts","sourceRoot":"","sources":["../src/KeyDidResolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6C,WAAW,EAAmC,MAAM,cAAc,CAAA;AAatH,wBAAgB,iBAAiB;;EAEhC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.getDidKeyResolver = getDidKeyResolver;
|
|
13
|
+
const did_resolver_1 = require("did-resolver");
|
|
14
|
+
const ssi_sdk_ext_did_resolver_key_1 = require("@sphereon/ssi-sdk-ext.did-resolver-key");
|
|
15
|
+
const resolveDidKey = (didUrl, _parsed, _resolver, options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
|
+
const resolver = new did_resolver_1.Resolver(Object.assign({}, (0, ssi_sdk_ext_did_resolver_key_1.getResolver)()));
|
|
17
|
+
return resolver.resolve(didUrl, options);
|
|
18
|
+
});
|
|
19
|
+
function getDidKeyResolver() {
|
|
20
|
+
return { key: resolveDidKey };
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=KeyDidResolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"KeyDidResolver.js","sourceRoot":"","sources":["../src/KeyDidResolver.ts"],"names":[],"mappings":";;;;;;;;;;;AAaA,8CAEC;AAfD,+CAAsH;AACtH,yFAAoE;AAEpE,MAAM,aAAa,GAAgB,CACjC,MAAc,EACd,OAAkB,EAClB,SAAqB,EACrB,OAA6B,EACC,EAAE;IAChC,MAAM,QAAQ,GAAG,IAAI,uBAAQ,mBAAM,IAAA,0CAAW,GAAE,EAAG,CAAA;IACnD,OAAO,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AAC1C,CAAC,CAAA,CAAA;AAED,SAAgB,iBAAiB;IAC/B,OAAO,EAAE,GAAG,EAAE,aAAa,EAAE,CAAA;AAC/B,CAAC"}
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { TKeyType } from '@sphereon/ssi-sdk-ext.key-utils';
|
|
2
|
-
import { IAgentContext,
|
|
2
|
+
import { IAgentContext, IIdentifier, IKey, IKeyManager, IService } from '@veramo/core';
|
|
3
3
|
import { AbstractIdentifierProvider } from '@veramo/did-manager';
|
|
4
4
|
import Multicodec from 'multicodec';
|
|
5
|
-
import { DIDResolver } from 'did-resolver';
|
|
6
|
-
|
|
7
5
|
type IContext = IAgentContext<IKeyManager>;
|
|
8
|
-
declare class SphereonKeyDidProvider extends AbstractIdentifierProvider {
|
|
6
|
+
export declare class SphereonKeyDidProvider extends AbstractIdentifierProvider {
|
|
9
7
|
private readonly kms?;
|
|
10
8
|
constructor(options: {
|
|
11
9
|
defaultKms?: string;
|
|
@@ -50,9 +48,5 @@ declare class SphereonKeyDidProvider extends AbstractIdentifierProvider {
|
|
|
50
48
|
options?: any;
|
|
51
49
|
}, context: IContext): Promise<any>;
|
|
52
50
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
key: DIDResolver;
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
export { SphereonKeyDidProvider, getDidKeyResolver };
|
|
51
|
+
export {};
|
|
52
|
+
//# sourceMappingURL=SphereonKeyDidProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SphereonKeyDidProvider.d.ts","sourceRoot":"","sources":["../src/SphereonKeyDidProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,QAAQ,EAGT,MAAM,iCAAiC,CAAA;AACxC,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,IAAI,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AACtF,OAAO,EAAE,0BAA0B,EAAE,MAAM,qBAAqB,CAAA;AAGhE,OAAO,UAAU,MAAM,YAAY,CAAA;AAKnC,KAAK,QAAQ,GAAG,aAAa,CAAC,WAAW,CAAC,CAAA;AAY1C,qBAAa,sBAAuB,SAAQ,0BAA0B;IACpE,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAQ;gBAEjB,OAAO,EAAE;QAAE,UAAU,CAAC,EAAE,MAAM,CAAA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,QAAQ,CAAC;QAAC,OAAO,CAAC,EAAE,GAAG,CAAA;KAAE,EAAE,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC;IAI5I,SAAS,CAAC,IAAI,EAAE;QAAE,UAAU,EAAE,WAAW,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,GAAG,CAAA;KAAE,EAAE,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC;IAIzG,aAAa,CAAC,IAAI,EAAE;QAAE,UAAU,EAAE,WAAW,CAAC;QAAC,EAAE,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,GAAG,CAAA;KAAE,EAAE,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC;CAGnH"}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
+
};
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
exports.SphereonKeyDidProvider = void 0;
|
|
39
|
+
const ssi_sdk_ext_key_utils_1 = require("@sphereon/ssi-sdk-ext.key-utils");
|
|
40
|
+
const did_manager_1 = require("@veramo/did-manager");
|
|
41
|
+
const debug_1 = __importDefault(require("debug"));
|
|
42
|
+
const multibase_1 = __importDefault(require("multibase"));
|
|
43
|
+
const multicodec_1 = __importDefault(require("multicodec"));
|
|
44
|
+
const u8a = __importStar(require("uint8arrays"));
|
|
45
|
+
const debug = (0, debug_1.default)('did-provider-key');
|
|
46
|
+
const keyCodecs = {
|
|
47
|
+
RSA: 'rsa-pub',
|
|
48
|
+
Ed25519: 'ed25519-pub',
|
|
49
|
+
X25519: 'x25519-pub',
|
|
50
|
+
Secp256k1: 'secp256k1-pub',
|
|
51
|
+
Secp256r1: 'p256-pub',
|
|
52
|
+
Bls12381G1: 'bls12_381-g1-pub',
|
|
53
|
+
Bls12381G2: 'bls12_381-g2-pub',
|
|
54
|
+
};
|
|
55
|
+
class SphereonKeyDidProvider extends did_manager_1.AbstractIdentifierProvider {
|
|
56
|
+
constructor(options) {
|
|
57
|
+
super();
|
|
58
|
+
this.kms = options.defaultKms;
|
|
59
|
+
}
|
|
60
|
+
createIdentifier(_a, context_1) {
|
|
61
|
+
return __awaiter(this, arguments, void 0, function* ({ kms, alias, options, }, context) {
|
|
62
|
+
var _b, _c, _d, _e;
|
|
63
|
+
let codecName = (((_b = options === null || options === void 0 ? void 0 : options.codecName) === null || _b === void 0 ? void 0 : _b.toUpperCase()) === 'EBSI' ? ssi_sdk_ext_key_utils_1.JWK_JCS_PUB_NAME : options === null || options === void 0 ? void 0 : options.codecName);
|
|
64
|
+
const keyType = ((_e = (_c = options === null || options === void 0 ? void 0 : options.type) !== null && _c !== void 0 ? _c : (_d = options === null || options === void 0 ? void 0 : options.key) === null || _d === void 0 ? void 0 : _d.type) !== null && _e !== void 0 ? _e : (codecName === ssi_sdk_ext_key_utils_1.JWK_JCS_PUB_NAME ? 'Secp256r1' : 'Secp256k1'));
|
|
65
|
+
// console.log(`keytype: ${keyType}, codecName: ${codecName}`)
|
|
66
|
+
const key = yield (0, ssi_sdk_ext_key_utils_1.importProvidedOrGeneratedKey)({
|
|
67
|
+
// @ts-ignore
|
|
68
|
+
kms: kms !== null && kms !== void 0 ? kms : this.kms,
|
|
69
|
+
alias: alias,
|
|
70
|
+
options: Object.assign(Object.assign({}, options), { type: keyType }),
|
|
71
|
+
}, context);
|
|
72
|
+
let methodSpecificId;
|
|
73
|
+
// did:key uses compressed pub keys
|
|
74
|
+
const compressedPublicKeyHex = (0, ssi_sdk_ext_key_utils_1.toRawCompressedHexPublicKey)(u8a.fromString(key.publicKeyHex, 'hex'), key.type);
|
|
75
|
+
if (codecName === ssi_sdk_ext_key_utils_1.JWK_JCS_PUB_NAME) {
|
|
76
|
+
const jwk = (0, ssi_sdk_ext_key_utils_1.toJwk)(key.publicKeyHex, keyType, { use: ssi_sdk_ext_key_utils_1.JwkKeyUse.Signature, key, noKidThumbprint: true });
|
|
77
|
+
// console.log(`FIXME JWK: ${JSON.stringify(toJwk(privateKeyHex, keyType, { use: JwkKeyUse.Signature, key, isPrivateKey: true }), null, 2)}`)
|
|
78
|
+
methodSpecificId = u8a.toString(multibase_1.default.encode('base58btc', multicodec_1.default.addPrefix(u8a.fromString(ssi_sdk_ext_key_utils_1.JWK_JCS_PUB_PREFIX.valueOf().toString(16), 'hex'), (0, ssi_sdk_ext_key_utils_1.jwkJcsEncode)(jwk))));
|
|
79
|
+
}
|
|
80
|
+
else if (codecName) {
|
|
81
|
+
methodSpecificId = u8a.toString(multibase_1.default.encode('base58btc', multicodec_1.default.addPrefix(codecName, u8a.fromString(compressedPublicKeyHex, 'hex'))));
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
codecName = keyCodecs[keyType];
|
|
85
|
+
if (codecName) {
|
|
86
|
+
// methodSpecificId = bytesToMultibase({bytes: u8a.fromString(key.publicKeyHex, 'hex'), codecName})
|
|
87
|
+
methodSpecificId = u8a
|
|
88
|
+
.toString(multibase_1.default.encode('base58btc', multicodec_1.default.addPrefix(codecName, u8a.fromString(compressedPublicKeyHex, 'hex'))))
|
|
89
|
+
.toString();
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (!methodSpecificId) {
|
|
93
|
+
throw Error(`Key type ${keyType}, codec ${codecName} is not supported currently for did:key`);
|
|
94
|
+
}
|
|
95
|
+
const identifier = {
|
|
96
|
+
did: `did:key:${methodSpecificId}`,
|
|
97
|
+
controllerKeyId: key.kid,
|
|
98
|
+
keys: [key],
|
|
99
|
+
services: [],
|
|
100
|
+
};
|
|
101
|
+
debug('Created', identifier.did);
|
|
102
|
+
return identifier;
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
updateIdentifier(args, context) {
|
|
106
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
107
|
+
throw new Error('KeyDIDProvider updateIdentifier not supported yet.');
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
deleteIdentifier(identifier, context) {
|
|
111
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
112
|
+
for (const { kid } of identifier.keys) {
|
|
113
|
+
yield context.agent.keyManagerDelete({ kid });
|
|
114
|
+
}
|
|
115
|
+
return true;
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
addKey(_a, context_1) {
|
|
119
|
+
return __awaiter(this, arguments, void 0, function* ({ identifier, key, options }, context) {
|
|
120
|
+
throw Error('KeyDIDProvider addKey not supported');
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
addService(_a, context_1) {
|
|
124
|
+
return __awaiter(this, arguments, void 0, function* ({ identifier, service, options }, context) {
|
|
125
|
+
throw Error('KeyDIDProvider addService not supported');
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
removeKey(args, context) {
|
|
129
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
130
|
+
throw Error('KeyDIDProvider removeKey not supported');
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
removeService(args, context) {
|
|
134
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
135
|
+
throw Error('KeyDIDProvider removeService not supported');
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
exports.SphereonKeyDidProvider = SphereonKeyDidProvider;
|
|
140
|
+
//# sourceMappingURL=SphereonKeyDidProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SphereonKeyDidProvider.js","sourceRoot":"","sources":["../src/SphereonKeyDidProvider.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2EASwC;AAExC,qDAAgE;AAChE,kDAAyB;AACzB,0DAAiC;AACjC,4DAAmC;AACnC,iDAAkC;AAElC,MAAM,KAAK,GAAG,IAAA,eAAK,EAAC,kBAAkB,CAAC,CAAA;AAIvC,M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lHD,wDAkHC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,58 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import Multicodec from 'multicodec';
|
|
5
|
-
import { DIDResolver } from 'did-resolver';
|
|
6
|
-
|
|
7
|
-
type IContext = IAgentContext<IKeyManager>;
|
|
8
|
-
declare class SphereonKeyDidProvider extends AbstractIdentifierProvider {
|
|
9
|
-
private readonly kms?;
|
|
10
|
-
constructor(options: {
|
|
11
|
-
defaultKms?: string;
|
|
12
|
-
});
|
|
13
|
-
createIdentifier({ kms, alias, options, }: {
|
|
14
|
-
kms?: string;
|
|
15
|
-
alias?: string;
|
|
16
|
-
options?: {
|
|
17
|
-
type?: TKeyType;
|
|
18
|
-
codecName?: 'EBSI' | 'jwk_jcs-pub' | Multicodec.CodecName;
|
|
19
|
-
key?: {
|
|
20
|
-
type?: Exclude<TKeyType, 'Secp384r1' | 'Secp521r1'>;
|
|
21
|
-
privateKeyHex: string;
|
|
22
|
-
};
|
|
23
|
-
};
|
|
24
|
-
}, context: IContext): Promise<Omit<IIdentifier, 'provider'>>;
|
|
25
|
-
updateIdentifier(args: {
|
|
26
|
-
did: string;
|
|
27
|
-
kms?: string | undefined;
|
|
28
|
-
alias?: string | undefined;
|
|
29
|
-
options?: any;
|
|
30
|
-
}, context: IAgentContext<IKeyManager>): Promise<IIdentifier>;
|
|
31
|
-
deleteIdentifier(identifier: IIdentifier, context: IContext): Promise<boolean>;
|
|
32
|
-
addKey({ identifier, key, options }: {
|
|
33
|
-
identifier: IIdentifier;
|
|
34
|
-
key: IKey;
|
|
35
|
-
options?: any;
|
|
36
|
-
}, context: IContext): Promise<any>;
|
|
37
|
-
addService({ identifier, service, options }: {
|
|
38
|
-
identifier: IIdentifier;
|
|
39
|
-
service: IService;
|
|
40
|
-
options?: any;
|
|
41
|
-
}, context: IContext): Promise<any>;
|
|
42
|
-
removeKey(args: {
|
|
43
|
-
identifier: IIdentifier;
|
|
44
|
-
kid: string;
|
|
45
|
-
options?: any;
|
|
46
|
-
}, context: IContext): Promise<any>;
|
|
47
|
-
removeService(args: {
|
|
48
|
-
identifier: IIdentifier;
|
|
49
|
-
id: string;
|
|
50
|
-
options?: any;
|
|
51
|
-
}, context: IContext): Promise<any>;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
declare function getDidKeyResolver(): {
|
|
55
|
-
key: DIDResolver;
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
export { SphereonKeyDidProvider, getDidKeyResolver };
|
|
1
|
+
export { SphereonKeyDidProvider } from './SphereonKeyDidProvider';
|
|
2
|
+
export { getDidKeyResolver } from './KeyDidResolver';
|
|
3
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAA;AACjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,118 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
import Multibase from "multibase";
|
|
9
|
-
import Multicodec from "multicodec";
|
|
10
|
-
import { fromString } from "uint8arrays/from-string";
|
|
11
|
-
import { toString } from "uint8arrays/to-string";
|
|
12
|
-
var debug = Debug("did-provider-key");
|
|
13
|
-
var keyCodecs = {
|
|
14
|
-
RSA: "rsa-pub",
|
|
15
|
-
Ed25519: "ed25519-pub",
|
|
16
|
-
X25519: "x25519-pub",
|
|
17
|
-
Secp256k1: "secp256k1-pub",
|
|
18
|
-
Secp256r1: "p256-pub",
|
|
19
|
-
Bls12381G1: "bls12_381-g1-pub",
|
|
20
|
-
Bls12381G2: "bls12_381-g2-pub"
|
|
21
|
-
};
|
|
22
|
-
var SphereonKeyDidProvider = class extends AbstractIdentifierProvider {
|
|
23
|
-
static {
|
|
24
|
-
__name(this, "SphereonKeyDidProvider");
|
|
25
|
-
}
|
|
26
|
-
kms;
|
|
27
|
-
constructor(options) {
|
|
28
|
-
super();
|
|
29
|
-
this.kms = options.defaultKms;
|
|
30
|
-
}
|
|
31
|
-
async createIdentifier({ kms, alias, options }, context) {
|
|
32
|
-
let codecName = options?.codecName?.toUpperCase() === "EBSI" ? JWK_JCS_PUB_NAME : options?.codecName;
|
|
33
|
-
const keyType = options?.type ?? options?.key?.type ?? (codecName === JWK_JCS_PUB_NAME ? "Secp256r1" : "Secp256k1");
|
|
34
|
-
const key = await importProvidedOrGeneratedKey({
|
|
35
|
-
// @ts-ignore
|
|
36
|
-
kms: kms ?? this.kms,
|
|
37
|
-
alias,
|
|
38
|
-
options: {
|
|
39
|
-
...options,
|
|
40
|
-
type: keyType
|
|
41
|
-
}
|
|
42
|
-
}, context);
|
|
43
|
-
let methodSpecificId;
|
|
44
|
-
const compressedPublicKeyHex = toRawCompressedHexPublicKey(fromString(key.publicKeyHex, "hex"), key.type);
|
|
45
|
-
if (codecName === JWK_JCS_PUB_NAME) {
|
|
46
|
-
const jwk = toJwk(key.publicKeyHex, keyType, {
|
|
47
|
-
use: JwkKeyUse.Signature,
|
|
48
|
-
key,
|
|
49
|
-
noKidThumbprint: true
|
|
50
|
-
});
|
|
51
|
-
methodSpecificId = toString(Multibase.encode("base58btc", Multicodec.addPrefix(fromString(JWK_JCS_PUB_PREFIX.valueOf().toString(16), "hex"), jwkJcsEncode(jwk))));
|
|
52
|
-
} else if (codecName) {
|
|
53
|
-
methodSpecificId = toString(Multibase.encode("base58btc", Multicodec.addPrefix(codecName, fromString(compressedPublicKeyHex, "hex"))));
|
|
54
|
-
} else {
|
|
55
|
-
codecName = keyCodecs[keyType];
|
|
56
|
-
if (codecName) {
|
|
57
|
-
methodSpecificId = toString(Multibase.encode("base58btc", Multicodec.addPrefix(codecName, fromString(compressedPublicKeyHex, "hex")))).toString();
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
if (!methodSpecificId) {
|
|
61
|
-
throw Error(`Key type ${keyType}, codec ${codecName} is not supported currently for did:key`);
|
|
62
|
-
}
|
|
63
|
-
const identifier = {
|
|
64
|
-
did: `did:key:${methodSpecificId}`,
|
|
65
|
-
controllerKeyId: key.kid,
|
|
66
|
-
keys: [
|
|
67
|
-
key
|
|
68
|
-
],
|
|
69
|
-
services: []
|
|
70
|
-
};
|
|
71
|
-
debug("Created", identifier.did);
|
|
72
|
-
return identifier;
|
|
73
|
-
}
|
|
74
|
-
async updateIdentifier(args, context) {
|
|
75
|
-
throw new Error("KeyDIDProvider updateIdentifier not supported yet.");
|
|
76
|
-
}
|
|
77
|
-
async deleteIdentifier(identifier, context) {
|
|
78
|
-
for (const { kid } of identifier.keys) {
|
|
79
|
-
await context.agent.keyManagerDelete({
|
|
80
|
-
kid
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
return true;
|
|
84
|
-
}
|
|
85
|
-
async addKey({ identifier, key, options }, context) {
|
|
86
|
-
throw Error("KeyDIDProvider addKey not supported");
|
|
87
|
-
}
|
|
88
|
-
async addService({ identifier, service, options }, context) {
|
|
89
|
-
throw Error("KeyDIDProvider addService not supported");
|
|
90
|
-
}
|
|
91
|
-
async removeKey(args, context) {
|
|
92
|
-
throw Error("KeyDIDProvider removeKey not supported");
|
|
93
|
-
}
|
|
94
|
-
async removeService(args, context) {
|
|
95
|
-
throw Error("KeyDIDProvider removeService not supported");
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
// src/KeyDidResolver.ts
|
|
100
|
-
import { Resolver } from "did-resolver";
|
|
101
|
-
import { getResolver } from "@sphereon/ssi-sdk-ext.did-resolver-key";
|
|
102
|
-
var resolveDidKey = /* @__PURE__ */ __name(async (didUrl, _parsed, _resolver, options) => {
|
|
103
|
-
const resolver = new Resolver({
|
|
104
|
-
...getResolver()
|
|
105
|
-
});
|
|
106
|
-
return resolver.resolve(didUrl, options);
|
|
107
|
-
}, "resolveDidKey");
|
|
108
|
-
function getDidKeyResolver() {
|
|
109
|
-
return {
|
|
110
|
-
key: resolveDidKey
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
__name(getDidKeyResolver, "getDidKeyResolver");
|
|
114
|
-
export {
|
|
115
|
-
SphereonKeyDidProvider,
|
|
116
|
-
getDidKeyResolver
|
|
117
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getDidKeyResolver = exports.SphereonKeyDidProvider = void 0;
|
|
4
|
+
var SphereonKeyDidProvider_1 = require("./SphereonKeyDidProvider");
|
|
5
|
+
Object.defineProperty(exports, "SphereonKeyDidProvider", { enumerable: true, get: function () { return SphereonKeyDidProvider_1.SphereonKeyDidProvider; } });
|
|
6
|
+
var KeyDidResolver_1 = require("./KeyDidResolver");
|
|
7
|
+
Object.defineProperty(exports, "getDidKeyResolver", { enumerable: true, get: function () { return KeyDidResolver_1.getDidKeyResolver; } });
|
|
118
8
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,mEAAiE;AAAxD,gIAAA,sBAAsB,OAAA;AAC/B,mDAAoD;AAA3C,mHAAA,iBAAiB,OAAA"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { AbstractIdentifierProvider } from '@veramo/did-manager';
|
|
2
|
+
import { DIDResolver } from 'did-resolver';
|
|
3
|
+
import { IAgentContext } from '@veramo/core';
|
|
4
|
+
import { IIdentifier } from '@veramo/core';
|
|
5
|
+
import { IKey } from '@veramo/core';
|
|
6
|
+
import { IKeyManager } from '@veramo/core';
|
|
7
|
+
import { IService } from '@veramo/core';
|
|
8
|
+
import Multicodec from 'multicodec';
|
|
9
|
+
import { TKeyType } from '@sphereon/ssi-sdk-ext.key-utils';
|
|
10
|
+
|
|
11
|
+
export declare function getDidKeyResolver(): {
|
|
12
|
+
key: DIDResolver;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
declare type IContext = IAgentContext<IKeyManager>;
|
|
16
|
+
|
|
17
|
+
export declare class SphereonKeyDidProvider extends AbstractIdentifierProvider {
|
|
18
|
+
private readonly kms?;
|
|
19
|
+
constructor(options: {
|
|
20
|
+
defaultKms?: string;
|
|
21
|
+
});
|
|
22
|
+
createIdentifier({ kms, alias, options, }: {
|
|
23
|
+
kms?: string;
|
|
24
|
+
alias?: string;
|
|
25
|
+
options?: {
|
|
26
|
+
type?: TKeyType;
|
|
27
|
+
codecName?: 'EBSI' | 'jwk_jcs-pub' | Multicodec.CodecName;
|
|
28
|
+
key?: {
|
|
29
|
+
type?: Exclude<TKeyType, 'Secp384r1' | 'Secp521r1'>;
|
|
30
|
+
privateKeyHex: string;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
}, context: IContext): Promise<Omit<IIdentifier, 'provider'>>;
|
|
34
|
+
updateIdentifier(args: {
|
|
35
|
+
did: string;
|
|
36
|
+
kms?: string | undefined;
|
|
37
|
+
alias?: string | undefined;
|
|
38
|
+
options?: any;
|
|
39
|
+
}, context: IAgentContext<IKeyManager>): Promise<IIdentifier>;
|
|
40
|
+
deleteIdentifier(identifier: IIdentifier, context: IContext): Promise<boolean>;
|
|
41
|
+
addKey({ identifier, key, options }: {
|
|
42
|
+
identifier: IIdentifier;
|
|
43
|
+
key: IKey;
|
|
44
|
+
options?: any;
|
|
45
|
+
}, context: IContext): Promise<any>;
|
|
46
|
+
addService({ identifier, service, options }: {
|
|
47
|
+
identifier: IIdentifier;
|
|
48
|
+
service: IService;
|
|
49
|
+
options?: any;
|
|
50
|
+
}, context: IContext): Promise<any>;
|
|
51
|
+
removeKey(args: {
|
|
52
|
+
identifier: IIdentifier;
|
|
53
|
+
kid: string;
|
|
54
|
+
options?: any;
|
|
55
|
+
}, context: IContext): Promise<any>;
|
|
56
|
+
removeService(args: {
|
|
57
|
+
identifier: IIdentifier;
|
|
58
|
+
id: string;
|
|
59
|
+
options?: any;
|
|
60
|
+
}, context: IContext): Promise<any>;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export { }
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// This file is read by tools that parse documentation comments conforming to the TSDoc standard.
|
|
2
|
+
// It should be published with your NPM package. It should not be tracked by Git.
|
|
3
|
+
{
|
|
4
|
+
"tsdocVersion": "0.12",
|
|
5
|
+
"toolPackages": [
|
|
6
|
+
{
|
|
7
|
+
"packageName": "@microsoft/api-extractor",
|
|
8
|
+
"packageVersion": "7.52.5"
|
|
9
|
+
}
|
|
10
|
+
]
|
|
11
|
+
}
|
package/package.json
CHANGED
|
@@ -1,29 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sphereon/ssi-sdk-ext.did-provider-key",
|
|
3
3
|
"description": "Sphereon SSI-SDK plugin for management of did:key identifiers.",
|
|
4
|
-
"version": "0.28.1-feature.
|
|
5
|
-
"source": "
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"module": "./dist/index.js",
|
|
9
|
-
"types": "./dist/index.d.ts",
|
|
10
|
-
"exports": {
|
|
11
|
-
"import": {
|
|
12
|
-
"types": "./dist/index.d.ts",
|
|
13
|
-
"import": "./dist/index.js"
|
|
14
|
-
},
|
|
15
|
-
"require": {
|
|
16
|
-
"types": "./dist/index.d.cts",
|
|
17
|
-
"require": "./dist/index.cjs"
|
|
18
|
-
}
|
|
19
|
-
},
|
|
4
|
+
"version": "0.28.1-feature.oyd.cmsm.improv.16+a254c6d",
|
|
5
|
+
"source": "src/index.ts",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
20
8
|
"scripts": {
|
|
21
|
-
"build": "
|
|
9
|
+
"build": "tsc",
|
|
22
10
|
"extract-api": "sphereon dev extract-api"
|
|
23
11
|
},
|
|
24
12
|
"dependencies": {
|
|
25
|
-
"@sphereon/ssi-sdk-ext.did-resolver-key": "
|
|
26
|
-
"@sphereon/ssi-sdk-ext.key-utils": "
|
|
13
|
+
"@sphereon/ssi-sdk-ext.did-resolver-key": "0.28.1-feature.oyd.cmsm.improv.16+a254c6d",
|
|
14
|
+
"@sphereon/ssi-sdk-ext.key-utils": "0.28.1-feature.oyd.cmsm.improv.16+a254c6d",
|
|
27
15
|
"@transmute/did-key-bls12381": "0.3.0-unstable.10",
|
|
28
16
|
"@veramo/core": "4.2.0",
|
|
29
17
|
"@veramo/did-manager": "4.2.0",
|
|
@@ -32,12 +20,12 @@
|
|
|
32
20
|
"did-resolver": "^4.1.0",
|
|
33
21
|
"multibase": "^4.0.6",
|
|
34
22
|
"multicodec": "^3.2.1",
|
|
35
|
-
"uint8arrays": "
|
|
23
|
+
"uint8arrays": "^3.1.1"
|
|
36
24
|
},
|
|
37
25
|
"devDependencies": {
|
|
38
|
-
"@sphereon/ssi-sdk-ext.key-manager": "
|
|
39
|
-
"@sphereon/ssi-sdk-ext.kms-local": "
|
|
40
|
-
"@sphereon/ssi-sdk.dev": "
|
|
26
|
+
"@sphereon/ssi-sdk-ext.key-manager": "0.28.1-feature.oyd.cmsm.improv.16+a254c6d",
|
|
27
|
+
"@sphereon/ssi-sdk-ext.kms-local": "0.28.1-feature.oyd.cmsm.improv.16+a254c6d",
|
|
28
|
+
"@sphereon/ssi-sdk.dev": "0.30.2-feature.SDK.41.oidf.support.286",
|
|
41
29
|
"@veramo/did-resolver": "4.2.0",
|
|
42
30
|
"@veramo/key-manager": "4.2.0"
|
|
43
31
|
},
|
|
@@ -46,8 +34,8 @@
|
|
|
46
34
|
"jsonld-signatures": "npm:@digitalcredentials/jsonld-signatures@^9.3.1"
|
|
47
35
|
},
|
|
48
36
|
"files": [
|
|
49
|
-
"dist",
|
|
50
|
-
"src",
|
|
37
|
+
"dist/**/*",
|
|
38
|
+
"src/**/*",
|
|
51
39
|
"README.md",
|
|
52
40
|
"LICENSE"
|
|
53
41
|
],
|
|
@@ -71,5 +59,5 @@
|
|
|
71
59
|
"secp256r1",
|
|
72
60
|
"RSA"
|
|
73
61
|
],
|
|
74
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "a254c6d44af6fbb12419b55054f1db5afbe484f0"
|
|
75
63
|
}
|
|
@@ -13,10 +13,7 @@ import { AbstractIdentifierProvider } from '@veramo/did-manager'
|
|
|
13
13
|
import Debug from 'debug'
|
|
14
14
|
import Multibase from 'multibase'
|
|
15
15
|
import Multicodec from 'multicodec'
|
|
16
|
-
|
|
17
|
-
import { fromString } from 'uint8arrays/from-string'
|
|
18
|
-
// @ts-ignore
|
|
19
|
-
import { toString } from 'uint8arrays/to-string'
|
|
16
|
+
import * as u8a from 'uint8arrays'
|
|
20
17
|
|
|
21
18
|
const debug = Debug('did-provider-key')
|
|
22
19
|
|
|
@@ -81,25 +78,27 @@ export class SphereonKeyDidProvider extends AbstractIdentifierProvider {
|
|
|
81
78
|
let methodSpecificId: string | undefined
|
|
82
79
|
|
|
83
80
|
// did:key uses compressed pub keys
|
|
84
|
-
const compressedPublicKeyHex = toRawCompressedHexPublicKey(fromString(key.publicKeyHex, 'hex'), key.type)
|
|
81
|
+
const compressedPublicKeyHex = toRawCompressedHexPublicKey(u8a.fromString(key.publicKeyHex, 'hex'), key.type)
|
|
85
82
|
if (codecName === JWK_JCS_PUB_NAME) {
|
|
86
83
|
const jwk = toJwk(key.publicKeyHex, keyType, { use: JwkKeyUse.Signature, key, noKidThumbprint: true })
|
|
87
84
|
// console.log(`FIXME JWK: ${JSON.stringify(toJwk(privateKeyHex, keyType, { use: JwkKeyUse.Signature, key, isPrivateKey: true }), null, 2)}`)
|
|
88
|
-
methodSpecificId = toString(
|
|
89
|
-
Multibase.encode('base58btc', Multicodec.addPrefix(fromString(JWK_JCS_PUB_PREFIX.valueOf().toString(16), 'hex'), jwkJcsEncode(jwk)))
|
|
85
|
+
methodSpecificId = u8a.toString(
|
|
86
|
+
Multibase.encode('base58btc', Multicodec.addPrefix(u8a.fromString(JWK_JCS_PUB_PREFIX.valueOf().toString(16), 'hex'), jwkJcsEncode(jwk)))
|
|
90
87
|
)
|
|
91
88
|
} else if (codecName) {
|
|
92
|
-
methodSpecificId = toString(
|
|
93
|
-
Multibase.encode('base58btc', Multicodec.addPrefix(codecName as Multicodec.CodecName, fromString(compressedPublicKeyHex, 'hex')))
|
|
89
|
+
methodSpecificId = u8a.toString(
|
|
90
|
+
Multibase.encode('base58btc', Multicodec.addPrefix(codecName as Multicodec.CodecName, u8a.fromString(compressedPublicKeyHex, 'hex')))
|
|
94
91
|
)
|
|
95
92
|
} else {
|
|
96
93
|
codecName = keyCodecs[keyType]
|
|
97
94
|
|
|
98
95
|
if (codecName) {
|
|
99
96
|
// methodSpecificId = bytesToMultibase({bytes: u8a.fromString(key.publicKeyHex, 'hex'), codecName})
|
|
100
|
-
methodSpecificId =
|
|
101
|
-
|
|
102
|
-
|
|
97
|
+
methodSpecificId = u8a
|
|
98
|
+
.toString(
|
|
99
|
+
Multibase.encode('base58btc', Multicodec.addPrefix(codecName as Multicodec.CodecName, u8a.fromString(compressedPublicKeyHex, 'hex')))
|
|
100
|
+
)
|
|
101
|
+
.toString()
|
|
103
102
|
}
|
|
104
103
|
}
|
|
105
104
|
if (!methodSpecificId) {
|
package/dist/index.cjs
DELETED
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var __defProp = Object.defineProperty;
|
|
2
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
|
|
4
|
-
// src/SphereonKeyDidProvider.ts
|
|
5
|
-
var _ssisdkextkeyutils = require('@sphereon/ssi-sdk-ext.key-utils');
|
|
6
|
-
var _didmanager = require('@veramo/did-manager');
|
|
7
|
-
var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug);
|
|
8
|
-
var _multibase = require('multibase'); var _multibase2 = _interopRequireDefault(_multibase);
|
|
9
|
-
var _multicodec = require('multicodec'); var _multicodec2 = _interopRequireDefault(_multicodec);
|
|
10
|
-
var _fromstring = require('uint8arrays/from-string');
|
|
11
|
-
var _tostring = require('uint8arrays/to-string');
|
|
12
|
-
var debug = _debug2.default.call(void 0, "did-provider-key");
|
|
13
|
-
var keyCodecs = {
|
|
14
|
-
RSA: "rsa-pub",
|
|
15
|
-
Ed25519: "ed25519-pub",
|
|
16
|
-
X25519: "x25519-pub",
|
|
17
|
-
Secp256k1: "secp256k1-pub",
|
|
18
|
-
Secp256r1: "p256-pub",
|
|
19
|
-
Bls12381G1: "bls12_381-g1-pub",
|
|
20
|
-
Bls12381G2: "bls12_381-g2-pub"
|
|
21
|
-
};
|
|
22
|
-
var SphereonKeyDidProvider = class extends _didmanager.AbstractIdentifierProvider {
|
|
23
|
-
static {
|
|
24
|
-
__name(this, "SphereonKeyDidProvider");
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
constructor(options) {
|
|
28
|
-
super();
|
|
29
|
-
this.kms = options.defaultKms;
|
|
30
|
-
}
|
|
31
|
-
async createIdentifier({ kms, alias, options }, context) {
|
|
32
|
-
let codecName = _optionalChain([options, 'optionalAccess', _ => _.codecName, 'optionalAccess', _2 => _2.toUpperCase, 'call', _3 => _3()]) === "EBSI" ? _ssisdkextkeyutils.JWK_JCS_PUB_NAME : _optionalChain([options, 'optionalAccess', _4 => _4.codecName]);
|
|
33
|
-
const keyType = _nullishCoalesce(_nullishCoalesce(_optionalChain([options, 'optionalAccess', _5 => _5.type]), () => ( _optionalChain([options, 'optionalAccess', _6 => _6.key, 'optionalAccess', _7 => _7.type]))), () => ( (codecName === _ssisdkextkeyutils.JWK_JCS_PUB_NAME ? "Secp256r1" : "Secp256k1")));
|
|
34
|
-
const key = await _ssisdkextkeyutils.importProvidedOrGeneratedKey.call(void 0, {
|
|
35
|
-
// @ts-ignore
|
|
36
|
-
kms: _nullishCoalesce(kms, () => ( this.kms)),
|
|
37
|
-
alias,
|
|
38
|
-
options: {
|
|
39
|
-
...options,
|
|
40
|
-
type: keyType
|
|
41
|
-
}
|
|
42
|
-
}, context);
|
|
43
|
-
let methodSpecificId;
|
|
44
|
-
const compressedPublicKeyHex = _ssisdkextkeyutils.toRawCompressedHexPublicKey.call(void 0, _fromstring.fromString.call(void 0, key.publicKeyHex, "hex"), key.type);
|
|
45
|
-
if (codecName === _ssisdkextkeyutils.JWK_JCS_PUB_NAME) {
|
|
46
|
-
const jwk = _ssisdkextkeyutils.toJwk.call(void 0, key.publicKeyHex, keyType, {
|
|
47
|
-
use: _ssisdkextkeyutils.JwkKeyUse.Signature,
|
|
48
|
-
key,
|
|
49
|
-
noKidThumbprint: true
|
|
50
|
-
});
|
|
51
|
-
methodSpecificId = _tostring.toString.call(void 0, _multibase2.default.encode("base58btc", _multicodec2.default.addPrefix(_fromstring.fromString.call(void 0, _ssisdkextkeyutils.JWK_JCS_PUB_PREFIX.valueOf().toString(16), "hex"), _ssisdkextkeyutils.jwkJcsEncode.call(void 0, jwk))));
|
|
52
|
-
} else if (codecName) {
|
|
53
|
-
methodSpecificId = _tostring.toString.call(void 0, _multibase2.default.encode("base58btc", _multicodec2.default.addPrefix(codecName, _fromstring.fromString.call(void 0, compressedPublicKeyHex, "hex"))));
|
|
54
|
-
} else {
|
|
55
|
-
codecName = keyCodecs[keyType];
|
|
56
|
-
if (codecName) {
|
|
57
|
-
methodSpecificId = _tostring.toString.call(void 0, _multibase2.default.encode("base58btc", _multicodec2.default.addPrefix(codecName, _fromstring.fromString.call(void 0, compressedPublicKeyHex, "hex")))).toString();
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
if (!methodSpecificId) {
|
|
61
|
-
throw Error(`Key type ${keyType}, codec ${codecName} is not supported currently for did:key`);
|
|
62
|
-
}
|
|
63
|
-
const identifier = {
|
|
64
|
-
did: `did:key:${methodSpecificId}`,
|
|
65
|
-
controllerKeyId: key.kid,
|
|
66
|
-
keys: [
|
|
67
|
-
key
|
|
68
|
-
],
|
|
69
|
-
services: []
|
|
70
|
-
};
|
|
71
|
-
debug("Created", identifier.did);
|
|
72
|
-
return identifier;
|
|
73
|
-
}
|
|
74
|
-
async updateIdentifier(args, context) {
|
|
75
|
-
throw new Error("KeyDIDProvider updateIdentifier not supported yet.");
|
|
76
|
-
}
|
|
77
|
-
async deleteIdentifier(identifier, context) {
|
|
78
|
-
for (const { kid } of identifier.keys) {
|
|
79
|
-
await context.agent.keyManagerDelete({
|
|
80
|
-
kid
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
return true;
|
|
84
|
-
}
|
|
85
|
-
async addKey({ identifier, key, options }, context) {
|
|
86
|
-
throw Error("KeyDIDProvider addKey not supported");
|
|
87
|
-
}
|
|
88
|
-
async addService({ identifier, service, options }, context) {
|
|
89
|
-
throw Error("KeyDIDProvider addService not supported");
|
|
90
|
-
}
|
|
91
|
-
async removeKey(args, context) {
|
|
92
|
-
throw Error("KeyDIDProvider removeKey not supported");
|
|
93
|
-
}
|
|
94
|
-
async removeService(args, context) {
|
|
95
|
-
throw Error("KeyDIDProvider removeService not supported");
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
// src/KeyDidResolver.ts
|
|
100
|
-
var _didresolver = require('did-resolver');
|
|
101
|
-
var _ssisdkextdidresolverkey = require('@sphereon/ssi-sdk-ext.did-resolver-key');
|
|
102
|
-
var resolveDidKey = /* @__PURE__ */ __name(async (didUrl, _parsed, _resolver, options) => {
|
|
103
|
-
const resolver = new (0, _didresolver.Resolver)({
|
|
104
|
-
..._ssisdkextdidresolverkey.getResolver.call(void 0, )
|
|
105
|
-
});
|
|
106
|
-
return resolver.resolve(didUrl, options);
|
|
107
|
-
}, "resolveDidKey");
|
|
108
|
-
function getDidKeyResolver() {
|
|
109
|
-
return {
|
|
110
|
-
key: resolveDidKey
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
__name(getDidKeyResolver, "getDidKeyResolver");
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
exports.SphereonKeyDidProvider = SphereonKeyDidProvider; exports.getDidKeyResolver = getDidKeyResolver;
|
|
118
|
-
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/SSI-SDK-crypto-extensions/SSI-SDK-crypto-extensions/packages/did-provider-key/dist/index.cjs","../src/SphereonKeyDidProvider.ts","../src/KeyDidResolver.ts"],"names":["debug","Debug","keyCodecs","RSA","Ed25519","X25519","Secp256k1","Secp256r1","Bls12381G1","Bls12381G2","SphereonKeyDidProvider","AbstractIdentifierProvider","kms","constructor","options","defaultKms","createIdentifier","alias","context","codecName","toUpperCase","JWK_JCS_PUB_NAME","keyType","type","key","importProvidedOrGeneratedKey","methodSpecificId","compressedPublicKeyHex","toRawCompressedHexPublicKey","fromString","publicKeyHex","jwk","toJwk","use","JwkKeyUse","Signature","noKidThumbprint","toString","Multibase","encode","Multicodec","addPrefix","JWK_JCS_PUB_PREFIX","valueOf","jwkJcsEncode","Error","identifier","did","kid","keys","keyManagerDelete","service","getResolver","getDidKeyResolver","resolveDidKey"],"mappings":"AAAA,qxBAAI,UAAU,EAAE,MAAM,CAAC,cAAc;AACrC,IAAI,OAAO,EAAE,CAAC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IAAAA;AAAc,EAAA;AAC9B;AAFgBD;AFoGuB;AACA;AACA;AACA","file":"/home/runner/work/SSI-SDK-crypto-extensions/SSI-SDK-crypto-extensions/packages/did-provider-key/dist/index.cjs","sourcesContent":[null,"import {\n importProvidedOrGeneratedKey,\n JWK_JCS_PUB_NAME,\n JWK_JCS_PUB_PREFIX,\n jwkJcsEncode,\n JwkKeyUse,\n TKeyType,\n toJwk,\n toRawCompressedHexPublicKey,\n} from '@sphereon/ssi-sdk-ext.key-utils'\nimport { IAgentContext, IIdentifier, IKey, IKeyManager, IService } from '@veramo/core'\nimport { AbstractIdentifierProvider } from '@veramo/did-manager'\nimport Debug from 'debug'\nimport Multibase from 'multibase'\nimport Multicodec from 'multicodec'\n// @ts-ignore\nimport { fromString } from 'uint8arrays/from-string'\n// @ts-ignore\nimport { toString } from 'uint8arrays/to-string'\n\nconst debug = Debug('did-provider-key')\n\ntype IContext = IAgentContext<IKeyManager>\n\nconst keyCodecs = {\n RSA: 'rsa-pub',\n Ed25519: 'ed25519-pub',\n X25519: 'x25519-pub',\n Secp256k1: 'secp256k1-pub',\n Secp256r1: 'p256-pub',\n Bls12381G1: 'bls12_381-g1-pub',\n Bls12381G2: 'bls12_381-g2-pub',\n} as const\n\nexport class SphereonKeyDidProvider extends AbstractIdentifierProvider {\n private readonly kms?: string\n\n constructor(options: { defaultKms?: string }) {\n super()\n this.kms = options.defaultKms\n }\n\n async createIdentifier(\n {\n kms,\n alias,\n options,\n }: {\n kms?: string\n alias?: string\n options?: {\n type?: TKeyType\n codecName?: 'EBSI' | 'jwk_jcs-pub' | Multicodec.CodecName\n key?: {\n type?: Exclude<TKeyType, 'Secp384r1' | 'Secp521r1'>\n privateKeyHex: string\n }\n }\n },\n context: IContext\n ): Promise<Omit<IIdentifier, 'provider'>> {\n let codecName = (options?.codecName?.toUpperCase() === 'EBSI' ? (JWK_JCS_PUB_NAME as Multicodec.CodecName) : options?.codecName) as\n | CodeNameType\n | undefined\n const keyType = (options?.type ?? options?.key?.type ?? (codecName === JWK_JCS_PUB_NAME ? 'Secp256r1' : 'Secp256k1')) as Exclude<\n TKeyType,\n 'Secp384r1' | 'Secp521r1'\n >\n // console.log(`keytype: ${keyType}, codecName: ${codecName}`)\n\n const key = await importProvidedOrGeneratedKey(\n {\n // @ts-ignore\n kms: kms ?? this.kms,\n alias: alias,\n options: { ...options, type: keyType },\n },\n context\n )\n\n let methodSpecificId: string | undefined\n\n // did:key uses compressed pub keys\n const compressedPublicKeyHex = toRawCompressedHexPublicKey(fromString(key.publicKeyHex, 'hex'), key.type)\n if (codecName === JWK_JCS_PUB_NAME) {\n const jwk = toJwk(key.publicKeyHex, keyType, { use: JwkKeyUse.Signature, key, noKidThumbprint: true })\n // console.log(`FIXME JWK: ${JSON.stringify(toJwk(privateKeyHex, keyType, { use: JwkKeyUse.Signature, key, isPrivateKey: true }), null, 2)}`)\n methodSpecificId = toString(\n Multibase.encode('base58btc', Multicodec.addPrefix(fromString(JWK_JCS_PUB_PREFIX.valueOf().toString(16), 'hex'), jwkJcsEncode(jwk)))\n )\n } else if (codecName) {\n methodSpecificId = toString(\n Multibase.encode('base58btc', Multicodec.addPrefix(codecName as Multicodec.CodecName, fromString(compressedPublicKeyHex, 'hex')))\n )\n } else {\n codecName = keyCodecs[keyType]\n\n if (codecName) {\n // methodSpecificId = bytesToMultibase({bytes: u8a.fromString(key.publicKeyHex, 'hex'), codecName})\n methodSpecificId = toString(\n Multibase.encode('base58btc', Multicodec.addPrefix(codecName as Multicodec.CodecName, fromString(compressedPublicKeyHex, 'hex')))\n ).toString()\n }\n }\n if (!methodSpecificId) {\n throw Error(`Key type ${keyType}, codec ${codecName} is not supported currently for did:key`)\n }\n const identifier: Omit<IIdentifier, 'provider'> = {\n did: `did:key:${methodSpecificId}`,\n controllerKeyId: key.kid,\n keys: [key],\n services: [],\n }\n debug('Created', identifier.did)\n return identifier\n }\n\n async updateIdentifier(\n args: { did: string; kms?: string | undefined; alias?: string | undefined; options?: any },\n context: IAgentContext<IKeyManager>\n ): Promise<IIdentifier> {\n throw new Error('KeyDIDProvider updateIdentifier not supported yet.')\n }\n\n async deleteIdentifier(identifier: IIdentifier, context: IContext): Promise<boolean> {\n for (const { kid } of identifier.keys) {\n await context.agent.keyManagerDelete({ kid })\n }\n return true\n }\n\n async addKey({ identifier, key, options }: { identifier: IIdentifier; key: IKey; options?: any }, context: IContext): Promise<any> {\n throw Error('KeyDIDProvider addKey not supported')\n }\n\n async addService({ identifier, service, options }: { identifier: IIdentifier; service: IService; options?: any }, context: IContext): Promise<any> {\n throw Error('KeyDIDProvider addService not supported')\n }\n\n async removeKey(args: { identifier: IIdentifier; kid: string; options?: any }, context: IContext): Promise<any> {\n throw Error('KeyDIDProvider removeKey not supported')\n }\n\n async removeService(args: { identifier: IIdentifier; id: string; options?: any }, context: IContext): Promise<any> {\n throw Error('KeyDIDProvider removeService not supported')\n }\n}\n\ntype CodeNameType = Multicodec.CodecName | 'rsa-pub' | 'jwk_jcs-pub'\n","import { DIDResolutionOptions, DIDResolutionResult, DIDResolver, ParsedDID, Resolvable, Resolver } from 'did-resolver'\nimport { getResolver } from '@sphereon/ssi-sdk-ext.did-resolver-key'\n\nconst resolveDidKey: DIDResolver = async (\n didUrl: string,\n _parsed: ParsedDID,\n _resolver: Resolvable,\n options: DIDResolutionOptions\n): Promise<DIDResolutionResult> => {\n const resolver = new Resolver({ ...getResolver() })\n return resolver.resolve(didUrl, options)\n}\n\nexport function getDidKeyResolver() {\n return { key: resolveDidKey }\n}\n"]}
|