@cheqd/did-provider-cheqd 1.6.3 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +43 -11
- package/build/agent/ICheqd.d.ts +7 -3
- package/build/agent/ICheqd.d.ts.map +1 -1
- package/build/agent/ICheqd.js +54 -4
- package/build/agent/ICheqd.js.map +1 -1
- package/build/did-manager/cheqd-did-provider.d.ts +12 -1
- package/build/did-manager/cheqd-did-provider.d.ts.map +1 -1
- package/build/did-manager/cheqd-did-provider.js +25 -1
- package/build/did-manager/cheqd-did-provider.js.map +1 -1
- package/package.json +12 -12
- package/plugin.schema.json +28 -1
- package/src/agent/ICheqd.ts +64 -7
- package/src/did-manager/cheqd-did-provider.ts +48 -4
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Veramo SDK plugin for cheqd DID method
|
|
2
2
|
|
|
3
|
-
[](https://img.shields.io/github/workflow/status/cheqd/did-provider-cheqd/Workflow%20Dispatch/main?label=workflows&style=flat-square)](https://github.com/cheqd/did-provider-cheqd/actions/workflows/dispatch.yml) [](https://www.npmjs.com/package/@cheqd/did-provider-cheqd)
|
|
4
4
|
|
|
5
5
|
[](https://github.com/cheqd/did-provider-cheqd/releases/latest) 
|
|
6
6
|
|
|
@@ -22,28 +22,60 @@ The package's core functionality is borrowed from [Veramo Core NPM package](http
|
|
|
22
22
|
|
|
23
23
|
New DID creation can also be done by passing a full-body DIDoc payload in JSON, rather than having to assemble the document field-by-field.
|
|
24
24
|
|
|
25
|
-
##
|
|
25
|
+
## 🧑💻🛠 Quick Start
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
These quick start steps provide the *minimal* configuration that you need to set Veramo CLI for use with cheqd.
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
Check out our [**advanced CLI setup guide**](https://docs.cheqd.io/identity/building-decentralized-identity-apps/veramo-sdk-for-cheqd/setup-cli) for further customisations and [**troubleshooting Veramo CLI setup**](https://docs.cheqd.io/identity/building-decentralized-identity-apps/veramo-sdk-for-cheqd/setup-cli/troubleshooting-setup) in case you run into any issues.
|
|
30
30
|
|
|
31
|
-
###
|
|
31
|
+
### 1. Install Veramo CLI and clone this repo
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
This step is exactly [as described in Veramo CLI docs](https://veramo.io/docs/veramo_agent/cli_tool/):
|
|
34
34
|
|
|
35
35
|
```bash
|
|
36
|
+
npm install -g @veramo/cli@3.1.6-next.160
|
|
37
|
+
git clone https://github.com/cheqd/did-provider-cheqd.git
|
|
36
38
|
npm install
|
|
37
39
|
```
|
|
38
40
|
|
|
39
|
-
###
|
|
41
|
+
### 2. Generate a new local database encryption key
|
|
40
42
|
|
|
41
|
-
|
|
43
|
+
By default, the `did-provider-cheqd` package has a default SQLite database password, but it's a good idea to modify and change this to a new key unique to your install.
|
|
42
44
|
|
|
43
|
-
|
|
45
|
+
```bash
|
|
46
|
+
$ veramo config gen-key
|
|
47
|
+
|
|
48
|
+
X25519 raw private key (hex encoded):
|
|
49
|
+
|
|
50
|
+
4a5aeb56c7956dd6f3312e7094130a03afc060b95621fa3a86577aaf2b67cc1d
|
|
51
|
+
|
|
52
|
+
You can use this key with @veramo/kms-local#SecretBox
|
|
53
|
+
or replace the default agent.yml 'dbEncryptionKey' constant
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Take the key generated and replace the value under `dbEncryptionKey` in the [`agent.yml`](https://github.com/cheqd/did-provider-cheqd/blob/main/agent.yml) file.
|
|
57
|
+
|
|
58
|
+
### 3. Configure your cheqd/Cosmos account keys and RPC endpoints
|
|
59
|
+
|
|
60
|
+
Configure the following properties under the `didManager` section:
|
|
61
|
+
|
|
62
|
+
1. `cosmosPayerMnemonic`: [Mnemonic associated with your cheqd/Comsos SDK account](https://docs.cheqd.io/node/docs/cheqd-cli/cheqd-cli-key-management). This is only stored locally, and the mnemonic is used to reconstitute the account address and keys used to pay for the transaction.
|
|
63
|
+
2. `rpcUrl`: For both `did:cheqd:mainnet:` as well as `did:cheqd:testnet:` sections, you can specify a Cosmos SDK RPC endpoint. This endpoint is where transactions are sent to. By default, this is populated with `rpc.cheqd.net` (for *mainnet*) and `rpc.cheqd.network` (for *testnet*), but you can can modify this to [a different hosted RPC endpoint for cheqd](https://cosmos.directory/cheqd/nodes) or even your own local/private RPC endpoint.
|
|
64
|
+
3. `defaultProvider` (optional): The default cheqd network is set to `did:cheqd:testnet` to allow developers to test out network functionality. However, if you prefer, you can switch this out to `did:cheqd:mainnet` instead.
|
|
65
|
+
|
|
66
|
+
### 4. Verify your configuration file is correct
|
|
67
|
+
|
|
68
|
+
Once you've completed the steps above, verify that your Veramo configuration is accurate using the following command. If your configuration is correct, you should get a success message like the one below.
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
$ veramo config check -f <path/to/>agent.yml
|
|
72
|
+
|
|
73
|
+
Your Veramo configuration seems fine. An agent can be created and the 'agent.execute()' method can be called on it.
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## 📖 Documentation
|
|
44
77
|
|
|
45
|
-
|
|
46
|
-
2. `cosmosPayerMnemonic`: Mnemonic for the cheqd Cosmos account from which the fees for any transactions are paid.
|
|
78
|
+
[Tutorials, advanced configuration, and architecture for cheqd's Veramo plugin](https://docs.cheqd.io/identity/building-decentralized-identity-apps/veramo-sdk-for-cheqd/) can be found on our [Identity Docs site](https://docs.cheqd.io/identity/).
|
|
47
79
|
|
|
48
80
|
## 💬 Community
|
|
49
81
|
|
package/build/agent/ICheqd.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IAgentContext, IKeyManager, IAgentPlugin, IPluginMethodMap, IAgentPluginSchema, IIdentifier } from '@veramo/core';
|
|
2
|
-
import { IdentifierPayload, TImportableEd25519Key } from '../did-manager/cheqd-did-provider';
|
|
2
|
+
import { CheqdDIDProvider, IdentifierPayload, TImportableEd25519Key } from '../did-manager/cheqd-did-provider';
|
|
3
3
|
declare type IContext = IAgentContext<IKeyManager>;
|
|
4
4
|
declare type TExportedDIDDocWithKeys = {
|
|
5
5
|
didDoc: IdentifierPayload;
|
|
@@ -7,23 +7,27 @@ declare type TExportedDIDDocWithKeys = {
|
|
|
7
7
|
};
|
|
8
8
|
declare const CreateIdentifierMethodName = "cheqdCreateIdentifier";
|
|
9
9
|
declare const UpdateIdentifierMethodName = "cheqdUpdateIdentifier";
|
|
10
|
+
declare const CreateResourceMethodName = "cheqdCreateResource";
|
|
10
11
|
declare const GenerateDidDocMethodName = "cheqdGenerateDidDoc";
|
|
11
12
|
declare const GenerateKeyPairMethodName = "cheqdGenerateIdentityKeys";
|
|
12
13
|
export interface ICheqd extends IPluginMethodMap {
|
|
13
14
|
[CreateIdentifierMethodName]: (args: any, context: IContext) => Promise<Omit<IIdentifier, 'provider'>>;
|
|
14
15
|
[UpdateIdentifierMethodName]: (args: any, context: IContext) => Promise<void>;
|
|
16
|
+
[CreateResourceMethodName]: (args: any, context: IContext) => Promise<void>;
|
|
15
17
|
[GenerateDidDocMethodName]: (args: any, context: IContext) => Promise<TExportedDIDDocWithKeys>;
|
|
16
18
|
[GenerateKeyPairMethodName]: (args: any, context: IContext) => Promise<TImportableEd25519Key>;
|
|
17
19
|
}
|
|
18
20
|
export declare class Cheqd implements IAgentPlugin {
|
|
19
21
|
readonly methods?: ICheqd;
|
|
20
22
|
readonly schema?: IAgentPluginSchema;
|
|
21
|
-
readonly didProvider:
|
|
23
|
+
readonly didProvider: CheqdDIDProvider;
|
|
24
|
+
readonly providerId: string;
|
|
22
25
|
constructor(args: {
|
|
23
|
-
provider:
|
|
26
|
+
provider: CheqdDIDProvider;
|
|
24
27
|
});
|
|
25
28
|
private CreateIdentifier;
|
|
26
29
|
private UpdateIdentifier;
|
|
30
|
+
private CreateResource;
|
|
27
31
|
private GenerateDidDoc;
|
|
28
32
|
private GenerateIdentityKeys;
|
|
29
33
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ICheqd.d.ts","sourceRoot":"","sources":["../../src/agent/ICheqd.ts"],"names":[],"mappings":"AAEA,OAAO,EACH,aAAa,EACb,WAAW,EACX,YAAY,EACZ,gBAAgB,EAChB,kBAAkB,EAClB,WAAW,EACd,MAAM,cAAc,CAAA;AACrB,OAAO,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,
|
|
1
|
+
{"version":3,"file":"ICheqd.d.ts","sourceRoot":"","sources":["../../src/agent/ICheqd.ts"],"names":[],"mappings":"AAEA,OAAO,EACH,aAAa,EACb,WAAW,EACX,YAAY,EACZ,gBAAgB,EAChB,kBAAkB,EAClB,WAAW,EACd,MAAM,cAAc,CAAA;AACrB,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAG/G,aAAK,QAAQ,GAAG,aAAa,CAAC,WAAW,CAAC,CAAA;AAC1C,aAAK,uBAAuB,GAAG;IAAE,MAAM,EAAE,iBAAiB,CAAC;IAAC,IAAI,EAAE,qBAAqB,CAAA;CAAE,CAAA;AAEzF,QAAA,MAAM,0BAA0B,0BAA0B,CAAA;AAC1D,QAAA,MAAM,0BAA0B,0BAA0B,CAAA;AAC1D,QAAA,MAAM,wBAAwB,wBAAwB,CAAA;AACtD,QAAA,MAAM,wBAAwB,wBAAwB,CAAA;AACtD,QAAA,MAAM,yBAAyB,8BAA8B,CAAA;AAK7D,MAAM,WAAW,MAAO,SAAQ,gBAAgB;IAC5C,CAAC,0BAA0B,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,QAAQ,KAAK,OAAO,CAAC,IAAI,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC,CAAA;IACtG,CAAC,0BAA0B,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,QAAQ,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9E,CAAC,wBAAwB,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,QAAQ,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5E,CAAC,wBAAwB,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,QAAQ,KAAK,OAAO,CAAC,uBAAuB,CAAC,CAAC;IAC/F,CAAC,yBAAyB,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,QAAQ,KAAK,OAAO,CAAC,qBAAqB,CAAC,CAAA;CAChG;AAED,qBAAa,KAAM,YAAW,YAAY;IACtC,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,MAAM,CAAC,EAAE,kBAAkB,CA6FnC;IACD,QAAQ,CAAC,WAAW,EAAE,gBAAgB,CAAC;IACvC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;gBAEhB,IAAI,EAAE;QAAE,QAAQ,EAAE,gBAAgB,CAAA;KAAE;YAiBlC,gBAAgB;YA4BhB,gBAAgB;YA4BhB,cAAc;YAsBd,cAAc;YAsCd,oBAAoB;CASrC"}
|
package/build/agent/ICheqd.js
CHANGED
|
@@ -5,8 +5,11 @@ const sdk_1 = require("@cheqd/sdk");
|
|
|
5
5
|
const uint8arrays_1 = require("uint8arrays");
|
|
6
6
|
const CreateIdentifierMethodName = 'cheqdCreateIdentifier';
|
|
7
7
|
const UpdateIdentifierMethodName = 'cheqdUpdateIdentifier';
|
|
8
|
+
const CreateResourceMethodName = 'cheqdCreateResource';
|
|
8
9
|
const GenerateDidDocMethodName = 'cheqdGenerateDidDoc';
|
|
9
10
|
const GenerateKeyPairMethodName = 'cheqdGenerateIdentityKeys';
|
|
11
|
+
const DidPrefix = 'did';
|
|
12
|
+
const CheqdDidMethod = 'cheqd';
|
|
10
13
|
class Cheqd {
|
|
11
14
|
constructor(args) {
|
|
12
15
|
this.schema = {
|
|
@@ -49,6 +52,24 @@ class Cheqd {
|
|
|
49
52
|
"type": "object"
|
|
50
53
|
}
|
|
51
54
|
},
|
|
55
|
+
"cheqdCreateResource": {
|
|
56
|
+
"description": "Create a new resource",
|
|
57
|
+
"arguments": {
|
|
58
|
+
"type": "object",
|
|
59
|
+
"properties": {
|
|
60
|
+
"args": {
|
|
61
|
+
"type": "object",
|
|
62
|
+
"description": "A cheqdCreateResource object as any for extensibility"
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
"required": [
|
|
66
|
+
"args"
|
|
67
|
+
]
|
|
68
|
+
},
|
|
69
|
+
"returnType": {
|
|
70
|
+
"type": "object"
|
|
71
|
+
}
|
|
72
|
+
},
|
|
52
73
|
"cheqdGenerateDidDoc": {
|
|
53
74
|
"description": "Generate a new DID document to use with `createIdentifier`",
|
|
54
75
|
"arguments": {
|
|
@@ -58,7 +79,13 @@ class Cheqd {
|
|
|
58
79
|
"type": "object",
|
|
59
80
|
"description": "A cheqdGenerateDidDocArgs object as any for extensibility"
|
|
60
81
|
}
|
|
61
|
-
}
|
|
82
|
+
},
|
|
83
|
+
"required": [
|
|
84
|
+
"args"
|
|
85
|
+
]
|
|
86
|
+
},
|
|
87
|
+
"returnType": {
|
|
88
|
+
"type": "object"
|
|
62
89
|
}
|
|
63
90
|
},
|
|
64
91
|
"cheqdGenerateIdentityKeys": {
|
|
@@ -71,18 +98,23 @@ class Cheqd {
|
|
|
71
98
|
"description": "A cheqdGenerateIdentityKeysArgs object as any for extensibility"
|
|
72
99
|
}
|
|
73
100
|
}
|
|
101
|
+
},
|
|
102
|
+
"returnType": {
|
|
103
|
+
"type": "object"
|
|
74
104
|
}
|
|
75
105
|
}
|
|
76
106
|
}
|
|
77
107
|
}
|
|
78
108
|
};
|
|
79
|
-
if (typeof args.provider !== '
|
|
109
|
+
if (typeof args.provider !== 'object') {
|
|
80
110
|
throw new Error('[cheqd-plugin]: provider is required');
|
|
81
111
|
}
|
|
82
112
|
this.didProvider = args.provider;
|
|
113
|
+
this.providerId = `${DidPrefix}:${CheqdDidMethod}:${this.didProvider.network}`;
|
|
83
114
|
this.methods = {
|
|
84
115
|
[CreateIdentifierMethodName]: this.CreateIdentifier.bind(this),
|
|
85
116
|
[UpdateIdentifierMethodName]: this.UpdateIdentifier.bind(this),
|
|
117
|
+
[CreateResourceMethodName]: this.CreateResource.bind(this),
|
|
86
118
|
[GenerateDidDocMethodName]: this.GenerateDidDoc.bind(this),
|
|
87
119
|
[GenerateKeyPairMethodName]: this.GenerateIdentityKeys.bind(this)
|
|
88
120
|
};
|
|
@@ -103,7 +135,7 @@ class Cheqd {
|
|
|
103
135
|
return await context.agent.didManagerCreate({
|
|
104
136
|
kms: args.kms,
|
|
105
137
|
alias: args.alias,
|
|
106
|
-
provider: this.
|
|
138
|
+
provider: this.providerId,
|
|
107
139
|
options: {
|
|
108
140
|
document: args.document,
|
|
109
141
|
keys: args.keys
|
|
@@ -126,13 +158,31 @@ class Cheqd {
|
|
|
126
158
|
return await context.agent.didManagerUpdate({
|
|
127
159
|
did: args.did,
|
|
128
160
|
document: args.document,
|
|
129
|
-
provider: this.
|
|
161
|
+
provider: this.providerId,
|
|
130
162
|
options: {
|
|
131
163
|
kms: args.kms,
|
|
132
164
|
keys: args.keys
|
|
133
165
|
}
|
|
134
166
|
});
|
|
135
167
|
}
|
|
168
|
+
async CreateResource(args, context) {
|
|
169
|
+
if (typeof args.kms !== 'string') {
|
|
170
|
+
throw new Error('[cheqd-plugin]: kms is required');
|
|
171
|
+
}
|
|
172
|
+
if (typeof args.payload !== 'object') {
|
|
173
|
+
throw new Error('[cheqd-plugin]: payload object is required');
|
|
174
|
+
}
|
|
175
|
+
if (typeof args.payload !== 'object') {
|
|
176
|
+
throw new Error('[cheqd-plugin]: payload object is required');
|
|
177
|
+
}
|
|
178
|
+
return await this.didProvider.createResource({
|
|
179
|
+
options: {
|
|
180
|
+
kms: args.kms,
|
|
181
|
+
payload: args.payload,
|
|
182
|
+
signInputs: args.signInputs
|
|
183
|
+
}
|
|
184
|
+
}, context);
|
|
185
|
+
}
|
|
136
186
|
async GenerateDidDoc(args,
|
|
137
187
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
138
188
|
context) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ICheqd.js","sourceRoot":"","sources":["../../src/agent/ICheqd.ts"],"names":[],"mappings":";;;AACA,oCAAyI;AAUzI,6CAAkD;AAKlD,MAAM,0BAA0B,GAAG,uBAAuB,CAAA;AAC1D,MAAM,0BAA0B,GAAG,uBAAuB,CAAA;AAC1D,MAAM,wBAAwB,GAAG,qBAAqB,CAAA;AACtD,MAAM,yBAAyB,GAAG,2BAA2B,CAAA;
|
|
1
|
+
{"version":3,"file":"ICheqd.js","sourceRoot":"","sources":["../../src/agent/ICheqd.ts"],"names":[],"mappings":";;;AACA,oCAAyI;AAUzI,6CAAkD;AAKlD,MAAM,0BAA0B,GAAG,uBAAuB,CAAA;AAC1D,MAAM,0BAA0B,GAAG,uBAAuB,CAAA;AAC1D,MAAM,wBAAwB,GAAG,qBAAqB,CAAA;AACtD,MAAM,wBAAwB,GAAG,qBAAqB,CAAA;AACtD,MAAM,yBAAyB,GAAG,2BAA2B,CAAA;AAE7D,MAAM,SAAS,GAAG,KAAK,CAAA;AACvB,MAAM,cAAc,GAAG,OAAO,CAAA;AAU9B,MAAa,KAAK;IAmGd,YAAY,IAAoC;QAjGvC,WAAM,GAAwB;YACnC,YAAY,EAAE;gBACV,SAAS,EAAE,EAAE;gBACb,SAAS,EAAE;oBACP,uBAAuB,EAAE;wBACrB,aAAa,EAAE,yBAAyB;wBACxC,WAAW,EAAE;4BACT,MAAM,EAAE,QAAQ;4BAChB,YAAY,EAAE;gCACV,MAAM,EAAE;oCACJ,MAAM,EAAE,QAAQ;oCAChB,aAAa,EAAE,6DAA6D;iCAC/E;6BACJ;4BACD,UAAU,EAAE;gCACR,MAAM;6BACT;yBACJ;wBACD,YAAY,EAAE;4BACV,MAAM,EAAE,QAAQ;yBACnB;qBACJ;oBACD,uBAAuB,EAAE;wBACrB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AE,CAAA;QAC3K,MAAM,gBAAgB,GAAG,IAAA,4BAAsB,EAAC,OAAO,EAAE,IAAI,CAAC,oBAAoB,EAAE,OAAO,EAAE,IAAI,CAAC,sBAAsB,EAAE,IAAI,CAAC,OAAO,CAAC,CAAA;QACvI,MAAM,mBAAmB,GAAG,IAAA,iCAA2B,EAAC,CAAC,IAAI,CAAC,kBAAkB,CAAC,EAAE,CAAC,gBAAgB,CAAC,CAAC,CAAA;QAEtG,OAAO;YACH,MAAM,EAAE,IAAA,sBAAgB,EAAC,mBAAmB,EAAE,CAAC,gBAAgB,CAAC,CAAC;YACjE,IAAI,EAAE;gBACF,YAAY,EAAE,UAAU,CAAC,SAAS;gBAClC,aAAa,EAAE,UAAU,CAAC,UAAU;gBACpC,GAAG,EAAE,UAAU,CAAC,SAAS;gBACzB,IAAI,EAAE,SAAS;aAClB;SACJ,CAAA;IACL,CAAC;IAED,6DAA6D;IACrD,KAAK,CAAC,oBAAoB,CAAC,IAAS,EAAE,OAAiB;QAC3D,MAAM,OAAO,GAAG,IAAA,sBAAgB,GAAE,CAAA;QAClC,OAAO;YACH,YAAY,EAAE,OAAO,CAAC,SAAS;YAC/B,aAAa,EAAE,OAAO,CAAC,UAAU;YACjC,GAAG,EAAE,OAAO,CAAC,SAAS;YACtB,IAAI,EAAE,SAAS;SAClB,CAAA;IACL,CAAC;CACJ;AAjPD,sBAiPC"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { ISignInputs } from '@cheqd/sdk/src/types';
|
|
1
2
|
import { MsgCreateDidPayload, MsgUpdateDidPayload } from '@cheqd/ts-proto/cheqd/v1/tx';
|
|
3
|
+
import { MsgCreateResourcePayload } from '@cheqd/ts-proto/resource/v1/tx';
|
|
2
4
|
import { DIDDocument } from '@veramo/core/src';
|
|
3
5
|
import { IIdentifier, IKey, IService, IAgentContext, IKeyManager } from '@veramo/core';
|
|
4
6
|
import { AbstractIdentifierProvider } from '@veramo/did-manager';
|
|
@@ -12,17 +14,19 @@ export declare enum NetworkType {
|
|
|
12
14
|
Testnet = "testnet"
|
|
13
15
|
}
|
|
14
16
|
export declare type IdentifierPayload = Partial<MsgCreateDidPayload> | Partial<MsgUpdateDidPayload>;
|
|
17
|
+
export declare type ResourcePayload = Partial<MsgCreateResourcePayload>;
|
|
15
18
|
export declare type TImportableEd25519Key = Required<Pick<IKey, 'publicKeyHex' | 'privateKeyHex'>> & {
|
|
16
19
|
kid: TImportableEd25519Key['publicKeyHex'];
|
|
17
20
|
type: 'Ed25519';
|
|
18
21
|
};
|
|
22
|
+
export declare type TSupportedKeyType = 'Ed25519' | 'Secp256k1';
|
|
19
23
|
/**
|
|
20
24
|
* {@link @veramo/did-manager#DIDManager} identifier provider for `did:cheqd` identifiers.
|
|
21
25
|
* @public
|
|
22
26
|
*/
|
|
23
27
|
export declare class CheqdDIDProvider extends AbstractIdentifierProvider {
|
|
24
28
|
private defaultKms;
|
|
25
|
-
|
|
29
|
+
readonly network: NetworkType;
|
|
26
30
|
private rpcUrl;
|
|
27
31
|
private readonly cosmosPayerWallet;
|
|
28
32
|
private sdk?;
|
|
@@ -59,6 +63,13 @@ export declare class CheqdDIDProvider extends AbstractIdentifierProvider {
|
|
|
59
63
|
keys: TImportableEd25519Key[];
|
|
60
64
|
};
|
|
61
65
|
}, context: IContext): Promise<IIdentifier>;
|
|
66
|
+
createResource({ options }: {
|
|
67
|
+
options: {
|
|
68
|
+
payload: ResourcePayload;
|
|
69
|
+
signInputs: ISignInputs[];
|
|
70
|
+
kms: string;
|
|
71
|
+
};
|
|
72
|
+
}, context: IContext): Promise<void>;
|
|
62
73
|
deleteIdentifier(identity: IIdentifier, context: IContext): Promise<boolean>;
|
|
63
74
|
addKey({ identifier, key, options, }: {
|
|
64
75
|
identifier: IIdentifier;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cheqd-did-provider.d.ts","sourceRoot":"","sources":["../../src/did-manager/cheqd-did-provider.ts"],"names":[],"mappings":"
|
|
1
|
+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CAAC;IAOb,MAAM,CACX,EAEC,UAAU,EAEV,GAAG,EAEH,OAAO,GAEP,EAAE;QAAE,UAAU,EAAE,WAAW,CAAC;QAAC,GAAG,EAAE,IAAI,CAAC;QAAC,OAAO,CAAC,EAAE,GAAG,CAAA;KAAE,EAExD,OAAO,EAAE,QAAQ,GAEf,OAAO,CAAC,GAAG,CAAC;IAIT,UAAU,CACf,EAEC,UAAU,EAEV,OAAO,EAEP,OAAO,GAEP,EAAE;QAAE,UAAU,EAAE,WAAW,CAAC;QAAC,OAAO,EAAE,QAAQ,CAAC;QAAC,OAAO,CAAC,EAAE,GAAG,CAAA;KAAE,EAEhE,OAAO,EAAE,QAAQ,GAEf,OAAO,CAAC,GAAG,CAAC;IAIT,SAAS,CAEd,IAAI,EAAE;QACL,UAAU,EAAE,WAAW,CAAC;QACxB,GAAG,EAAE,MAAM,CAAC;QAEZ,OAAO,CAAC,EAAE,GAAG,CAAA;KACb,EAED,OAAO,EAAE,QAAQ,GAEf,OAAO,CAAC,GAAG,CAAC;IAIT,aAAa,CAElB,IAAI,EAAE;QACL,UAAU,EAAE,WAAW,CAAC;QACxB,EAAE,EAAE,MAAM,CAAC;QAEX,OAAO,CAAC,EAAE,GAAG,CAAA;KACb,EAED,OAAO,EAAE,QAAQ,GAEf,OAAO,CAAC,GAAG,CAAC;CAGf"}
|
|
@@ -46,7 +46,7 @@ class CheqdDIDProvider extends did_manager_1.AbstractIdentifierProvider {
|
|
|
46
46
|
const sdkOptions = {
|
|
47
47
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
48
48
|
// @ts-ignore - No actual type insufficiency here. Learn more about this in the docs.
|
|
49
|
-
modules: [sdk_1.DIDModule],
|
|
49
|
+
modules: [sdk_1.DIDModule, sdk_1.ResourceModule],
|
|
50
50
|
rpcUrl: this.rpcUrl,
|
|
51
51
|
wallet: await this.cosmosPayerWallet,
|
|
52
52
|
};
|
|
@@ -113,6 +113,30 @@ class CheqdDIDProvider extends did_manager_1.AbstractIdentifierProvider {
|
|
|
113
113
|
debug('Updated DID', did);
|
|
114
114
|
return identifier;
|
|
115
115
|
}
|
|
116
|
+
async createResource({ options }, context) {
|
|
117
|
+
const sdk = await this.getCheqdSDK();
|
|
118
|
+
const tx = await sdk.createResourceTx(options.signInputs, options.payload, '', this.fee || 'auto', undefined, { sdk: sdk });
|
|
119
|
+
(0, utils_1.assert)(tx.code === 0, `cosmos_transaction: Failed to create Resource. Reason: ${tx.rawLog}`);
|
|
120
|
+
const mapKeyType = (keyType) => {
|
|
121
|
+
switch (keyType) {
|
|
122
|
+
case "Ed25519": return "Ed25519";
|
|
123
|
+
case "Secp256k1": return "Secp256k1";
|
|
124
|
+
default: return undefined;
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
await Promise.all(options.signInputs.filter(input => mapKeyType(input.keyType) !== undefined)
|
|
128
|
+
.map(async (signInput) => await context.agent.keyManagerImport({
|
|
129
|
+
privateKeyHex: signInput.privateKeyHex,
|
|
130
|
+
type: mapKeyType(signInput.keyType),
|
|
131
|
+
kms: options.kms || this.defaultKms,
|
|
132
|
+
}).catch((e) => {
|
|
133
|
+
if (e.message.includes('key_already_exists'))
|
|
134
|
+
debug('Key already exists');
|
|
135
|
+
else
|
|
136
|
+
throw e;
|
|
137
|
+
})));
|
|
138
|
+
debug('Created Resource', options.payload);
|
|
139
|
+
}
|
|
116
140
|
async deleteIdentifier(identity, context) {
|
|
117
141
|
for (const { kid } of identity.keys) {
|
|
118
142
|
await context.agent.keyManagerDelete({ kid });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cheqd-did-provider.js","sourceRoot":"","sources":["../../src/did-manager/cheqd-did-provider.ts"],"names":[],"mappings":";;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"cheqd-did-provider.js","sourceRoot":"","sources":["../../src/did-manager/cheqd-did-provider.ts"],"names":[],"mappings":";;;;;;AAAA,oCAA4I;AAM5I,yDAA+D;AAC/D,yCAAsC;AAYtC,q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AC,gBAAgB,CACrB,QAAqB,EACrB,OAAiB;QAEjB,KAAK,MAAM,EAAE,GAAG,EAAE,IAAI,QAAQ,CAAC,IAAI,EAAE;YACpC,MAAM,OAAO,CAAC,KAAK,CAAC,gBAAgB,CAAC,EAAE,GAAG,EAAE,CAAC,CAAA;SAC7C;QACD,OAAO,IAAI,CAAA;IACZ,CAAC;IAED,KAAK,CAAC,MAAM,CACX;IACC,8DAA8D;IAC9D,UAAU;IACV,8DAA8D;IAC9D,GAAG;IACH,8DAA8D;IAC9D,OAAO;IACP,+DAA+D;MACR;IACxD,8DAA8D;IAC9D,OAAiB;QAGjB,MAAM,KAAK,CAAC,4CAA4C,CAAC,CAAA;IAC1D,CAAC;IAED,KAAK,CAAC,UAAU,CACf;IACC,8DAA8D;IAC9D,UAAU;IACV,8DAA8D;IAC9D,OAAO;IACP,8DAA8D;IAC9D,OAAO;IACP,+DAA+D;MACA;IAChE,8DAA8D;IAC9D,OAAiB;QAGjB,MAAM,KAAK,CAAC,gDAAgD,CAAC,CAAA;IAC9D,CAAC;IAED,KAAK,CAAC,SAAS;IACd,8DAA8D;IAC9D,IAKC;IACD,8DAA8D;IAC9D,OAAiB;QAGjB,MAAM,KAAK,CAAC,+CAA+C,CAAC,CAAA;IAC7D,CAAC;IAED,KAAK,CAAC,aAAa;IAClB,8DAA8D;IAC9D,IAKC;IACD,8DAA8D;IAC9D,OAAiB;QAGjB,MAAM,KAAK,CAAC,mDAAmD,CAAC,CAAA;IACjE,CAAC;CACD;AA1PD,4CA0PC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cheqd/did-provider-cheqd",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0",
|
|
4
4
|
"description": "Veramo SDK plugin for the did:cheqd DID method",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"source": "src/index.ts",
|
|
@@ -46,18 +46,18 @@
|
|
|
46
46
|
"@types/debug": "^4.1.7",
|
|
47
47
|
"@types/jest": "27.5.1",
|
|
48
48
|
"@types/uuid": "^8.3.4",
|
|
49
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
50
|
-
"@typescript-eslint/parser": "^5.
|
|
49
|
+
"@typescript-eslint/eslint-plugin": "^5.34.0",
|
|
50
|
+
"@typescript-eslint/parser": "^5.34.0",
|
|
51
51
|
"@veramo/cli": "^3.1.5",
|
|
52
52
|
"conventional-changelog-conventionalcommits": "^5.0.0",
|
|
53
|
-
"eslint": "^8.
|
|
53
|
+
"eslint": "^8.22.0",
|
|
54
54
|
"eslint-config-prettier": "^8.5.0",
|
|
55
55
|
"eslint-config-typescript": "^3.0.0",
|
|
56
56
|
"jest": "27.5.1",
|
|
57
57
|
"prettier": "^2.7.1",
|
|
58
|
-
"semantic-release": "^19.0.
|
|
59
|
-
"ts-jest": "27.1.5",
|
|
60
|
-
"typescript": "4.7.4"
|
|
58
|
+
"semantic-release": "^19.0.4",
|
|
59
|
+
"ts-jest": "^27.1.5",
|
|
60
|
+
"typescript": "^4.7.4"
|
|
61
61
|
},
|
|
62
62
|
"files": [
|
|
63
63
|
"build/**/*",
|
|
@@ -68,14 +68,14 @@
|
|
|
68
68
|
"tsconfig.json"
|
|
69
69
|
],
|
|
70
70
|
"dependencies": {
|
|
71
|
-
"@cheqd/sdk": "^1.
|
|
72
|
-
"@cheqd/ts-proto": "^1.0.
|
|
71
|
+
"@cheqd/sdk": "^1.3.0",
|
|
72
|
+
"@cheqd/ts-proto": "^1.0.12",
|
|
73
73
|
"@cosmjs/proto-signing": "^0.28.11",
|
|
74
74
|
"@cosmjs/utils": "^0.28.11",
|
|
75
|
-
"@veramo/core": "^3.1.6-next.
|
|
76
|
-
"@veramo/did-manager": "^3.1.6-next.
|
|
75
|
+
"@veramo/core": "^3.1.6-next.167",
|
|
76
|
+
"@veramo/did-manager": "^3.1.6-next.167",
|
|
77
77
|
"@veramo/did-provider-key": "^3.1.3",
|
|
78
|
-
"@veramo/key-manager": "^3.1.6-next.
|
|
78
|
+
"@veramo/key-manager": "^3.1.6-next.167",
|
|
79
79
|
"debug": "^4.3.4",
|
|
80
80
|
"multibase": "^4.0.6",
|
|
81
81
|
"multicodec": "^3.2.1",
|
package/plugin.schema.json
CHANGED
|
@@ -39,6 +39,24 @@
|
|
|
39
39
|
"type": "object"
|
|
40
40
|
}
|
|
41
41
|
},
|
|
42
|
+
"cheqdCreateResource": {
|
|
43
|
+
"description": "Create a new resource",
|
|
44
|
+
"arguments": {
|
|
45
|
+
"type": "object",
|
|
46
|
+
"properties": {
|
|
47
|
+
"args": {
|
|
48
|
+
"type": "object",
|
|
49
|
+
"description": "A cheqdCreateResource object as any for extensibility"
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
"required": [
|
|
53
|
+
"args"
|
|
54
|
+
]
|
|
55
|
+
},
|
|
56
|
+
"returnType": {
|
|
57
|
+
"type": "object"
|
|
58
|
+
}
|
|
59
|
+
},
|
|
42
60
|
"cheqdGenerateDidDoc": {
|
|
43
61
|
"description": "Generate a new DID document to use with `createIdentifier`",
|
|
44
62
|
"arguments": {
|
|
@@ -48,7 +66,13 @@
|
|
|
48
66
|
"type": "object",
|
|
49
67
|
"description": "A cheqdGenerateDidDocArgs object as any for extensibility"
|
|
50
68
|
}
|
|
51
|
-
}
|
|
69
|
+
},
|
|
70
|
+
"required": [
|
|
71
|
+
"args"
|
|
72
|
+
]
|
|
73
|
+
},
|
|
74
|
+
"returnType": {
|
|
75
|
+
"type": "object"
|
|
52
76
|
}
|
|
53
77
|
},
|
|
54
78
|
"cheqdGenerateIdentityKeys": {
|
|
@@ -61,6 +85,9 @@
|
|
|
61
85
|
"description": "A cheqdGenerateIdentityKeysArgs object as any for extensibility"
|
|
62
86
|
}
|
|
63
87
|
}
|
|
88
|
+
},
|
|
89
|
+
"returnType": {
|
|
90
|
+
"type": "object"
|
|
64
91
|
}
|
|
65
92
|
}
|
|
66
93
|
}
|
package/src/agent/ICheqd.ts
CHANGED
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
IAgentPluginSchema,
|
|
9
9
|
IIdentifier
|
|
10
10
|
} from '@veramo/core'
|
|
11
|
-
import { IdentifierPayload, TImportableEd25519Key } from '../did-manager/cheqd-did-provider'
|
|
11
|
+
import { CheqdDIDProvider, IdentifierPayload, TImportableEd25519Key } from '../did-manager/cheqd-did-provider';
|
|
12
12
|
import { fromString, toString } from 'uint8arrays'
|
|
13
13
|
|
|
14
14
|
type IContext = IAgentContext<IKeyManager>
|
|
@@ -16,12 +16,17 @@ type TExportedDIDDocWithKeys = { didDoc: IdentifierPayload, keys: TImportableEd2
|
|
|
16
16
|
|
|
17
17
|
const CreateIdentifierMethodName = 'cheqdCreateIdentifier'
|
|
18
18
|
const UpdateIdentifierMethodName = 'cheqdUpdateIdentifier'
|
|
19
|
+
const CreateResourceMethodName = 'cheqdCreateResource'
|
|
19
20
|
const GenerateDidDocMethodName = 'cheqdGenerateDidDoc'
|
|
20
21
|
const GenerateKeyPairMethodName = 'cheqdGenerateIdentityKeys'
|
|
21
22
|
|
|
23
|
+
const DidPrefix = 'did'
|
|
24
|
+
const CheqdDidMethod = 'cheqd'
|
|
25
|
+
|
|
22
26
|
export interface ICheqd extends IPluginMethodMap {
|
|
23
27
|
[CreateIdentifierMethodName]: (args: any, context: IContext) => Promise<Omit<IIdentifier, 'provider'>>
|
|
24
28
|
[UpdateIdentifierMethodName]: (args: any, context: IContext) => Promise<void>,
|
|
29
|
+
[CreateResourceMethodName]: (args: any, context: IContext) => Promise<void>,
|
|
25
30
|
[GenerateDidDocMethodName]: (args: any, context: IContext) => Promise<TExportedDIDDocWithKeys>,
|
|
26
31
|
[GenerateKeyPairMethodName]: (args: any, context: IContext) => Promise<TImportableEd25519Key>
|
|
27
32
|
}
|
|
@@ -68,6 +73,24 @@ export class Cheqd implements IAgentPlugin {
|
|
|
68
73
|
"type": "object"
|
|
69
74
|
}
|
|
70
75
|
},
|
|
76
|
+
"cheqdCreateResource": {
|
|
77
|
+
"description": "Create a new resource",
|
|
78
|
+
"arguments": {
|
|
79
|
+
"type": "object",
|
|
80
|
+
"properties": {
|
|
81
|
+
"args": {
|
|
82
|
+
"type": "object",
|
|
83
|
+
"description": "A cheqdCreateResource object as any for extensibility"
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
"required": [
|
|
87
|
+
"args"
|
|
88
|
+
]
|
|
89
|
+
},
|
|
90
|
+
"returnType": {
|
|
91
|
+
"type": "object"
|
|
92
|
+
}
|
|
93
|
+
},
|
|
71
94
|
"cheqdGenerateDidDoc": {
|
|
72
95
|
"description": "Generate a new DID document to use with `createIdentifier`",
|
|
73
96
|
"arguments": {
|
|
@@ -77,7 +100,13 @@ export class Cheqd implements IAgentPlugin {
|
|
|
77
100
|
"type": "object",
|
|
78
101
|
"description": "A cheqdGenerateDidDocArgs object as any for extensibility"
|
|
79
102
|
}
|
|
80
|
-
}
|
|
103
|
+
},
|
|
104
|
+
"required": [
|
|
105
|
+
"args"
|
|
106
|
+
]
|
|
107
|
+
},
|
|
108
|
+
"returnType": {
|
|
109
|
+
"type": "object"
|
|
81
110
|
}
|
|
82
111
|
},
|
|
83
112
|
"cheqdGenerateIdentityKeys": {
|
|
@@ -90,23 +119,29 @@ export class Cheqd implements IAgentPlugin {
|
|
|
90
119
|
"description": "A cheqdGenerateIdentityKeysArgs object as any for extensibility"
|
|
91
120
|
}
|
|
92
121
|
}
|
|
122
|
+
},
|
|
123
|
+
"returnType": {
|
|
124
|
+
"type": "object"
|
|
93
125
|
}
|
|
94
126
|
}
|
|
95
127
|
}
|
|
96
128
|
}
|
|
97
129
|
}
|
|
98
|
-
readonly didProvider:
|
|
130
|
+
readonly didProvider: CheqdDIDProvider;
|
|
131
|
+
readonly providerId: string;
|
|
99
132
|
|
|
100
|
-
constructor(args: { provider:
|
|
101
|
-
if (typeof args.provider !== '
|
|
133
|
+
constructor(args: { provider: CheqdDIDProvider }) {
|
|
134
|
+
if (typeof args.provider !== 'object') {
|
|
102
135
|
throw new Error('[cheqd-plugin]: provider is required')
|
|
103
136
|
}
|
|
104
137
|
|
|
105
138
|
this.didProvider = args.provider
|
|
139
|
+
this.providerId = `${DidPrefix}:${CheqdDidMethod}:${this.didProvider.network}`
|
|
106
140
|
|
|
107
141
|
this.methods = {
|
|
108
142
|
[CreateIdentifierMethodName]: this.CreateIdentifier.bind(this),
|
|
109
143
|
[UpdateIdentifierMethodName]: this.UpdateIdentifier.bind(this),
|
|
144
|
+
[CreateResourceMethodName]: this.CreateResource.bind(this),
|
|
110
145
|
[GenerateDidDocMethodName]: this.GenerateDidDoc.bind(this),
|
|
111
146
|
[GenerateKeyPairMethodName]: this.GenerateIdentityKeys.bind(this)
|
|
112
147
|
}
|
|
@@ -132,7 +167,7 @@ export class Cheqd implements IAgentPlugin {
|
|
|
132
167
|
return await context.agent.didManagerCreate({
|
|
133
168
|
kms: args.kms,
|
|
134
169
|
alias: args.alias,
|
|
135
|
-
provider: this.
|
|
170
|
+
provider: this.providerId,
|
|
136
171
|
options: {
|
|
137
172
|
document: args.document,
|
|
138
173
|
keys: args.keys
|
|
@@ -160,7 +195,7 @@ export class Cheqd implements IAgentPlugin {
|
|
|
160
195
|
return await context.agent.didManagerUpdate({
|
|
161
196
|
did: args.did,
|
|
162
197
|
document: args.document,
|
|
163
|
-
provider: this.
|
|
198
|
+
provider: this.providerId,
|
|
164
199
|
options: {
|
|
165
200
|
kms: args.kms,
|
|
166
201
|
keys: args.keys
|
|
@@ -168,6 +203,28 @@ export class Cheqd implements IAgentPlugin {
|
|
|
168
203
|
})
|
|
169
204
|
}
|
|
170
205
|
|
|
206
|
+
private async CreateResource(args: any, context: IContext) {
|
|
207
|
+
if (typeof args.kms !== 'string') {
|
|
208
|
+
throw new Error('[cheqd-plugin]: kms is required')
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
if (typeof args.payload !== 'object') {
|
|
212
|
+
throw new Error('[cheqd-plugin]: payload object is required')
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
if (typeof args.payload !== 'object') {
|
|
216
|
+
throw new Error('[cheqd-plugin]: payload object is required')
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
return await this.didProvider.createResource({
|
|
220
|
+
options: {
|
|
221
|
+
kms: args.kms,
|
|
222
|
+
payload: args.payload,
|
|
223
|
+
signInputs: args.signInputs
|
|
224
|
+
}
|
|
225
|
+
}, context)
|
|
226
|
+
}
|
|
227
|
+
|
|
171
228
|
private async GenerateDidDoc(
|
|
172
229
|
args: { verificationMethod: VerificationMethods, methodSpecificIdAlgo: MethodSpecificIdAlgo, methodSpecificIdLength: 16 | 32, network: CheqdNetwork },
|
|
173
230
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { CheqdSDK, createCheqdSDK, createSignInputsFromImportableEd25519Key, DIDModule, ICheqdSDKOptions } from '@cheqd/sdk'
|
|
1
|
+
import { CheqdSDK, createCheqdSDK, createSignInputsFromImportableEd25519Key, DIDModule, ICheqdSDKOptions, ResourceModule } from '@cheqd/sdk'
|
|
2
2
|
import { AbstractCheqdSDKModule } from '@cheqd/sdk/src/modules/_'
|
|
3
|
-
import { DidStdFee } from '@cheqd/sdk/src/types'
|
|
3
|
+
import { DidStdFee, ISignInputs } from '@cheqd/sdk/src/types'
|
|
4
4
|
import { Service, VerificationMethod } from '@cheqd/ts-proto/cheqd/v1/did'
|
|
5
5
|
import { MsgCreateDidPayload, MsgUpdateDidPayload } from '@cheqd/ts-proto/cheqd/v1/tx'
|
|
6
|
+
import { MsgCreateResourcePayload } from '@cheqd/ts-proto/resource/v1/tx'
|
|
6
7
|
import { DirectSecp256k1HdWallet } from '@cosmjs/proto-signing'
|
|
7
8
|
import { assert } from '@cosmjs/utils'
|
|
8
9
|
import { DIDDocument } from '@veramo/core/src'
|
|
@@ -14,6 +15,7 @@ import {
|
|
|
14
15
|
IKeyManager,
|
|
15
16
|
ManagedKeyInfo,
|
|
16
17
|
MinimalImportableKey,
|
|
18
|
+
TKeyType,
|
|
17
19
|
} from '@veramo/core'
|
|
18
20
|
import { AbstractIdentifierProvider } from '@veramo/did-manager'
|
|
19
21
|
import Debug from 'debug'
|
|
@@ -34,15 +36,19 @@ export enum NetworkType {
|
|
|
34
36
|
|
|
35
37
|
export type IdentifierPayload = Partial<MsgCreateDidPayload> | Partial<MsgUpdateDidPayload>
|
|
36
38
|
|
|
39
|
+
export type ResourcePayload = Partial<MsgCreateResourcePayload>
|
|
40
|
+
|
|
37
41
|
export type TImportableEd25519Key = Required<Pick<IKey, 'publicKeyHex' | 'privateKeyHex'>> & { kid: TImportableEd25519Key['publicKeyHex'], type: 'Ed25519' }
|
|
38
42
|
|
|
43
|
+
export type TSupportedKeyType = 'Ed25519' | 'Secp256k1'
|
|
44
|
+
|
|
39
45
|
/**
|
|
40
46
|
* {@link @veramo/did-manager#DIDManager} identifier provider for `did:cheqd` identifiers.
|
|
41
47
|
* @public
|
|
42
48
|
*/
|
|
43
49
|
export class CheqdDIDProvider extends AbstractIdentifierProvider {
|
|
44
50
|
private defaultKms: string
|
|
45
|
-
|
|
51
|
+
public readonly network: NetworkType
|
|
46
52
|
private rpcUrl: string
|
|
47
53
|
private readonly cosmosPayerWallet: Promise<DirectSecp256k1HdWallet>
|
|
48
54
|
private sdk?: CheqdSDK
|
|
@@ -71,7 +77,7 @@ export class CheqdDIDProvider extends AbstractIdentifierProvider {
|
|
|
71
77
|
const sdkOptions: ICheqdSDKOptions = {
|
|
72
78
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
73
79
|
// @ts-ignore - No actual type insufficiency here. Learn more about this in the docs.
|
|
74
|
-
modules: [DIDModule as unknown as AbstractCheqdSDKModule],
|
|
80
|
+
modules: [DIDModule as unknown as AbstractCheqdSDKModule, ResourceModule as unknown as AbstractCheqdSDKModule],
|
|
75
81
|
rpcUrl: this.rpcUrl,
|
|
76
82
|
wallet: await this.cosmosPayerWallet,
|
|
77
83
|
}
|
|
@@ -179,6 +185,44 @@ export class CheqdDIDProvider extends AbstractIdentifierProvider {
|
|
|
179
185
|
return identifier
|
|
180
186
|
}
|
|
181
187
|
|
|
188
|
+
async createResource(
|
|
189
|
+
{ options }: { options: { payload: ResourcePayload, signInputs: ISignInputs[], kms: string } },
|
|
190
|
+
context: IContext,
|
|
191
|
+
): Promise<void> {
|
|
192
|
+
const sdk = await this.getCheqdSDK()
|
|
193
|
+
|
|
194
|
+
const tx = await sdk.createResourceTx(
|
|
195
|
+
options.signInputs,
|
|
196
|
+
options.payload,
|
|
197
|
+
'',
|
|
198
|
+
this.fee || 'auto',
|
|
199
|
+
undefined,
|
|
200
|
+
{ sdk: sdk }
|
|
201
|
+
)
|
|
202
|
+
|
|
203
|
+
assert(tx.code === 0, `cosmos_transaction: Failed to create Resource. Reason: ${tx.rawLog}`)
|
|
204
|
+
|
|
205
|
+
const mapKeyType = (keyType: "Ed25519" | "Secp256k1" | "P256" | undefined): TKeyType | undefined => {
|
|
206
|
+
switch (keyType) {
|
|
207
|
+
case "Ed25519": return "Ed25519"
|
|
208
|
+
case "Secp256k1": return "Secp256k1"
|
|
209
|
+
default: return undefined
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
await Promise.all(options.signInputs.filter(input => mapKeyType(input.keyType) !== undefined)
|
|
214
|
+
.map(async signInput => await context.agent.keyManagerImport({
|
|
215
|
+
privateKeyHex: signInput.privateKeyHex,
|
|
216
|
+
type: mapKeyType(signInput.keyType) as TSupportedKeyType,
|
|
217
|
+
kms: options.kms || this.defaultKms,
|
|
218
|
+
} as MinimalImportableKey).catch((e: Error) => {
|
|
219
|
+
if (e.message.includes('key_already_exists')) debug('Key already exists'); else throw e
|
|
220
|
+
}))
|
|
221
|
+
)
|
|
222
|
+
|
|
223
|
+
debug('Created Resource', options.payload)
|
|
224
|
+
}
|
|
225
|
+
|
|
182
226
|
async deleteIdentifier(
|
|
183
227
|
identity: IIdentifier,
|
|
184
228
|
context: IContext,
|