@ayanworks/credo-polygon-w3c-module 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +30 -0
- package/build/PolygonApi.d.ts +48 -0
- package/build/PolygonApi.js +42 -0
- package/build/PolygonApi.js.map +1 -0
- package/build/PolygonModule.d.ts +10 -0
- package/build/PolygonModule.js +31 -0
- package/build/PolygonModule.js.map +1 -0
- package/build/PolygonModuleConfig.d.ts +18 -0
- package/build/PolygonModuleConfig.js +14 -0
- package/build/PolygonModuleConfig.js.map +1 -0
- package/build/dids/PolygonDidRegistrar.d.ts +30 -0
- package/build/dids/PolygonDidRegistrar.js +267 -0
- package/build/dids/PolygonDidRegistrar.js.map +1 -0
- package/build/dids/PolygonDidResolver.d.ts +8 -0
- package/build/dids/PolygonDidResolver.js +39 -0
- package/build/dids/PolygonDidResolver.js.map +1 -0
- package/build/dids/didPolygonUtil.d.ts +7 -0
- package/build/dids/didPolygonUtil.js +98 -0
- package/build/dids/didPolygonUtil.js.map +1 -0
- package/build/dids/index.d.ts +3 -0
- package/build/dids/index.js +20 -0
- package/build/dids/index.js.map +1 -0
- package/build/index.d.ts +5 -0
- package/build/index.js +28 -0
- package/build/index.js.map +1 -0
- package/build/ledger/PolygonLedgerService.d.ts +100 -0
- package/build/ledger/PolygonLedgerService.js +210 -0
- package/build/ledger/PolygonLedgerService.js.map +1 -0
- package/build/ledger/index.d.ts +1 -0
- package/build/ledger/index.js +18 -0
- package/build/ledger/index.js.map +1 -0
- package/build/signature-suites/EcdsaSecp256k1Signature2019.d.ts +60 -0
- package/build/signature-suites/EcdsaSecp256k1Signature2019.js +126 -0
- package/build/signature-suites/EcdsaSecp256k1Signature2019.js.map +1 -0
- package/build/signature-suites/index.d.ts +1 -0
- package/build/signature-suites/index.js +18 -0
- package/build/signature-suites/index.js.map +1 -0
- package/build/utils/index.d.ts +1 -0
- package/build/utils/index.js +18 -0
- package/build/utils/index.js.map +1 -0
- package/build/utils/utils.d.ts +7 -0
- package/build/utils/utils.js +38 -0
- package/build/utils/utils.js.map +1 -0
- package/package.json +71 -0
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.PolygonLedgerService = exports.SchemaOperation = exports.DidOperation = void 0;
|
|
13
|
+
const askar_1 = require("@aries-framework/askar");
|
|
14
|
+
const core_1 = require("@aries-framework/core");
|
|
15
|
+
const polygon_did_registrar_1 = require("@ayanworks/polygon-did-registrar");
|
|
16
|
+
const did_1 = require("@ayanworks/polygon-did-registrar/build/utils/did");
|
|
17
|
+
const polygon_schema_manager_1 = require("@ayanworks/polygon-schema-manager");
|
|
18
|
+
const ethers_1 = require("ethers");
|
|
19
|
+
const PolygonModuleConfig_1 = require("../PolygonModuleConfig");
|
|
20
|
+
const utils_1 = require("../utils");
|
|
21
|
+
var DidOperation;
|
|
22
|
+
(function (DidOperation) {
|
|
23
|
+
DidOperation["Create"] = "createDID";
|
|
24
|
+
DidOperation["Update"] = "updateDIDDoc";
|
|
25
|
+
DidOperation["Deactivate"] = "deactivate";
|
|
26
|
+
DidOperation["AddResource"] = "addResource";
|
|
27
|
+
})(DidOperation = exports.DidOperation || (exports.DidOperation = {}));
|
|
28
|
+
var SchemaOperation;
|
|
29
|
+
(function (SchemaOperation) {
|
|
30
|
+
SchemaOperation["CreateSchema"] = "createSchema";
|
|
31
|
+
})(SchemaOperation = exports.SchemaOperation || (exports.SchemaOperation = {}));
|
|
32
|
+
let PolygonLedgerService = class PolygonLedgerService {
|
|
33
|
+
constructor({ didContractAddress, rpcUrl, fileServerToken, schemaManagerContractAddress, serverUrl, }) {
|
|
34
|
+
this.rpcUrl = rpcUrl;
|
|
35
|
+
this.didContractAddress = didContractAddress;
|
|
36
|
+
this.schemaManagerContractAddress = schemaManagerContractAddress;
|
|
37
|
+
this.fileServerToken = fileServerToken;
|
|
38
|
+
this.fileServerUrl = serverUrl;
|
|
39
|
+
}
|
|
40
|
+
async createSchema(agentContext, { did, schemaName, schema }) {
|
|
41
|
+
const publicKeyBase58 = await this.getPublicKeyFromDid(agentContext, did);
|
|
42
|
+
if (!publicKeyBase58) {
|
|
43
|
+
throw new core_1.AriesFrameworkError('Public Key not found in wallet');
|
|
44
|
+
}
|
|
45
|
+
const signingKey = await this.getSigningKey(agentContext.wallet, publicKeyBase58);
|
|
46
|
+
const schemaRegistry = this.createSchemaRegistryInstance(signingKey);
|
|
47
|
+
agentContext.config.logger.info(`Creating schema on ledger: ${did}`);
|
|
48
|
+
const response = await schemaRegistry.createSchema(did, schemaName, schema);
|
|
49
|
+
if (!response) {
|
|
50
|
+
agentContext.config.logger.error(`Schema creation failed for did: ${did} and schema: ${schema}`);
|
|
51
|
+
throw new core_1.AriesFrameworkError(`Schema creation failed for did: ${did} and schema: ${schema}`);
|
|
52
|
+
}
|
|
53
|
+
agentContext.config.logger.info(`Published schema on ledger: ${did}`);
|
|
54
|
+
return response;
|
|
55
|
+
}
|
|
56
|
+
async getSchemaByDidAndSchemaId(agentContext, did, schemaId) {
|
|
57
|
+
agentContext.config.logger.info(`Getting schema from ledger: ${did} and schemaId: ${schemaId}`);
|
|
58
|
+
const publicKeyBase58 = await this.getPublicKeyFromDid(agentContext, did);
|
|
59
|
+
if (!publicKeyBase58) {
|
|
60
|
+
throw new core_1.AriesFrameworkError('Public Key not found in wallet');
|
|
61
|
+
}
|
|
62
|
+
const signingKey = await this.getSigningKey(agentContext.wallet, publicKeyBase58);
|
|
63
|
+
const schemaRegistry = this.createSchemaRegistryInstance(signingKey);
|
|
64
|
+
const response = await schemaRegistry.getSchemaById(did, schemaId);
|
|
65
|
+
if (!response) {
|
|
66
|
+
agentContext.config.logger.error(`Schema not found for did: ${did} and schemaId: ${schemaId} Error: ${response}`);
|
|
67
|
+
throw new core_1.AriesFrameworkError(`Schema not found for did: ${did} and schemaId: ${schemaId}`);
|
|
68
|
+
}
|
|
69
|
+
agentContext.config.logger.info(`Got schema from ledger: ${did} and schemaId: ${schemaId}`);
|
|
70
|
+
return response;
|
|
71
|
+
}
|
|
72
|
+
async estimateFeeForDidOperation(agentContext, options) {
|
|
73
|
+
const keyPair = await (0, utils_1.generateSecp256k1KeyPair)();
|
|
74
|
+
const didRegistry = this.createDidRegistryInstance(new ethers_1.SigningKey(keyPair.privateKey));
|
|
75
|
+
const { operation } = options;
|
|
76
|
+
if (operation === DidOperation.Create) {
|
|
77
|
+
agentContext.config.logger.info(`Getting estimated fee for operation: ${operation} `);
|
|
78
|
+
const did = `did:polygon:testnet${keyPair.address}`;
|
|
79
|
+
const didDoc = (0, utils_1.getSecp256k1DidDocWithPublicKey)(did, keyPair.publicKeyBase58, options === null || options === void 0 ? void 0 : options.serviceEndpoint);
|
|
80
|
+
const response = await didRegistry.estimateTxFee(DidOperation.Create, [keyPair.address, JSON.stringify(didDoc)]);
|
|
81
|
+
return response;
|
|
82
|
+
}
|
|
83
|
+
if (operation === DidOperation.Update) {
|
|
84
|
+
agentContext.config.logger.info(`Getting estimated fee for operation: ${operation} `);
|
|
85
|
+
const parsedDid = (0, did_1.parseDid)(options.did);
|
|
86
|
+
const response = await didRegistry.estimateTxFee(DidOperation.Update, [parsedDid.didAddress, JSON.stringify(options.didDocument)], parsedDid.didAddress);
|
|
87
|
+
return response;
|
|
88
|
+
}
|
|
89
|
+
if (operation === DidOperation.Deactivate) {
|
|
90
|
+
agentContext.config.logger.info(`Getting estimated fee for operation: ${operation} `);
|
|
91
|
+
const parsedDid = (0, did_1.parseDid)(options.did);
|
|
92
|
+
const deactivatedDidDocument = new core_1.DidDocumentBuilder(options.did)
|
|
93
|
+
.addContext('https://www.w3.org/ns/did/v1')
|
|
94
|
+
.build();
|
|
95
|
+
const response = await didRegistry.estimateTxFee(DidOperation.Update, [parsedDid.didAddress, JSON.stringify(deactivatedDidDocument)], parsedDid.didAddress);
|
|
96
|
+
return response;
|
|
97
|
+
}
|
|
98
|
+
if (operation === DidOperation.AddResource) {
|
|
99
|
+
agentContext.config.logger.info(`Getting estimated fee for operation: ${operation} `);
|
|
100
|
+
const parsedDid = (0, did_1.parseDid)(options.did);
|
|
101
|
+
const response = await didRegistry.estimateTxFee(DidOperation.AddResource, [parsedDid.didAddress, options.resourceId, JSON.stringify(options.resource)], parsedDid.didAddress);
|
|
102
|
+
return response;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
async estimateFeeForSchemaOperation(agentContext, options) {
|
|
106
|
+
const keyPair = await (0, utils_1.generateSecp256k1KeyPair)();
|
|
107
|
+
const schemaRegistry = this.createSchemaRegistryInstance(new ethers_1.SigningKey(keyPair.privateKey));
|
|
108
|
+
const { operation } = options;
|
|
109
|
+
const testResourceBody = {
|
|
110
|
+
resourceURI: 'did:polygon:testnet:0x13cd23928Ae515b86592C630f56C138aE4c7B79a/resources/398cee0a-efac-4643-9f4c-74c48c72a14b',
|
|
111
|
+
resourceCollectionId: '55dbc8bf-fba3-4117-855c-1e0dc1d3bb47',
|
|
112
|
+
resourceId: '398cee0a-efac-4643-9f4c-74c48c72a14b',
|
|
113
|
+
resourceName: 'Eventbrite1 Logo',
|
|
114
|
+
resourceType: 'W3C-schema',
|
|
115
|
+
mediaType: 'image/svg+xml',
|
|
116
|
+
created: '2022-11-17T08:10:36Z',
|
|
117
|
+
checksum: 'a95380f460e63ad939541a57aecbfd795fcd37c6d78ee86c885340e33a91b559',
|
|
118
|
+
previousVersionId: null,
|
|
119
|
+
nextVersionId: null,
|
|
120
|
+
};
|
|
121
|
+
if (operation === SchemaOperation.CreateSchema) {
|
|
122
|
+
agentContext.config.logger.info(`Getting estimated fee for operation: ${operation} `);
|
|
123
|
+
const schemaEstimatedFee = await schemaRegistry.estimateTxFee(SchemaOperation.CreateSchema, [
|
|
124
|
+
keyPair.address,
|
|
125
|
+
core_1.utils.uuid(),
|
|
126
|
+
JSON.stringify(testResourceBody),
|
|
127
|
+
]);
|
|
128
|
+
const resourceEstimatedFee = await this.estimateFeeForDidOperation(agentContext, {
|
|
129
|
+
operation: DidOperation.AddResource,
|
|
130
|
+
resourceId: core_1.utils.uuid(),
|
|
131
|
+
resource: testResourceBody,
|
|
132
|
+
did: options.did,
|
|
133
|
+
});
|
|
134
|
+
let feeParameters = {};
|
|
135
|
+
if (schemaEstimatedFee && resourceEstimatedFee) {
|
|
136
|
+
feeParameters = {
|
|
137
|
+
estimatedTotalTxFee: Number(schemaEstimatedFee.transactionFee) + Number(resourceEstimatedFee.transactionFee),
|
|
138
|
+
estimatedSchemaTxFee: schemaEstimatedFee,
|
|
139
|
+
estimatedResourceTxFee: resourceEstimatedFee,
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
return feeParameters;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
createDidRegistryInstance(signingKey) {
|
|
146
|
+
if (!this.rpcUrl || !this.didContractAddress) {
|
|
147
|
+
throw new core_1.AriesFrameworkError('Ledger config not found');
|
|
148
|
+
}
|
|
149
|
+
return new polygon_did_registrar_1.PolygonDID({
|
|
150
|
+
rpcUrl: this.rpcUrl,
|
|
151
|
+
contractAddress: this.didContractAddress,
|
|
152
|
+
signingKey,
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
createSchemaRegistryInstance(signingKey) {
|
|
156
|
+
if (!this.rpcUrl ||
|
|
157
|
+
!this.schemaManagerContractAddress ||
|
|
158
|
+
!this.fileServerToken ||
|
|
159
|
+
!this.fileServerUrl ||
|
|
160
|
+
!this.didContractAddress) {
|
|
161
|
+
throw new core_1.AriesFrameworkError('Polygon schema module config not found');
|
|
162
|
+
}
|
|
163
|
+
return new polygon_schema_manager_1.PolygonSchema({
|
|
164
|
+
rpcUrl: this.rpcUrl,
|
|
165
|
+
didRegistrarContractAddress: this.didContractAddress,
|
|
166
|
+
schemaManagerContractAddress: this.schemaManagerContractAddress,
|
|
167
|
+
fileServerToken: this.fileServerToken,
|
|
168
|
+
serverUrl: this.fileServerUrl,
|
|
169
|
+
signingKey,
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
async getSigningKey(wallet, publicKeyBase58) {
|
|
173
|
+
if (!(wallet instanceof askar_1.AskarWallet)) {
|
|
174
|
+
throw new core_1.AriesFrameworkError('Incorrect wallet type: Polygon Module currently only supports Askar wallet');
|
|
175
|
+
}
|
|
176
|
+
const keyEntry = await wallet.session.fetchKey({ name: publicKeyBase58 });
|
|
177
|
+
if (!keyEntry) {
|
|
178
|
+
throw new core_1.WalletError('Key not found in wallet');
|
|
179
|
+
}
|
|
180
|
+
const signingKey = new ethers_1.SigningKey(keyEntry.key.secretBytes);
|
|
181
|
+
keyEntry.key.handle.free();
|
|
182
|
+
return signingKey;
|
|
183
|
+
}
|
|
184
|
+
async getPublicKeyFromDid(agentContext, did) {
|
|
185
|
+
var _a;
|
|
186
|
+
const didRepository = agentContext.dependencyManager.resolve(core_1.DidRepository);
|
|
187
|
+
const didRecord = await didRepository.findCreatedDid(agentContext, did);
|
|
188
|
+
if (!didRecord) {
|
|
189
|
+
throw new core_1.AriesFrameworkError('DidRecord not found');
|
|
190
|
+
}
|
|
191
|
+
if (!((_a = didRecord.didDocument) === null || _a === void 0 ? void 0 : _a.verificationMethod)) {
|
|
192
|
+
throw new core_1.AriesFrameworkError('VerificationMethod not found cannot get public key');
|
|
193
|
+
}
|
|
194
|
+
const publicKeyBase58 = didRecord.didDocument.verificationMethod[0].publicKeyBase58;
|
|
195
|
+
return publicKeyBase58;
|
|
196
|
+
}
|
|
197
|
+
updateModuleConfig({ didRegistrarContractAddress, fileServerToken, rpcUrl, schemaManagerContractAddress, serverUrl, }) {
|
|
198
|
+
this.rpcUrl = rpcUrl;
|
|
199
|
+
this.didContractAddress = didRegistrarContractAddress;
|
|
200
|
+
this.schemaManagerContractAddress = schemaManagerContractAddress;
|
|
201
|
+
this.fileServerToken = fileServerToken;
|
|
202
|
+
this.fileServerUrl = serverUrl;
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
PolygonLedgerService = __decorate([
|
|
206
|
+
(0, core_1.injectable)(),
|
|
207
|
+
__metadata("design:paramtypes", [PolygonModuleConfig_1.PolygonModuleConfig])
|
|
208
|
+
], PolygonLedgerService);
|
|
209
|
+
exports.PolygonLedgerService = PolygonLedgerService;
|
|
210
|
+
//# sourceMappingURL=PolygonLedgerService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PolygonLedgerService.js","sourceRoot":"","sources":["../../src/ledger/PolygonLedgerService.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA,kDAAoD;AACpD,gDAO8B;AAC9B,4EAA6D;AAC7D,0EAA2E;AAC3E,8EAAiE;AACjE,mCAAmC;AAEnC,gEAA4D;AAC5D,oCAAoF;AAkCpF,IAAY,YAKX;AALD,WAAY,YAAY;IACtB,oCAAoB,CAAA;IACpB,uCAAuB,CAAA;IACvB,yCAAyB,CAAA;IACzB,2CAA2B,CAAA;AAC7B,CAAC,EALW,YAAY,GAAZ,oBAAY,KAAZ,oBAAY,QAKvB;AAeD,IAAY,eAEX;AAFD,WAAY,eAAe;IACzB,gDAA6B,CAAA;AAC/B,CAAC,EAFW,eAAe,GAAf,uBAAe,KAAf,u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,UAAU,CAAA;IACnB,CAAC;IAEO,KAAK,CAAC,mBAAmB,CAAC,YAA0B,EAAE,GAAW;;QACvE,MAAM,aAAa,GAAG,YAAY,CAAC,iBAAiB,CAAC,OAAO,CAAC,oBAAa,CAAC,CAAA;QAE3E,MAAM,SAAS,GAAG,MAAM,aAAa,CAAC,cAAc,CAAC,YAAY,EAAE,GAAG,CAAC,CAAA;QACvE,IAAI,CAAC,SAAS,EAAE;YACd,MAAM,IAAI,0BAAmB,CAAC,qBAAqB,CAAC,CAAA;SACrD;QAED,IAAI,CAAC,CAAA,MAAA,SAAS,CAAC,WAAW,0CAAE,kBAAkB,CAAA,EAAE;YAC9C,MAAM,IAAI,0BAAmB,CAAC,oDAAoD,CAAC,CAAA;SACpF;QAED,MAAM,eAAe,GAAG,SAAS,CAAC,WAAW,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,eAAe,CAAA;QAEnF,OAAO,eAAe,CAAA;IACxB,CAAC;IAEM,kBAAkB,CAAC,EACxB,2BAA2B,EAC3B,eAAe,EACf,MAAM,EACN,4BAA4B,EAC5B,SAAS,GACY;QACrB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,kBAAkB,GAAG,2BAA2B,CAAA;QACrD,IAAI,CAAC,4BAA4B,GAAG,4BAA4B,CAAA;QAChE,IAAI,CAAC,eAAe,GAAG,eAAe,CAAA;QACtC,IAAI,CAAC,aAAa,GAAG,SAAS,CAAA;IAChC,CAAC;CACF,CAAA;AA9PY,oBAAoB;IADhC,IAAA,iBAAU,GAAE;qCAcR,yCAAmB;GAbX,oBAAoB,CA8PhC;AA9PY,oDAAoB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './PolygonLedgerService';
|
|
@@ -0,0 +1,18 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./PolygonLedgerService"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ledger/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yDAAsC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { DocumentLoader, JwsLinkedDataSignatureOptions, Proof } from '@aries-framework/core';
|
|
2
|
+
import type { JsonLdDoc } from '@aries-framework/core/build/modules/vc/data-integrity/jsonldUtil';
|
|
3
|
+
import { JwsLinkedDataSignature } from '@aries-framework/core';
|
|
4
|
+
export declare const SECURITY_CONTEXT_SECP256k1_URL = "https://w3id.org/security/suites/secp256k1-2019/v1";
|
|
5
|
+
type EcdsaSecp256k1Signature2019Options = Pick<JwsLinkedDataSignatureOptions, 'key' | 'proof' | 'date' | 'useNativeCanonize' | 'LDKeyClass'>;
|
|
6
|
+
/**
|
|
7
|
+
* A secp256k1 signature suite for use with k251 key pairs
|
|
8
|
+
*/
|
|
9
|
+
export declare class EcdsaSecp256k1Signature2019 extends JwsLinkedDataSignature {
|
|
10
|
+
static CONTEXT_URL: string;
|
|
11
|
+
/**
|
|
12
|
+
* @param {object} options - Options hashmap.
|
|
13
|
+
*
|
|
14
|
+
* Either a `key` OR at least one of `signer`/`verifier` is required.
|
|
15
|
+
*
|
|
16
|
+
* @param {object} [options.key] - An optional key object (containing an
|
|
17
|
+
* `id` property, and either `signer` or `verifier`, depending on the
|
|
18
|
+
* intended operation. Useful for when the application is managing keys
|
|
19
|
+
* itself (when using a KMS, you never have access to the private key,
|
|
20
|
+
* and so should use the `signer` param instead).
|
|
21
|
+
* @param {Function} [options.signer] - Signer function that returns an
|
|
22
|
+
* object with an async sign() method. This is useful when interfacing
|
|
23
|
+
* with a KMS (since you don't get access to the private key and its
|
|
24
|
+
* `signer()`, the KMS client gives you only the signer function to use).
|
|
25
|
+
* @param {Function} [options.verifier] - Verifier function that returns
|
|
26
|
+
* an object with an async `verify()` method. Useful when working with a
|
|
27
|
+
* KMS-provided verifier function.
|
|
28
|
+
*
|
|
29
|
+
* Advanced optional parameters and overrides.
|
|
30
|
+
*
|
|
31
|
+
* @param {object} [options.proof] - A JSON-LD document with options to use
|
|
32
|
+
* for the `proof` node. Any other custom fields can be provided here
|
|
33
|
+
* using a context different from security-v2).
|
|
34
|
+
* @param {string|Date} [options.date] - Signing date to use if not passed.
|
|
35
|
+
* @param {boolean} [options.useNativeCanonize] - Whether to use a native
|
|
36
|
+
* canonize algorithm.
|
|
37
|
+
*/
|
|
38
|
+
constructor(options: EcdsaSecp256k1Signature2019Options);
|
|
39
|
+
assertVerificationMethod(document: JsonLdDoc): Promise<void>;
|
|
40
|
+
getVerificationMethod(options: {
|
|
41
|
+
proof: Proof;
|
|
42
|
+
documentLoader?: DocumentLoader;
|
|
43
|
+
}): Promise<any>;
|
|
44
|
+
/**
|
|
45
|
+
* Ensures the document to be signed contains the required signature suite
|
|
46
|
+
* specific `@context`, by either adding it (if `addSuiteContext` is true),
|
|
47
|
+
* or throwing an error if it's missing.
|
|
48
|
+
*
|
|
49
|
+
* @override
|
|
50
|
+
*
|
|
51
|
+
* @param {object} options - Options hashmap.
|
|
52
|
+
* @param {object} options.document - JSON-LD document to be signed.
|
|
53
|
+
* @param {boolean} options.addSuiteContext - Add suite context?
|
|
54
|
+
*/
|
|
55
|
+
ensureSuiteContext(options: {
|
|
56
|
+
document: JsonLdDoc;
|
|
57
|
+
addSuiteContext: boolean;
|
|
58
|
+
}): void;
|
|
59
|
+
}
|
|
60
|
+
export {};
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EcdsaSecp256k1Signature2019 = exports.SECURITY_CONTEXT_SECP256k1_URL = void 0;
|
|
4
|
+
const core_1 = require("@aries-framework/core");
|
|
5
|
+
const jsonldUtil_1 = require("@aries-framework/core/build/modules/vc/data-integrity/jsonldUtil");
|
|
6
|
+
const { jsonld } = core_1.vcLibraries;
|
|
7
|
+
exports.SECURITY_CONTEXT_SECP256k1_URL = 'https://w3id.org/security/suites/secp256k1-2019/v1';
|
|
8
|
+
/**
|
|
9
|
+
* A secp256k1 signature suite for use with k251 key pairs
|
|
10
|
+
*/
|
|
11
|
+
class EcdsaSecp256k1Signature2019 extends core_1.JwsLinkedDataSignature {
|
|
12
|
+
/**
|
|
13
|
+
* @param {object} options - Options hashmap.
|
|
14
|
+
*
|
|
15
|
+
* Either a `key` OR at least one of `signer`/`verifier` is required.
|
|
16
|
+
*
|
|
17
|
+
* @param {object} [options.key] - An optional key object (containing an
|
|
18
|
+
* `id` property, and either `signer` or `verifier`, depending on the
|
|
19
|
+
* intended operation. Useful for when the application is managing keys
|
|
20
|
+
* itself (when using a KMS, you never have access to the private key,
|
|
21
|
+
* and so should use the `signer` param instead).
|
|
22
|
+
* @param {Function} [options.signer] - Signer function that returns an
|
|
23
|
+
* object with an async sign() method. This is useful when interfacing
|
|
24
|
+
* with a KMS (since you don't get access to the private key and its
|
|
25
|
+
* `signer()`, the KMS client gives you only the signer function to use).
|
|
26
|
+
* @param {Function} [options.verifier] - Verifier function that returns
|
|
27
|
+
* an object with an async `verify()` method. Useful when working with a
|
|
28
|
+
* KMS-provided verifier function.
|
|
29
|
+
*
|
|
30
|
+
* Advanced optional parameters and overrides.
|
|
31
|
+
*
|
|
32
|
+
* @param {object} [options.proof] - A JSON-LD document with options to use
|
|
33
|
+
* for the `proof` node. Any other custom fields can be provided here
|
|
34
|
+
* using a context different from security-v2).
|
|
35
|
+
* @param {string|Date} [options.date] - Signing date to use if not passed.
|
|
36
|
+
* @param {boolean} [options.useNativeCanonize] - Whether to use a native
|
|
37
|
+
* canonize algorithm.
|
|
38
|
+
*/
|
|
39
|
+
constructor(options) {
|
|
40
|
+
super({
|
|
41
|
+
type: 'EcdsaSecp256k1Signature2019',
|
|
42
|
+
algorithm: 'EcDSA',
|
|
43
|
+
LDKeyClass: options.LDKeyClass,
|
|
44
|
+
contextUrl: exports.SECURITY_CONTEXT_SECP256k1_URL,
|
|
45
|
+
key: options.key,
|
|
46
|
+
proof: options.proof,
|
|
47
|
+
date: options.date,
|
|
48
|
+
useNativeCanonize: options.useNativeCanonize,
|
|
49
|
+
});
|
|
50
|
+
this.requiredKeyType = 'EcdsaSecp256k1VerificationKey2019';
|
|
51
|
+
}
|
|
52
|
+
async assertVerificationMethod(document) {
|
|
53
|
+
if (!_includesCompatibleContext({ document: document })) {
|
|
54
|
+
// For DID Documents, since keys do not have their own contexts,
|
|
55
|
+
// the suite context is usually provided by the documentLoader logic
|
|
56
|
+
throw new TypeError(`The '@context' of the verification method (key) MUST contain the context url "${this.contextUrl}".`);
|
|
57
|
+
}
|
|
58
|
+
if (!_isSecp256k12019Key(document)) {
|
|
59
|
+
const verificationMethodType = jsonld.getValues(document, 'type')[0];
|
|
60
|
+
throw new Error(`Unsupported verification method type '${verificationMethodType}'. Verification method type MUST be 'EcdsaSecp256k1VerificationKey2019'.`);
|
|
61
|
+
}
|
|
62
|
+
else if (_isSecp256k12019Key(document) && !_includesSecp256k12019Context(document)) {
|
|
63
|
+
throw new Error(`For verification method type 'EcdsaSecp256k1VerificationKey2019' the '@context' MUST contain the context url "${exports.SECURITY_CONTEXT_SECP256k1_URL}".`);
|
|
64
|
+
}
|
|
65
|
+
// ensure verification method has not been revoked
|
|
66
|
+
if (document.revoked !== undefined) {
|
|
67
|
+
throw new Error('The verification method has been revoked.');
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
async getVerificationMethod(options) {
|
|
71
|
+
const verificationMethod = await super.getVerificationMethod({
|
|
72
|
+
proof: options.proof,
|
|
73
|
+
documentLoader: options.documentLoader,
|
|
74
|
+
});
|
|
75
|
+
return verificationMethod;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Ensures the document to be signed contains the required signature suite
|
|
79
|
+
* specific `@context`, by either adding it (if `addSuiteContext` is true),
|
|
80
|
+
* or throwing an error if it's missing.
|
|
81
|
+
*
|
|
82
|
+
* @override
|
|
83
|
+
*
|
|
84
|
+
* @param {object} options - Options hashmap.
|
|
85
|
+
* @param {object} options.document - JSON-LD document to be signed.
|
|
86
|
+
* @param {boolean} options.addSuiteContext - Add suite context?
|
|
87
|
+
*/
|
|
88
|
+
ensureSuiteContext(options) {
|
|
89
|
+
if (_includesCompatibleContext({ document: options.document })) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
super.ensureSuiteContext({ document: options.document, addSuiteContext: options.addSuiteContext });
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
exports.EcdsaSecp256k1Signature2019 = EcdsaSecp256k1Signature2019;
|
|
96
|
+
EcdsaSecp256k1Signature2019.CONTEXT_URL = exports.SECURITY_CONTEXT_SECP256k1_URL;
|
|
97
|
+
function _includesCompatibleContext(options) {
|
|
98
|
+
// Handle the EcdsaSecp256k1Signature2019 / credentials/v1 collision
|
|
99
|
+
const hasSecp256k1 = (0, jsonldUtil_1._includesContext)({
|
|
100
|
+
document: options.document,
|
|
101
|
+
contextUrl: exports.SECURITY_CONTEXT_SECP256k1_URL,
|
|
102
|
+
});
|
|
103
|
+
const hasCred = (0, jsonldUtil_1._includesContext)({ document: options.document, contextUrl: core_1.CREDENTIALS_CONTEXT_V1_URL });
|
|
104
|
+
const hasSecV2 = (0, jsonldUtil_1._includesContext)({ document: options.document, contextUrl: core_1.SECURITY_CONTEXT_URL });
|
|
105
|
+
if (hasSecp256k1 && hasCred) {
|
|
106
|
+
// The secp256k1-2019/v1 and credentials/v1 contexts are incompatible.
|
|
107
|
+
// For VCs using EcdsaSecp256k1Signature2019 suite using the credentials/v1 context is sufficient
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
if (hasSecp256k1 && hasSecV2) {
|
|
111
|
+
// The secp256k1-2019/v1 and security/v2 contexts are incompatible.
|
|
112
|
+
// For VCs using EcdsaSecp256k1Signature2019 suite, using the security/v2 context is sufficient.
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
// Either one by itself is fine, for this suite
|
|
116
|
+
return hasSecp256k1 || hasCred || hasSecV2;
|
|
117
|
+
}
|
|
118
|
+
function _isSecp256k12019Key(verificationMethod) {
|
|
119
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
120
|
+
// @ts-ignore - .hasValue is not part of the public API
|
|
121
|
+
return jsonld.hasValue(verificationMethod, 'type', 'EcdsaSecp256k1VerificationKey2019');
|
|
122
|
+
}
|
|
123
|
+
function _includesSecp256k12019Context(document) {
|
|
124
|
+
return (0, jsonldUtil_1._includesContext)({ document, contextUrl: exports.SECURITY_CONTEXT_SECP256k1_URL });
|
|
125
|
+
}
|
|
126
|
+
//# sourceMappingURL=EcdsaSecp256k1Signature2019.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EcdsaSecp256k1Signature2019.js","sourceRoot":"","sources":["../../src/signature-suites/EcdsaSecp256k1Signature2019.ts"],"names":[],"mappings":";;;AAGA,gDAK8B;AAC9B,iGAAmG;AAEnG,MAAM,EAAE,MAAM,EAAE,GAAG,kBAAW,CAAA;AAEjB,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AAY,IAAI,OAAO,IAAI,QAAQ,CAAA;AAC5C,CAAC;AAED,SAAS,mBAAmB,CAAC,kBAA6B;IACxD,6DAA6D;IAC7D,uDAAuD;IACvD,OAAO,MAAM,CAAC,QAAQ,CAAC,kBAAkB,EAAE,MAAM,EAAE,mCAAmC,CAAC,CAAA;AACzF,CAAC;AAED,SAAS,6BAA6B,CAAC,QAAmB;IACxD,OAAO,IAAA,6BAAgB,EAAC,EAAE,QAAQ,EAAE,UAAU,EAAE,sCAA8B,EAAE,CAAC,CAAA;AACnF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './EcdsaSecp256k1Signature2019';
|
|
@@ -0,0 +1,18 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./EcdsaSecp256k1Signature2019"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/signature-suites/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gEAA6C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './utils';
|
|
@@ -0,0 +1,18 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./utils"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAuB"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { DidDocument } from '@aries-framework/core';
|
|
2
|
+
export declare const generateSecp256k1KeyPair: () => Promise<{
|
|
3
|
+
privateKey: string;
|
|
4
|
+
publicKeyBase58: string;
|
|
5
|
+
address: string;
|
|
6
|
+
}>;
|
|
7
|
+
export declare function getSecp256k1DidDocWithPublicKey(did: string, publicKeyBase58: string, serviceEndpoint?: string): DidDocument;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getSecp256k1DidDocWithPublicKey = exports.generateSecp256k1KeyPair = void 0;
|
|
4
|
+
const core_1 = require("@aries-framework/core");
|
|
5
|
+
const polygon_did_registrar_1 = require("@ayanworks/polygon-did-registrar");
|
|
6
|
+
const signature_suites_1 = require("../signature-suites");
|
|
7
|
+
const generateSecp256k1KeyPair = async () => {
|
|
8
|
+
const { privateKey, publicKeyBase58, address } = await polygon_did_registrar_1.PolygonDID.createKeyPair('testnet');
|
|
9
|
+
return { privateKey, publicKeyBase58, address };
|
|
10
|
+
};
|
|
11
|
+
exports.generateSecp256k1KeyPair = generateSecp256k1KeyPair;
|
|
12
|
+
function getSecp256k1DidDocWithPublicKey(did, publicKeyBase58, serviceEndpoint) {
|
|
13
|
+
const verificationMethod = new core_1.VerificationMethod({
|
|
14
|
+
id: `${did}#key-1`,
|
|
15
|
+
type: core_1.VERIFICATION_METHOD_TYPE_ECDSA_SECP256K1_VERIFICATION_KEY_2019,
|
|
16
|
+
controller: did,
|
|
17
|
+
publicKeyBase58,
|
|
18
|
+
});
|
|
19
|
+
const didDocumentBuilder = new core_1.DidDocumentBuilder(did);
|
|
20
|
+
didDocumentBuilder.addContext(signature_suites_1.SECURITY_CONTEXT_SECP256k1_URL).addVerificationMethod(verificationMethod);
|
|
21
|
+
if (serviceEndpoint) {
|
|
22
|
+
const service = new core_1.DidDocumentService({
|
|
23
|
+
id: `${did}#linked-domain`,
|
|
24
|
+
serviceEndpoint,
|
|
25
|
+
type: 'LinkedDomains',
|
|
26
|
+
});
|
|
27
|
+
didDocumentBuilder.addService(service);
|
|
28
|
+
}
|
|
29
|
+
didDocumentBuilder
|
|
30
|
+
.addAuthentication(verificationMethod.id)
|
|
31
|
+
.addAssertionMethod(verificationMethod.id)
|
|
32
|
+
.addCapabilityDelegation(verificationMethod.id)
|
|
33
|
+
.addCapabilityInvocation(verificationMethod.id);
|
|
34
|
+
didDocumentBuilder.addKeyAgreement(verificationMethod.id);
|
|
35
|
+
return didDocumentBuilder.build();
|
|
36
|
+
}
|
|
37
|
+
exports.getSecp256k1DidDocWithPublicKey = getSecp256k1DidDocWithPublicKey;
|
|
38
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils/utils.ts"],"names":[],"mappings":";;;AAEA,gDAK8B;AAC9B,4EAA6D;AAE7D,0DAAoE;AAE7D,MAAM,wBAAwB,GAAG,KAAK,IAAI,EAAE;IACjD,MAAM,EAAE,UAAU,EAAE,eAAe,EAAE,OAAO,EAAE,GAAG,MAAM,kCAAU,CAAC,aAAa,CAAC,SAAS,CAAC,CAAA;IAC1F,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,OAAO,EAAE,CAAA;AACjD,CAAC,CAAA;AAHY,QAAA,wBAAwB,4BAGpC;AAED,SAAgB,+BAA+B,CAC7C,GAAW,EACX,eAAuB,EACvB,eAAwB;IAExB,MAAM,kBAAkB,GAAG,IAAI,yBAAkB,CAAC;QAChD,EAAE,EAAE,GAAG,GAAG,QAAQ;QAClB,IAAI,EAAE,qEAA8D;QACpE,UAAU,EAAE,GAAG;QACf,eAAe;KAChB,CAAC,CAAA;IAEF,MAAM,kBAAkB,GAAG,IAAI,yBAAkB,CAAC,GAAG,CAAC,CAAA;IACtD,kBAAkB,CAAC,UAAU,CAAC,iDAA8B,CAAC,CAAC,qBAAqB,CAAC,kBAAkB,CAAC,CAAA;IAEvG,IAAI,eAAe,EAAE;QACnB,MAAM,OAAO,GAAG,IAAI,yBAAkB,CAAC;YACrC,EAAE,EAAE,GAAG,GAAG,gBAAgB;YAC1B,eAAe;YACf,IAAI,EAAE,eAAe;SACtB,CAAC,CAAA;QAEF,kBAAkB,CAAC,UAAU,CAAC,OAAO,CAAC,CAAA;KACvC;IAED,kBAAkB;SACf,iBAAiB,CAAC,kBAAkB,CAAC,EAAE,CAAC;SACxC,kBAAkB,CAAC,kBAAkB,CAAC,EAAE,CAAC;SACzC,uBAAuB,CAAC,kBAAkB,CAAC,EAAE,CAAC;SAC9C,uBAAuB,CAAC,kBAAkB,CAAC,EAAE,CAAC,CAAA;IAEjD,kBAAkB,CAAC,eAAe,CAAC,kBAAkB,CAAC,EAAE,CAAC,CAAA;IAEzD,OAAO,kBAAkB,CAAC,KAAK,EAAE,CAAA;AACnC,CAAC;AAlCD,0EAkCC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ayanworks/credo-polygon-w3c-module",
|
|
3
|
+
"main": "build/index",
|
|
4
|
+
"types": "build/index",
|
|
5
|
+
"version": "0.0.1",
|
|
6
|
+
"files": [
|
|
7
|
+
"build"
|
|
8
|
+
],
|
|
9
|
+
"license": "Apache-2.0",
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"access": "public"
|
|
12
|
+
},
|
|
13
|
+
"homepage": "https://github.com/ayanworks/afj-polygon-w3c-module",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "https://github.com/ayanworks/afj-polygon-w3c-module"
|
|
17
|
+
},
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "yarn run clean && yarn run compile",
|
|
20
|
+
"clean": "rimraf -rf ./build",
|
|
21
|
+
"compile": "tsc -p tsconfig.build.json",
|
|
22
|
+
"prepublishOnly": "yarn run build",
|
|
23
|
+
"check-types": "tsc --noEmit -p tsconfig.build.json",
|
|
24
|
+
"check-format": "yarn prettier --check",
|
|
25
|
+
"prettier": "prettier --ignore-path .gitignore '**/*.+(js|json|ts|md|yml|yaml)'",
|
|
26
|
+
"test": "jest",
|
|
27
|
+
"lint": "eslint --ignore-path .gitignore ."
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@aries-framework/askar": "0.4.2",
|
|
31
|
+
"@aries-framework/core": "0.4.2",
|
|
32
|
+
"@ayanworks/polygon-did-registrar": "0.0.16-alpha.12",
|
|
33
|
+
"@ayanworks/polygon-did-resolver": "0.0.16-alpha.10",
|
|
34
|
+
"@ayanworks/polygon-schema-manager": "0.0.2-alpha.4",
|
|
35
|
+
"@sphereon/pex": "^2.2.2",
|
|
36
|
+
"@sphereon/pex-models": "^2.1.2",
|
|
37
|
+
"@sphereon/ssi-types": "^0.17.5",
|
|
38
|
+
"did-resolver": "^4.1.0",
|
|
39
|
+
"ethers": "^6.9.0",
|
|
40
|
+
"jsonpath": "^1.1.1"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@aries-framework/node": "0.4.2",
|
|
44
|
+
"@hyperledger/aries-askar-nodejs": "^0.1.0",
|
|
45
|
+
"@hyperledger/aries-askar-shared": "^0.1.0",
|
|
46
|
+
"@types/jest": "^26.0.23",
|
|
47
|
+
"@types/jsonpath": "^0.2.4",
|
|
48
|
+
"@types/node": "^16.11.7",
|
|
49
|
+
"@types/node-fetch": "^2.6.4",
|
|
50
|
+
"@types/uuid": "^9.0.0",
|
|
51
|
+
"@typescript-eslint/eslint-plugin": "^6.19.1",
|
|
52
|
+
"@typescript-eslint/parser": "^6.19.1",
|
|
53
|
+
"eslint": "^7.32.0",
|
|
54
|
+
"eslint-config-prettier": "^8.8.0",
|
|
55
|
+
"eslint-import-resolver-typescript": "^3.5.5",
|
|
56
|
+
"eslint-plugin-import": "^2.27.5",
|
|
57
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
58
|
+
"jest": "^29.5.0",
|
|
59
|
+
"patch-package": "^8.0.0",
|
|
60
|
+
"postinstall-postinstall": "^2.1.0",
|
|
61
|
+
"prettier": "^2.2.1",
|
|
62
|
+
"reflect-metadata": "^0.2.1",
|
|
63
|
+
"release-it": "^16.3.0",
|
|
64
|
+
"rimraf": "^4.4.0",
|
|
65
|
+
"rxjs": "^7.8.1",
|
|
66
|
+
"ts-jest": "^29.0.5",
|
|
67
|
+
"ts-node": "^10.8.1",
|
|
68
|
+
"tsconfig-paths": "^4.1.2",
|
|
69
|
+
"typescript": "~4.9.5"
|
|
70
|
+
}
|
|
71
|
+
}
|