@sphereon/ssi-sdk-ext.did-provider-key 0.28.1-feature.oyd.cmsm.improv.21 → 0.28.1-next.54
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/index.cjs +149 -0
- package/dist/index.cjs.map +1 -0
- package/dist/{SphereonKeyDidProvider.d.ts → index.d.cts} +10 -4
- package/dist/index.d.ts +58 -3
- package/dist/index.js +117 -7
- package/dist/index.js.map +1 -1
- package/package.json +27 -14
- package/src/SphereonKeyDidProvider.ts +10 -10
- package/dist/KeyDidResolver.d.ts +0 -5
- package/dist/KeyDidResolver.d.ts.map +0 -1
- package/dist/KeyDidResolver.js +0 -22
- package/dist/KeyDidResolver.js.map +0 -1
- package/dist/SphereonKeyDidProvider.d.ts.map +0 -1
- package/dist/SphereonKeyDidProvider.js +0 -140
- package/dist/SphereonKeyDidProvider.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/ssi-sdk-ext.did-provider-key.d.ts +0 -63
- package/dist/tsdoc-metadata.json +0 -11
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
+
|
|
31
|
+
// src/index.ts
|
|
32
|
+
var index_exports = {};
|
|
33
|
+
__export(index_exports, {
|
|
34
|
+
SphereonKeyDidProvider: () => SphereonKeyDidProvider,
|
|
35
|
+
getDidKeyResolver: () => getDidKeyResolver
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(index_exports);
|
|
38
|
+
|
|
39
|
+
// src/SphereonKeyDidProvider.ts
|
|
40
|
+
var import_ssi_sdk_ext = require("@sphereon/ssi-sdk-ext.key-utils");
|
|
41
|
+
var import_did_manager = require("@veramo/did-manager");
|
|
42
|
+
var import_debug = __toESM(require("debug"), 1);
|
|
43
|
+
var import_multibase = __toESM(require("multibase"), 1);
|
|
44
|
+
var import_multicodec = __toESM(require("multicodec"), 1);
|
|
45
|
+
var u8a = __toESM(require("uint8arrays"), 1);
|
|
46
|
+
var { fromString, toString } = u8a;
|
|
47
|
+
var debug = (0, import_debug.default)("did-provider-key");
|
|
48
|
+
var keyCodecs = {
|
|
49
|
+
RSA: "rsa-pub",
|
|
50
|
+
Ed25519: "ed25519-pub",
|
|
51
|
+
X25519: "x25519-pub",
|
|
52
|
+
Secp256k1: "secp256k1-pub",
|
|
53
|
+
Secp256r1: "p256-pub",
|
|
54
|
+
Bls12381G1: "bls12_381-g1-pub",
|
|
55
|
+
Bls12381G2: "bls12_381-g2-pub"
|
|
56
|
+
};
|
|
57
|
+
var SphereonKeyDidProvider = class extends import_did_manager.AbstractIdentifierProvider {
|
|
58
|
+
static {
|
|
59
|
+
__name(this, "SphereonKeyDidProvider");
|
|
60
|
+
}
|
|
61
|
+
kms;
|
|
62
|
+
constructor(options) {
|
|
63
|
+
super();
|
|
64
|
+
this.kms = options.defaultKms;
|
|
65
|
+
}
|
|
66
|
+
async createIdentifier({ kms, alias, options }, context) {
|
|
67
|
+
let codecName = options?.codecName?.toUpperCase() === "EBSI" ? import_ssi_sdk_ext.JWK_JCS_PUB_NAME : options?.codecName;
|
|
68
|
+
const keyType = options?.type ?? options?.key?.type ?? (codecName === import_ssi_sdk_ext.JWK_JCS_PUB_NAME ? "Secp256r1" : "Secp256k1");
|
|
69
|
+
const key = await (0, import_ssi_sdk_ext.importProvidedOrGeneratedKey)({
|
|
70
|
+
// @ts-ignore
|
|
71
|
+
kms: kms ?? this.kms,
|
|
72
|
+
alias,
|
|
73
|
+
options: {
|
|
74
|
+
...options,
|
|
75
|
+
type: keyType
|
|
76
|
+
}
|
|
77
|
+
}, context);
|
|
78
|
+
let methodSpecificId;
|
|
79
|
+
const compressedPublicKeyHex = (0, import_ssi_sdk_ext.toRawCompressedHexPublicKey)(fromString(key.publicKeyHex, "hex"), key.type);
|
|
80
|
+
if (codecName === import_ssi_sdk_ext.JWK_JCS_PUB_NAME) {
|
|
81
|
+
const jwk = (0, import_ssi_sdk_ext.toJwk)(key.publicKeyHex, keyType, {
|
|
82
|
+
use: import_ssi_sdk_ext.JwkKeyUse.Signature,
|
|
83
|
+
key,
|
|
84
|
+
noKidThumbprint: true
|
|
85
|
+
});
|
|
86
|
+
methodSpecificId = toString(import_multibase.default.encode("base58btc", import_multicodec.default.addPrefix(fromString(import_ssi_sdk_ext.JWK_JCS_PUB_PREFIX.valueOf().toString(16), "hex"), (0, import_ssi_sdk_ext.jwkJcsEncode)(jwk))));
|
|
87
|
+
} else if (codecName) {
|
|
88
|
+
methodSpecificId = toString(import_multibase.default.encode("base58btc", import_multicodec.default.addPrefix(codecName, fromString(compressedPublicKeyHex, "hex"))));
|
|
89
|
+
} else {
|
|
90
|
+
codecName = keyCodecs[keyType];
|
|
91
|
+
if (codecName) {
|
|
92
|
+
methodSpecificId = toString(import_multibase.default.encode("base58btc", import_multicodec.default.addPrefix(codecName, fromString(compressedPublicKeyHex, "hex")))).toString();
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
if (!methodSpecificId) {
|
|
96
|
+
throw Error(`Key type ${keyType}, codec ${codecName} is not supported currently for did:key`);
|
|
97
|
+
}
|
|
98
|
+
const identifier = {
|
|
99
|
+
did: `did:key:${methodSpecificId}`,
|
|
100
|
+
controllerKeyId: key.kid,
|
|
101
|
+
keys: [
|
|
102
|
+
key
|
|
103
|
+
],
|
|
104
|
+
services: []
|
|
105
|
+
};
|
|
106
|
+
debug("Created", identifier.did);
|
|
107
|
+
return identifier;
|
|
108
|
+
}
|
|
109
|
+
async updateIdentifier(args, context) {
|
|
110
|
+
throw new Error("KeyDIDProvider updateIdentifier not supported yet.");
|
|
111
|
+
}
|
|
112
|
+
async deleteIdentifier(identifier, context) {
|
|
113
|
+
for (const { kid } of identifier.keys) {
|
|
114
|
+
await context.agent.keyManagerDelete({
|
|
115
|
+
kid
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
async addKey({ identifier, key, options }, context) {
|
|
121
|
+
throw Error("KeyDIDProvider addKey not supported");
|
|
122
|
+
}
|
|
123
|
+
async addService({ identifier, service, options }, context) {
|
|
124
|
+
throw Error("KeyDIDProvider addService not supported");
|
|
125
|
+
}
|
|
126
|
+
async removeKey(args, context) {
|
|
127
|
+
throw Error("KeyDIDProvider removeKey not supported");
|
|
128
|
+
}
|
|
129
|
+
async removeService(args, context) {
|
|
130
|
+
throw Error("KeyDIDProvider removeService not supported");
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
// src/KeyDidResolver.ts
|
|
135
|
+
var import_did_resolver = require("did-resolver");
|
|
136
|
+
var import_ssi_sdk_ext2 = require("@sphereon/ssi-sdk-ext.did-resolver-key");
|
|
137
|
+
var resolveDidKey = /* @__PURE__ */ __name(async (didUrl, _parsed, _resolver, options) => {
|
|
138
|
+
const resolver = new import_did_resolver.Resolver({
|
|
139
|
+
...(0, import_ssi_sdk_ext2.getResolver)()
|
|
140
|
+
});
|
|
141
|
+
return resolver.resolve(didUrl, options);
|
|
142
|
+
}, "resolveDidKey");
|
|
143
|
+
function getDidKeyResolver() {
|
|
144
|
+
return {
|
|
145
|
+
key: resolveDidKey
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
__name(getDidKeyResolver, "getDidKeyResolver");
|
|
149
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/SphereonKeyDidProvider.ts","../src/KeyDidResolver.ts"],"sourcesContent":["export { SphereonKeyDidProvider } from './SphereonKeyDidProvider'\nexport { getDidKeyResolver } from './KeyDidResolver'\n","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 * as u8a from 'uint8arrays'\nconst { fromString, toString } = u8a\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;ACAA,yBASO;AAEP,yBAA2C;AAC3C,mBAAkB;AAClB,uBAAsB;AACtB,wBAAuB;AAEvB,UAAqB;AACrB,IAAM,EAAEA,YAAYC,SAAQ,IAAKC;AAEjC,IAAMC,YAAQC,aAAAA,SAAM,kBAAA;AAIpB,IAAMC,YAAY;EAChBC,KAAK;EACLC,SAAS;EACTC,QAAQ;EACRC,WAAW;EACXC,WAAW;EACXC,YAAY;EACZC,YAAY;AACd;AAEO,IAAMC,yBAAN,cAAqCC,8CAAAA;EAjC5C,OAiC4CA;;;EACzBC;EAEjBC,YAAYC,SAAkC;AAC5C,UAAK;AACL,SAAKF,MAAME,QAAQC;EACrB;EAEA,MAAMC,iBACJ,EACEJ,KACAK,OACAH,QAAO,GAaTI,SACwC;AACxC,QAAIC,YAAaL,SAASK,WAAWC,YAAAA,MAAkB,SAAUC,sCAA4CP,SAASK;AAGtH,UAAMG,UAAWR,SAASS,QAAQT,SAASU,KAAKD,SAASJ,cAAcE,sCAAmB,cAAc;AAMxG,UAAMG,MAAM,UAAMC,iDAChB;;MAEEb,KAAKA,OAAO,KAAKA;MACjBK;MACAH,SAAS;QAAE,GAAGA;QAASS,MAAMD;MAAQ;IACvC,GACAJ,OAAAA;AAGF,QAAIQ;AAGJ,UAAMC,6BAA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EP;MAAI,CAAA;IAC7C;AACA,WAAO;EACT;EAEA,MAAMQ,OAAO,EAAEX,YAAYpB,KAAKV,QAAO,GAA2DI,SAAiC;AACjI,UAAMyB,MAAM,qCAAA;EACd;EAEA,MAAMa,WAAW,EAAEZ,YAAYa,SAAS3C,QAAO,GAAmEI,SAAiC;AACjJ,UAAMyB,MAAM,yCAAA;EACd;EAEA,MAAMe,UAAUP,MAA+DjC,SAAiC;AAC9G,UAAMyB,MAAM,wCAAA;EACd;EAEA,MAAMgB,cAAcR,MAA8DjC,SAAiC;AACjH,UAAMyB,MAAM,4CAAA;EACd;AACF;;;ACjJA,0BAAwG;AACxG,IAAAiB,sBAA4B;AAE5B,IAAMC,gBAA6B,8BACjCC,QACAC,SACAC,WACAC,YAAAA;AAEA,QAAMC,WAAW,IAAIC,6BAAS;IAAE,OAAGC,iCAAAA;EAAc,CAAA;AACjD,SAAOF,SAASG,QAAQP,QAAQG,OAAAA;AAClC,GARmC;AAU5B,SAASK,oBAAAA;AACd,SAAO;IAAEC,KAAKV;EAAc;AAC9B;AAFgBS;","names":["fromString","toString","u8a","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","publicKeyHex","jwk","toJwk","use","JwkKeyUse","Signature","noKidThumbprint","Multibase","encode","Multicodec","addPrefix","JWK_JCS_PUB_PREFIX","valueOf","jwkJcsEncode","Error","identifier","did","controllerKeyId","kid","keys","services","updateIdentifier","args","deleteIdentifier","agent","keyManagerDelete","addKey","addService","service","removeKey","removeService","import_ssi_sdk_ext","resolveDidKey","didUrl","_parsed","_resolver","options","resolver","Resolver","getResolver","resolve","getDidKeyResolver","key"]}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { TKeyType } from '@sphereon/ssi-sdk-ext.key-utils';
|
|
2
|
-
import { IAgentContext, IIdentifier, IKey,
|
|
2
|
+
import { IAgentContext, IKeyManager, IIdentifier, IKey, 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
|
+
|
|
5
7
|
type IContext = IAgentContext<IKeyManager>;
|
|
6
|
-
|
|
8
|
+
declare class SphereonKeyDidProvider extends AbstractIdentifierProvider {
|
|
7
9
|
private readonly kms?;
|
|
8
10
|
constructor(options: {
|
|
9
11
|
defaultKms?: string;
|
|
@@ -48,5 +50,9 @@ export declare class SphereonKeyDidProvider extends AbstractIdentifierProvider {
|
|
|
48
50
|
options?: any;
|
|
49
51
|
}, context: IContext): Promise<any>;
|
|
50
52
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
+
|
|
54
|
+
declare function getDidKeyResolver(): {
|
|
55
|
+
key: DIDResolver;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export { SphereonKeyDidProvider, getDidKeyResolver };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,58 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { TKeyType } from '@sphereon/ssi-sdk-ext.key-utils';
|
|
2
|
+
import { IAgentContext, IKeyManager, IIdentifier, IKey, IService } from '@veramo/core';
|
|
3
|
+
import { AbstractIdentifierProvider } from '@veramo/did-manager';
|
|
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 };
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,118 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// src/SphereonKeyDidProvider.ts
|
|
5
|
+
import { importProvidedOrGeneratedKey, JWK_JCS_PUB_NAME, JWK_JCS_PUB_PREFIX, jwkJcsEncode, JwkKeyUse, toJwk, toRawCompressedHexPublicKey } from "@sphereon/ssi-sdk-ext.key-utils";
|
|
6
|
+
import { AbstractIdentifierProvider } from "@veramo/did-manager";
|
|
7
|
+
import Debug from "debug";
|
|
8
|
+
import Multibase from "multibase";
|
|
9
|
+
import Multicodec from "multicodec";
|
|
10
|
+
import * as u8a from "uint8arrays";
|
|
11
|
+
var { fromString, toString } = u8a;
|
|
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
|
+
};
|
|
8
118
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../src/SphereonKeyDidProvider.ts","../src/KeyDidResolver.ts"],"sourcesContent":["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 * as u8a from 'uint8arrays'\nconst { fromString, toString } = u8a\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"],"mappings":";;;;AAAA,SACEA,8BACAC,kBACAC,oBACAC,cACAC,WAEAC,OACAC,mCACK;AAEP,SAASC,kCAAkC;AAC3C,OAAOC,WAAW;AAClB,OAAOC,eAAe;AACtB,OAAOC,gBAAgB;AAEvB,YAAYC,SAAS;AACrB,IAAM,EAAEC,YAAYC,SAAQ,IAAKC;AAEjC,IAAMC,QAAQC,MAAM,kBAAA;AAIpB,IAAMC,YAAY;EAChBC,KAAK;EACLC,SAAS;EACTC,QAAQ;EACRC,WAAW;EACXC,WAAW;EACXC,YAAY;EACZC,YAA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CompressedHexPublicKey","AbstractIdentifierProvider","Debug","Multibase","Multicodec","u8a","fromString","toString","u8a","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","publicKeyHex","jwk","toJwk","use","JwkKeyUse","Signature","noKidThumbprint","Multibase","encode","Multicodec","addPrefix","JWK_JCS_PUB_PREFIX","valueOf","jwkJcsEncode","Error","identifier","did","controllerKeyId","kid","keys","services","updateIdentifier","args","deleteIdentifier","agent","keyManagerDelete","addKey","addService","service","removeKey","removeService","Resolver","getResolver","resolveDidKey","didUrl","_parsed","_resolver","options","resolver","Resolver","getResolver","resolve","getDidKeyResolver","key"]}
|
package/package.json
CHANGED
|
@@ -1,17 +1,30 @@
|
|
|
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-
|
|
5
|
-
"source": "src/index.ts",
|
|
6
|
-
"
|
|
7
|
-
"
|
|
4
|
+
"version": "0.28.1-next.54+59fa071",
|
|
5
|
+
"source": "./src/index.ts",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.cjs",
|
|
8
|
+
"module": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
"react-native": "./dist/index.js",
|
|
12
|
+
"import": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"import": "./dist/index.js"
|
|
15
|
+
},
|
|
16
|
+
"require": {
|
|
17
|
+
"types": "./dist/index.d.cts",
|
|
18
|
+
"require": "./dist/index.cjs"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
8
21
|
"scripts": {
|
|
9
|
-
"build": "
|
|
22
|
+
"build": "tsup --config ../../tsup.config.ts --tsconfig ../../tsconfig.tsup.json",
|
|
10
23
|
"extract-api": "sphereon dev extract-api"
|
|
11
24
|
},
|
|
12
25
|
"dependencies": {
|
|
13
|
-
"@sphereon/ssi-sdk-ext.did-resolver-key": "0.28.1-
|
|
14
|
-
"@sphereon/ssi-sdk-ext.key-utils": "0.28.1-
|
|
26
|
+
"@sphereon/ssi-sdk-ext.did-resolver-key": "0.28.1-next.54+59fa071",
|
|
27
|
+
"@sphereon/ssi-sdk-ext.key-utils": "0.28.1-next.54+59fa071",
|
|
15
28
|
"@transmute/did-key-bls12381": "0.3.0-unstable.10",
|
|
16
29
|
"@veramo/core": "4.2.0",
|
|
17
30
|
"@veramo/did-manager": "4.2.0",
|
|
@@ -20,12 +33,12 @@
|
|
|
20
33
|
"did-resolver": "^4.1.0",
|
|
21
34
|
"multibase": "^4.0.6",
|
|
22
35
|
"multicodec": "^3.2.1",
|
|
23
|
-
"uint8arrays": "
|
|
36
|
+
"uint8arrays": "3.1.1"
|
|
24
37
|
},
|
|
25
38
|
"devDependencies": {
|
|
26
|
-
"@sphereon/ssi-sdk-ext.key-manager": "0.28.1-
|
|
27
|
-
"@sphereon/ssi-sdk-ext.kms-local": "0.28.1-
|
|
28
|
-
"@sphereon/ssi-sdk.dev": "0.
|
|
39
|
+
"@sphereon/ssi-sdk-ext.key-manager": "0.28.1-next.54+59fa071",
|
|
40
|
+
"@sphereon/ssi-sdk-ext.kms-local": "0.28.1-next.54+59fa071",
|
|
41
|
+
"@sphereon/ssi-sdk.dev": "0.33.1-next.73",
|
|
29
42
|
"@veramo/did-resolver": "4.2.0",
|
|
30
43
|
"@veramo/key-manager": "4.2.0"
|
|
31
44
|
},
|
|
@@ -34,8 +47,8 @@
|
|
|
34
47
|
"jsonld-signatures": "npm:@digitalcredentials/jsonld-signatures@^9.3.1"
|
|
35
48
|
},
|
|
36
49
|
"files": [
|
|
37
|
-
"dist
|
|
38
|
-
"src
|
|
50
|
+
"dist",
|
|
51
|
+
"src",
|
|
39
52
|
"README.md",
|
|
40
53
|
"LICENSE"
|
|
41
54
|
],
|
|
@@ -59,5 +72,5 @@
|
|
|
59
72
|
"secp256r1",
|
|
60
73
|
"RSA"
|
|
61
74
|
],
|
|
62
|
-
"gitHead": "
|
|
75
|
+
"gitHead": "59fa0719e8d0094164182c3f2a31a5dc8954bade"
|
|
63
76
|
}
|
|
@@ -13,7 +13,9 @@ 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
|
+
// @ts-ignore
|
|
16
17
|
import * as u8a from 'uint8arrays'
|
|
18
|
+
const { fromString, toString } = u8a
|
|
17
19
|
|
|
18
20
|
const debug = Debug('did-provider-key')
|
|
19
21
|
|
|
@@ -78,27 +80,25 @@ export class SphereonKeyDidProvider extends AbstractIdentifierProvider {
|
|
|
78
80
|
let methodSpecificId: string | undefined
|
|
79
81
|
|
|
80
82
|
// did:key uses compressed pub keys
|
|
81
|
-
const compressedPublicKeyHex = toRawCompressedHexPublicKey(
|
|
83
|
+
const compressedPublicKeyHex = toRawCompressedHexPublicKey(fromString(key.publicKeyHex, 'hex'), key.type)
|
|
82
84
|
if (codecName === JWK_JCS_PUB_NAME) {
|
|
83
85
|
const jwk = toJwk(key.publicKeyHex, keyType, { use: JwkKeyUse.Signature, key, noKidThumbprint: true })
|
|
84
86
|
// console.log(`FIXME JWK: ${JSON.stringify(toJwk(privateKeyHex, keyType, { use: JwkKeyUse.Signature, key, isPrivateKey: true }), null, 2)}`)
|
|
85
|
-
methodSpecificId =
|
|
86
|
-
Multibase.encode('base58btc', Multicodec.addPrefix(
|
|
87
|
+
methodSpecificId = toString(
|
|
88
|
+
Multibase.encode('base58btc', Multicodec.addPrefix(fromString(JWK_JCS_PUB_PREFIX.valueOf().toString(16), 'hex'), jwkJcsEncode(jwk)))
|
|
87
89
|
)
|
|
88
90
|
} else if (codecName) {
|
|
89
|
-
methodSpecificId =
|
|
90
|
-
Multibase.encode('base58btc', Multicodec.addPrefix(codecName as Multicodec.CodecName,
|
|
91
|
+
methodSpecificId = toString(
|
|
92
|
+
Multibase.encode('base58btc', Multicodec.addPrefix(codecName as Multicodec.CodecName, fromString(compressedPublicKeyHex, 'hex')))
|
|
91
93
|
)
|
|
92
94
|
} else {
|
|
93
95
|
codecName = keyCodecs[keyType]
|
|
94
96
|
|
|
95
97
|
if (codecName) {
|
|
96
98
|
// methodSpecificId = bytesToMultibase({bytes: u8a.fromString(key.publicKeyHex, 'hex'), codecName})
|
|
97
|
-
methodSpecificId =
|
|
98
|
-
.
|
|
99
|
-
|
|
100
|
-
)
|
|
101
|
-
.toString()
|
|
99
|
+
methodSpecificId = toString(
|
|
100
|
+
Multibase.encode('base58btc', Multicodec.addPrefix(codecName as Multicodec.CodecName, fromString(compressedPublicKeyHex, 'hex')))
|
|
101
|
+
).toString()
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
104
|
if (!methodSpecificId) {
|
package/dist/KeyDidResolver.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
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"}
|
package/dist/KeyDidResolver.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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 +0,0 @@
|
|
|
1
|
-
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GAAG,CAAA;KAAE,EAC1F,OAAO,EAAE,aAAa,CAAC,WAAW,CAAC,GAClC,OAAO,CAAC,WAAW,CAAC;IAIjB,gBAAgB,CAAC,UAAU,EAAE,WAAW,EAAE,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC;IAO9E,MAAM,CAAC,EAAE,UAAU,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE;QAAE,UAAU,EAAE,WAAW,CAAC;QAAC,GAAG,EAAE,IAAI,CAAC;QAAC,OAAO,CAAC,EAAE,GAAG,CAAA;KAAE,EAAE,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC;IAI5H,UAAU,CAAC,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE;QAAE,UAAU,EAAE,WAAW,CAAC;QAAC,OAAO,EAAE,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"}
|
|
@@ -1,140 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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,MAAM,SAAS,GAAG;IAChB,GAAG,EAAE,SAAS;IACd,OAAO,EAAE,aAAa;IACtB,MAAM,EAAE,YAAY;IACpB,SAAS,EAAE,eAAe;IAC1B,SAAS,EAAE,UAAU;IACrB,UAAU,EAAE,kBAAkB;IAC9B,UAAU,EAAE,kBAAkB;CACtB,CAAA;AAEV,MAAa,sBAAuB,SAAQ,wCAA0B;IAGpE,YAAY,OAAgC;QAC1C,KAAK,EAAE,CAAA;QACP,IAAI,CAAC,GAAG,GAAG,OAAO,CAAC,UAAU,CAAA;IAC/B,CAAC;IAEK,gBAAgB;6DACpB,EACE,GAAG,EACH,KAAK,EACL,OAAO,GAYR,EACD,OAAiB;;YAEjB,IAAI,SAAS,GAAG,CAAC,CAAA,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,SAAS,0CAAE,WAAW,EAAE,MAAK,MAAM,CAAC,CAAC,CAAE,wCAAyC,CAAC,CAAC,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,SAAS,CAElH,CAAA;YACb,MAAM,OAAO,GAAG,CAAC,MAAA,MAAA,OAAO,aAAP,OAAO,uBAA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OAAO,IAAI,CAAA;QACb,CAAC;KAAA;IAEK,MAAM;6DAAC,EAAE,UAAU,EAAE,GAAG,EAAE,OAAO,EAAyD,EAAE,OAAiB;YACjH,MAAM,KAAK,CAAC,qCAAqC,CAAC,CAAA;QACpD,CAAC;KAAA;IAEK,UAAU;6DAAC,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAiE,EAAE,OAAiB;YACjI,MAAM,KAAK,CAAC,yCAAyC,CAAC,CAAA;QACxD,CAAC;KAAA;IAEK,SAAS,CAAC,IAA6D,EAAE,OAAiB;;YAC9F,MAAM,KAAK,CAAC,wCAAwC,CAAC,CAAA;QACvD,CAAC;KAAA;IAEK,aAAa,CAAC,IAA4D,EAAE,OAAiB;;YACjG,MAAM,KAAK,CAAC,4CAA4C,CAAC,CAAA;QAC3D,CAAC;KAAA;CACF;AAlHD,wDAkHC"}
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,63 +0,0 @@
|
|
|
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 { }
|
package/dist/tsdoc-metadata.json
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
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
|
-
}
|