@cheqd/did-provider-cheqd 3.6.10-develop.1 → 3.6.10-develop.2
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/build/cjs/agent/ICheqd.d.ts +2 -2
- package/build/cjs/agent/ICheqd.d.ts.map +1 -1
- package/build/cjs/agent/ICheqd.js +1011 -783
- package/build/cjs/agent/ICheqd.js.map +1 -1
- package/build/cjs/agent/index.d.ts.map +1 -1
- package/build/cjs/agent/index.js.map +1 -1
- package/build/cjs/did-manager/cheqd-did-provider.d.ts +12 -12
- package/build/cjs/did-manager/cheqd-did-provider.d.ts.map +1 -1
- package/build/cjs/did-manager/cheqd-did-provider.js +56 -41
- package/build/cjs/did-manager/cheqd-did-provider.js.map +1 -1
- package/build/cjs/did-manager/cheqd-did-resolver.d.ts.map +1 -1
- package/build/cjs/did-manager/cheqd-did-resolver.js.map +1 -1
- package/build/cjs/did-manager/index.d.ts.map +1 -1
- package/build/cjs/did-manager/index.js.map +1 -1
- package/build/cjs/did-manager/resolver.d.ts.map +1 -1
- package/build/cjs/did-manager/resolver.js.map +1 -1
- package/build/cjs/dkg-threshold/index.d.ts.map +1 -1
- package/build/cjs/dkg-threshold/index.js.map +1 -1
- package/build/cjs/dkg-threshold/lit-protocol.d.ts +3 -3
- package/build/cjs/dkg-threshold/lit-protocol.d.ts.map +1 -1
- package/build/cjs/dkg-threshold/lit-protocol.js +30 -19
- package/build/cjs/dkg-threshold/lit-protocol.js.map +1 -1
- package/build/cjs/index.d.ts.map +1 -1
- package/build/cjs/index.js.map +1 -1
- package/build/cjs/utils/env.d.ts.map +1 -1
- package/build/cjs/utils/env.js +11 -2
- package/build/cjs/utils/env.js.map +1 -1
- package/build/cjs/utils/helpers.d.ts.map +1 -1
- package/build/cjs/utils/helpers.js.map +1 -1
- package/build/cjs/utils/index.d.ts.map +1 -1
- package/build/cjs/utils/index.js.map +1 -1
- package/build/esm/agent/ICheqd.d.ts +2 -2
- package/build/esm/agent/ICheqd.d.ts.map +1 -1
- package/build/esm/agent/ICheqd.js +1013 -785
- package/build/esm/agent/ICheqd.js.map +1 -1
- package/build/esm/agent/index.d.ts.map +1 -1
- package/build/esm/agent/index.js.map +1 -1
- package/build/esm/did-manager/cheqd-did-provider.d.ts +12 -12
- package/build/esm/did-manager/cheqd-did-provider.d.ts.map +1 -1
- package/build/esm/did-manager/cheqd-did-provider.js +58 -43
- package/build/esm/did-manager/cheqd-did-provider.js.map +1 -1
- package/build/esm/did-manager/cheqd-did-resolver.d.ts.map +1 -1
- package/build/esm/did-manager/cheqd-did-resolver.js.map +1 -1
- package/build/esm/did-manager/index.d.ts.map +1 -1
- package/build/esm/did-manager/index.js.map +1 -1
- package/build/esm/did-manager/resolver.d.ts.map +1 -1
- package/build/esm/did-manager/resolver.js.map +1 -1
- package/build/esm/dkg-threshold/index.d.ts.map +1 -1
- package/build/esm/dkg-threshold/index.js.map +1 -1
- package/build/esm/dkg-threshold/lit-protocol.d.ts +3 -3
- package/build/esm/dkg-threshold/lit-protocol.d.ts.map +1 -1
- package/build/esm/dkg-threshold/lit-protocol.js +31 -20
- package/build/esm/dkg-threshold/lit-protocol.js.map +1 -1
- package/build/esm/index.d.ts.map +1 -1
- package/build/esm/index.js.map +1 -1
- package/build/esm/utils/env.d.ts.map +1 -1
- package/build/esm/utils/env.js +11 -2
- package/build/esm/utils/env.js.map +1 -1
- package/build/esm/utils/helpers.d.ts.map +1 -1
- package/build/esm/utils/helpers.js.map +1 -1
- package/build/esm/utils/index.d.ts.map +1 -1
- package/build/esm/utils/index.js.map +1 -1
- package/build/tsconfig.cjs.tsbuildinfo +1 -1
- package/build/tsconfig.esm.tsbuildinfo +1 -1
- package/build/tsconfig.types.tsbuildinfo +1 -1
- package/build/types/agent/ICheqd.d.ts +2 -2
- package/build/types/agent/ICheqd.d.ts.map +1 -1
- package/build/types/agent/index.d.ts.map +1 -1
- package/build/types/did-manager/cheqd-did-provider.d.ts +12 -12
- package/build/types/did-manager/cheqd-did-provider.d.ts.map +1 -1
- package/build/types/did-manager/cheqd-did-resolver.d.ts.map +1 -1
- package/build/types/did-manager/index.d.ts.map +1 -1
- package/build/types/did-manager/resolver.d.ts.map +1 -1
- package/build/types/dkg-threshold/index.d.ts.map +1 -1
- package/build/types/dkg-threshold/lit-protocol.d.ts +3 -3
- package/build/types/dkg-threshold/lit-protocol.d.ts.map +1 -1
- package/build/types/index.d.ts.map +1 -1
- package/build/types/utils/env.d.ts.map +1 -1
- package/build/types/utils/helpers.d.ts.map +1 -1
- package/build/types/utils/index.d.ts.map +1 -1
- package/package.json +6 -5
- package/src/agent/ICheqd.ts +6506 -4727
- package/src/agent/index.ts +1 -1
- package/src/did-manager/cheqd-did-provider.ts +364 -325
- package/src/did-manager/cheqd-did-resolver.ts +34 -40
- package/src/did-manager/index.ts +3 -3
- package/src/did-manager/resolver.ts +30 -32
- package/src/dkg-threshold/index.ts +1 -1
- package/src/dkg-threshold/lit-protocol.ts +272 -240
- package/src/global.d.ts +1 -1
- package/src/index.ts +5 -5
- package/src/utils/env.ts +18 -6
- package/src/utils/helpers.ts +33 -38
- package/src/utils/index.ts +2 -2
|
@@ -14,18 +14,13 @@ import {
|
|
|
14
14
|
DidStdFee,
|
|
15
15
|
ISignInputs,
|
|
16
16
|
IContext as ISDKContext,
|
|
17
|
-
CheqdNetwork
|
|
18
|
-
} from '@cheqd/sdk'
|
|
19
|
-
import { MsgCreateResourcePayload } from '@cheqd/ts-proto/cheqd/resource/v2/index.js'
|
|
20
|
-
import {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
DirectSecp256k1Wallet
|
|
25
|
-
} from '@cosmjs/proto-signing'
|
|
26
|
-
import { GasPrice, DeliverTxResponse } from '@cosmjs/stargate'
|
|
27
|
-
import { assert } from '@cosmjs/utils'
|
|
28
|
-
import { DIDDocument } from 'did-resolver'
|
|
17
|
+
CheqdNetwork,
|
|
18
|
+
} from '@cheqd/sdk';
|
|
19
|
+
import { MsgCreateResourcePayload } from '@cheqd/ts-proto/cheqd/resource/v2/index.js';
|
|
20
|
+
import { AccountData, Coin, DirectSecp256k1HdWallet, DirectSecp256k1Wallet } from '@cosmjs/proto-signing';
|
|
21
|
+
import { GasPrice, DeliverTxResponse } from '@cosmjs/stargate';
|
|
22
|
+
import { assert } from '@cosmjs/utils';
|
|
23
|
+
import { DIDDocument } from 'did-resolver';
|
|
29
24
|
import {
|
|
30
25
|
IIdentifier,
|
|
31
26
|
IKey,
|
|
@@ -35,89 +30,85 @@ import {
|
|
|
35
30
|
ManagedKeyInfo,
|
|
36
31
|
MinimalImportableKey,
|
|
37
32
|
TKeyType,
|
|
38
|
-
} from '@veramo/core'
|
|
39
|
-
import { AbstractIdentifierProvider } from '@veramo/did-manager'
|
|
40
|
-
import { base64ToBytes, extractPublicKeyHex } from '@veramo/utils'
|
|
41
|
-
import Debug from 'debug'
|
|
42
|
-
import {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
} from '
|
|
46
|
-
import {
|
|
47
|
-
fromString,
|
|
48
|
-
toString
|
|
49
|
-
} from 'uint8arrays'
|
|
50
|
-
import {
|
|
51
|
-
MsgCreateDidDocPayload,
|
|
52
|
-
MsgDeactivateDidDocPayload,
|
|
53
|
-
SignInfo
|
|
54
|
-
} from '@cheqd/ts-proto/cheqd/did/v2/index.js'
|
|
55
|
-
import { v4 } from 'uuid'
|
|
33
|
+
} from '@veramo/core';
|
|
34
|
+
import { AbstractIdentifierProvider } from '@veramo/did-manager';
|
|
35
|
+
import { base64ToBytes, extractPublicKeyHex } from '@veramo/utils';
|
|
36
|
+
import Debug from 'debug';
|
|
37
|
+
import { EnglishMnemonic as _, Ed25519 } from '@cosmjs/crypto';
|
|
38
|
+
import { fromString, toString } from 'uint8arrays';
|
|
39
|
+
import { MsgCreateDidDocPayload, MsgDeactivateDidDocPayload, SignInfo } from '@cheqd/ts-proto/cheqd/did/v2/index.js';
|
|
40
|
+
import { v4 } from 'uuid';
|
|
56
41
|
import {
|
|
57
42
|
LitCompatibleCosmosChain,
|
|
58
43
|
LitCompatibleCosmosChains,
|
|
59
44
|
LitNetwork,
|
|
60
|
-
LitNetworks
|
|
61
|
-
} from '../dkg-threshold/lit-protocol.js'
|
|
62
|
-
import { IContext } from '../agent/ICheqd.js'
|
|
45
|
+
LitNetworks,
|
|
46
|
+
} from '../dkg-threshold/lit-protocol.js';
|
|
47
|
+
import { IContext } from '../agent/ICheqd.js';
|
|
63
48
|
|
|
64
|
-
const debug = Debug('veramo:did-provider-cheqd')
|
|
49
|
+
const debug = Debug('veramo:did-provider-cheqd');
|
|
65
50
|
|
|
66
51
|
export const DefaultRPCUrls = {
|
|
67
52
|
[CheqdNetwork.Mainnet]: 'https://rpc.cheqd.net',
|
|
68
|
-
[CheqdNetwork.Testnet]: 'https://rpc.cheqd.network'
|
|
69
|
-
} as const
|
|
53
|
+
[CheqdNetwork.Testnet]: 'https://rpc.cheqd.network',
|
|
54
|
+
} as const;
|
|
70
55
|
|
|
71
56
|
export const DefaultRESTUrls = {
|
|
72
57
|
[CheqdNetwork.Mainnet]: 'https://api.cheqd.net',
|
|
73
|
-
[CheqdNetwork.Testnet]: 'https://api.cheqd.network'
|
|
74
|
-
} as const
|
|
58
|
+
[CheqdNetwork.Testnet]: 'https://api.cheqd.network',
|
|
59
|
+
} as const;
|
|
75
60
|
|
|
76
61
|
export const DefaultDkgSupportedChains = {
|
|
77
62
|
[CheqdNetwork.Mainnet]: LitCompatibleCosmosChains.cheqdMainnet,
|
|
78
|
-
[CheqdNetwork.Testnet]: LitCompatibleCosmosChains.cheqdTestnet
|
|
79
|
-
} as const
|
|
63
|
+
[CheqdNetwork.Testnet]: LitCompatibleCosmosChains.cheqdTestnet,
|
|
64
|
+
} as const;
|
|
80
65
|
|
|
81
66
|
export const DefaultStatusList2021StatusPurposeTypes = {
|
|
82
67
|
revocation: 'revocation',
|
|
83
|
-
suspension: 'suspension'
|
|
84
|
-
} as const
|
|
68
|
+
suspension: 'suspension',
|
|
69
|
+
} as const;
|
|
85
70
|
|
|
86
71
|
export const DefaultStatusList2021ResourceTypes = {
|
|
87
72
|
default: 'StatusList2021',
|
|
88
73
|
revocation: 'StatusList2021Revocation',
|
|
89
|
-
suspension: 'StatusList2021Suspension'
|
|
90
|
-
} as const
|
|
74
|
+
suspension: 'StatusList2021Suspension',
|
|
75
|
+
} as const;
|
|
91
76
|
|
|
92
77
|
export const DefaultStatusList2021Encodings = {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
} as const
|
|
78
|
+
base64: 'base64',
|
|
79
|
+
base64url: 'base64url',
|
|
80
|
+
hex: 'hex',
|
|
81
|
+
} as const;
|
|
97
82
|
|
|
98
|
-
export type DefaultRPCUrl = typeof DefaultRPCUrls[keyof typeof DefaultRPCUrls]
|
|
83
|
+
export type DefaultRPCUrl = (typeof DefaultRPCUrls)[keyof typeof DefaultRPCUrls];
|
|
99
84
|
|
|
100
|
-
export type DefaultRESTUrl = typeof DefaultRESTUrls[keyof typeof DefaultRESTUrls]
|
|
85
|
+
export type DefaultRESTUrl = (typeof DefaultRESTUrls)[keyof typeof DefaultRESTUrls];
|
|
101
86
|
|
|
102
|
-
export type DefaultStatusList2021ResourceType =
|
|
87
|
+
export type DefaultStatusList2021ResourceType =
|
|
88
|
+
(typeof DefaultStatusList2021ResourceTypes)[keyof typeof DefaultStatusList2021ResourceTypes];
|
|
103
89
|
|
|
104
|
-
export type DefaultStatusList2021StatusPurposeType =
|
|
90
|
+
export type DefaultStatusList2021StatusPurposeType =
|
|
91
|
+
(typeof DefaultStatusList2021StatusPurposeTypes)[keyof typeof DefaultStatusList2021StatusPurposeTypes];
|
|
105
92
|
|
|
106
|
-
export type DefaultStatusList2021Encoding =
|
|
93
|
+
export type DefaultStatusList2021Encoding =
|
|
94
|
+
(typeof DefaultStatusList2021Encodings)[keyof typeof DefaultStatusList2021Encodings];
|
|
107
95
|
|
|
108
|
-
export type LinkedResource = Omit<MsgCreateResourcePayload, 'data'> & { data?: string }
|
|
96
|
+
export type LinkedResource = Omit<MsgCreateResourcePayload, 'data'> & { data?: string };
|
|
109
97
|
|
|
110
|
-
export type ResourcePayload = Partial<MsgCreateResourcePayload
|
|
98
|
+
export type ResourcePayload = Partial<MsgCreateResourcePayload>;
|
|
111
99
|
|
|
112
|
-
export type StatusList2021ResourcePayload = ResourcePayload & { resourceType: DefaultStatusList2021ResourceType }
|
|
100
|
+
export type StatusList2021ResourcePayload = ResourcePayload & { resourceType: DefaultStatusList2021ResourceType };
|
|
113
101
|
|
|
114
|
-
export type TImportableEd25519Key = Required<Pick<IKey, 'publicKeyHex' | 'privateKeyHex'>> & {
|
|
102
|
+
export type TImportableEd25519Key = Required<Pick<IKey, 'publicKeyHex' | 'privateKeyHex'>> & {
|
|
103
|
+
kid: TImportableEd25519Key['publicKeyHex'];
|
|
104
|
+
type: 'Ed25519';
|
|
105
|
+
};
|
|
115
106
|
|
|
116
107
|
declare const TImportableEd25519Key: {
|
|
117
|
-
|
|
118
|
-
}
|
|
108
|
+
isTImportableEd25519Key(object: object[]): object is TImportableEd25519Key[];
|
|
109
|
+
};
|
|
119
110
|
|
|
120
|
-
export type TSupportedKeyType = 'Ed25519' | 'Secp256k1'
|
|
111
|
+
export type TSupportedKeyType = 'Ed25519' | 'Secp256k1';
|
|
121
112
|
|
|
122
113
|
export class EnglishMnemonic extends _ {
|
|
123
114
|
static readonly _mnemonicMatcher = /^[a-z]+( [a-z]+)*$/;
|
|
@@ -126,151 +117,178 @@ export class EnglishMnemonic extends _ {
|
|
|
126
117
|
/**
|
|
127
118
|
* {@link @veramo/did-manager#DIDManager} identifier provider for `did:cheqd` identifiers.
|
|
128
119
|
* @public
|
|
129
|
-
*/
|
|
120
|
+
*/
|
|
130
121
|
export class CheqdDIDProvider extends AbstractIdentifierProvider {
|
|
131
|
-
private defaultKms: string
|
|
132
|
-
public readonly network: CheqdNetwork
|
|
133
|
-
public readonly rpcUrl: string
|
|
134
|
-
private readonly cosmosPayerWallet: Promise<DirectSecp256k1HdWallet | DirectSecp256k1Wallet
|
|
135
|
-
public readonly dkgOptions: {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
122
|
+
private defaultKms: string;
|
|
123
|
+
public readonly network: CheqdNetwork;
|
|
124
|
+
public readonly rpcUrl: string;
|
|
125
|
+
private readonly cosmosPayerWallet: Promise<DirectSecp256k1HdWallet | DirectSecp256k1Wallet>;
|
|
126
|
+
public readonly dkgOptions: {
|
|
127
|
+
chain: Extract<LitCompatibleCosmosChain, 'cheqdTestnet' | 'cheqdMainnet'>;
|
|
128
|
+
network: LitNetwork;
|
|
129
|
+
};
|
|
130
|
+
private sdk?: CheqdSDK;
|
|
131
|
+
private fee?: DidStdFee;
|
|
132
|
+
|
|
133
|
+
static readonly defaultGasPrice = GasPrice.fromString('50ncheq');
|
|
134
|
+
|
|
135
|
+
constructor(options: {
|
|
136
|
+
defaultKms: string;
|
|
137
|
+
cosmosPayerSeed: string;
|
|
138
|
+
networkType?: CheqdNetwork;
|
|
139
|
+
rpcUrl?: string;
|
|
140
|
+
dkgOptions?: {
|
|
141
|
+
chain?: Extract<LitCompatibleCosmosChain, 'cheqdTestnet' | 'cheqdMainnet'>;
|
|
142
|
+
network?: LitNetwork;
|
|
143
|
+
};
|
|
144
|
+
}) {
|
|
145
|
+
super();
|
|
146
|
+
this.defaultKms = options.defaultKms;
|
|
147
|
+
this.network = options.networkType ? options.networkType : CheqdNetwork.Testnet;
|
|
148
|
+
this.rpcUrl = options.rpcUrl ? options.rpcUrl : DefaultRPCUrls[this.network];
|
|
146
149
|
this.dkgOptions = options.dkgOptions
|
|
147
|
-
? {
|
|
148
|
-
|
|
150
|
+
? {
|
|
151
|
+
chain: options.dkgOptions.chain
|
|
152
|
+
? options.dkgOptions.chain
|
|
153
|
+
: DefaultDkgSupportedChains[this.network],
|
|
154
|
+
network: options.dkgOptions.network ? options.dkgOptions.network : LitNetworks.serrano,
|
|
155
|
+
}
|
|
156
|
+
: { chain: DefaultDkgSupportedChains[this.network], network: LitNetworks.serrano };
|
|
149
157
|
|
|
150
158
|
if (!options?.cosmosPayerSeed || options.cosmosPayerSeed === '') {
|
|
151
|
-
this.cosmosPayerWallet = DirectSecp256k1HdWallet.generate()
|
|
152
|
-
return
|
|
159
|
+
this.cosmosPayerWallet = DirectSecp256k1HdWallet.generate();
|
|
160
|
+
return;
|
|
153
161
|
}
|
|
154
162
|
this.cosmosPayerWallet = EnglishMnemonic._mnemonicMatcher.test(options.cosmosPayerSeed)
|
|
155
163
|
? DirectSecp256k1HdWallet.fromMnemonic(options.cosmosPayerSeed, { prefix: 'cheqd' })
|
|
156
|
-
: DirectSecp256k1Wallet.fromKey(
|
|
157
|
-
fromString(
|
|
158
|
-
options.cosmosPayerSeed.replace(/^0x/, ''),
|
|
159
|
-
'hex'
|
|
160
|
-
),
|
|
161
|
-
'cheqd'
|
|
162
|
-
)
|
|
164
|
+
: DirectSecp256k1Wallet.fromKey(fromString(options.cosmosPayerSeed.replace(/^0x/, ''), 'hex'), 'cheqd');
|
|
163
165
|
}
|
|
164
166
|
|
|
165
167
|
async getWalletAccounts(): Promise<readonly AccountData[]> {
|
|
166
|
-
return await (await this.cosmosPayerWallet).getAccounts()
|
|
168
|
+
return await (await this.cosmosPayerWallet).getAccounts();
|
|
167
169
|
}
|
|
168
170
|
|
|
169
171
|
private async getCheqdSDK(fee?: DidStdFee, gasPrice?: GasPrice): Promise<CheqdSDK> {
|
|
170
172
|
if (!this.sdk) {
|
|
171
173
|
const wallet = await this.cosmosPayerWallet.catch(() => {
|
|
172
|
-
throw new Error(`[did-provider-cheqd]: network: ${this.network} valid cosmosPayerSeed is required`)
|
|
173
|
-
})
|
|
174
|
+
throw new Error(`[did-provider-cheqd]: network: ${this.network} valid cosmosPayerSeed is required`);
|
|
175
|
+
});
|
|
174
176
|
const sdkOptions: ICheqdSDKOptions = {
|
|
175
|
-
modules: [
|
|
177
|
+
modules: [
|
|
178
|
+
DIDModule as unknown as AbstractCheqdSDKModule,
|
|
179
|
+
ResourceModule as unknown as AbstractCheqdSDKModule,
|
|
180
|
+
],
|
|
176
181
|
rpcUrl: this.rpcUrl,
|
|
177
182
|
wallet: wallet,
|
|
178
|
-
gasPrice
|
|
179
|
-
}
|
|
183
|
+
gasPrice,
|
|
184
|
+
};
|
|
180
185
|
|
|
181
|
-
this.sdk = await createCheqdSDK(sdkOptions)
|
|
182
|
-
this.fee = fee
|
|
186
|
+
this.sdk = await createCheqdSDK(sdkOptions);
|
|
187
|
+
this.fee = fee;
|
|
183
188
|
|
|
184
189
|
if (this?.fee && !this?.fee?.payer) {
|
|
185
|
-
const feePayer = (await (await this.cosmosPayerWallet).getAccounts())[0].address
|
|
186
|
-
this.fee.payer = feePayer
|
|
190
|
+
const feePayer = (await (await this.cosmosPayerWallet).getAccounts())[0].address;
|
|
191
|
+
this.fee.payer = feePayer;
|
|
187
192
|
}
|
|
188
193
|
}
|
|
189
|
-
return this.sdk
|
|
194
|
+
return this.sdk!;
|
|
190
195
|
}
|
|
191
196
|
|
|
192
197
|
async createIdentifier(
|
|
193
|
-
{
|
|
194
|
-
|
|
198
|
+
{
|
|
199
|
+
kms,
|
|
200
|
+
options,
|
|
201
|
+
}: {
|
|
202
|
+
kms?: string;
|
|
203
|
+
alias?: string;
|
|
204
|
+
options: { document: DIDDocument; keys?: TImportableEd25519Key[]; versionId?: string; fee?: DidStdFee };
|
|
205
|
+
},
|
|
206
|
+
context: IContext
|
|
195
207
|
): Promise<Omit<IIdentifier, 'provider'>> {
|
|
196
|
-
const sdk = await this.getCheqdSDK(options?.fee)
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
? function () {
|
|
200
|
-
|
|
201
|
-
|
|
208
|
+
const sdk = await this.getCheqdSDK(options?.fee);
|
|
209
|
+
const versionId = options.versionId || v4();
|
|
210
|
+
const signInputs: ISignInputs[] | SignInfo[] = options.keys
|
|
211
|
+
? (function () {
|
|
212
|
+
return options.keys.map((key) =>
|
|
213
|
+
createSignInputsFromImportableEd25519Key(key, options.document.verificationMethod || [])
|
|
214
|
+
);
|
|
215
|
+
})()
|
|
202
216
|
: await (async function (that: CheqdDIDProvider) {
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
217
|
+
const data = await createMsgCreateDidDocPayloadToSign(options.document, versionId);
|
|
218
|
+
return await that.signPayload(context, data, options.document.verificationMethod);
|
|
219
|
+
})(this);
|
|
206
220
|
|
|
207
|
-
const tx = await sdk.createDidDocTx(
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
'',
|
|
211
|
-
this?.fee,
|
|
212
|
-
undefined,
|
|
213
|
-
versionId,
|
|
214
|
-
{ sdk: sdk } satisfies ISDKContext,
|
|
215
|
-
)
|
|
221
|
+
const tx = await sdk.createDidDocTx(signInputs, options.document, '', this?.fee, undefined, versionId, {
|
|
222
|
+
sdk: sdk,
|
|
223
|
+
} satisfies ISDKContext);
|
|
216
224
|
|
|
217
|
-
assert(tx.code === 0, `cosmos_transaction: Failed to create DID. Reason: ${tx.rawLog}`)
|
|
225
|
+
assert(tx.code === 0, `cosmos_transaction: Failed to create DID. Reason: ${tx.rawLog}`);
|
|
218
226
|
|
|
219
227
|
//* Currently, only one controller key is supported.
|
|
220
228
|
//* We assume that the first key in the list is the controller key.
|
|
221
229
|
//* This is subject to change in the near future.
|
|
222
|
-
|
|
230
|
+
const keys: ManagedKeyInfo[] = options.keys
|
|
223
231
|
? await (async function (that: CheqdDIDProvider) {
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
232
|
+
const scopedKeys: ManagedKeyInfo[] = [];
|
|
233
|
+
for (const key of options.keys!) {
|
|
234
|
+
let managedKey: ManagedKeyInfo | undefined;
|
|
235
|
+
try {
|
|
236
|
+
managedKey = await context.agent.keyManagerImport({
|
|
237
|
+
...key,
|
|
238
|
+
kms: kms || that.defaultKms,
|
|
239
|
+
} satisfies MinimalImportableKey);
|
|
240
|
+
} catch (e) {
|
|
241
|
+
debug(`Failed to import key ${key.kid}. Reason: ${e}`);
|
|
242
|
+
|
|
243
|
+
// construct key, if it failed to import
|
|
244
|
+
managedKey = { ...key, kms: kms || that.defaultKms };
|
|
245
|
+
}
|
|
246
|
+
if (managedKey) {
|
|
247
|
+
scopedKeys.push(managedKey);
|
|
248
|
+
}
|
|
240
249
|
}
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
: await this.getKeysFromVerificationMethod(context, options.document.verificationMethod)
|
|
250
|
+
return scopedKeys;
|
|
251
|
+
})(this)
|
|
252
|
+
: await this.getKeysFromVerificationMethod(context, options.document.verificationMethod);
|
|
245
253
|
|
|
246
|
-
|
|
254
|
+
const controllerKey: IKey = keys[0];
|
|
247
255
|
const identifier: IIdentifier = {
|
|
248
256
|
did: <string>options.document.id,
|
|
249
257
|
controllerKeyId: controllerKey.kid,
|
|
250
258
|
keys,
|
|
251
259
|
services: options.document.service || [],
|
|
252
260
|
provider: options.document.id.split(':').splice(0, 3).join(':'),
|
|
253
|
-
}
|
|
261
|
+
};
|
|
254
262
|
|
|
255
|
-
debug('Created DID', identifier.did)
|
|
263
|
+
debug('Created DID', identifier.did);
|
|
256
264
|
|
|
257
|
-
return identifier
|
|
265
|
+
return identifier;
|
|
258
266
|
}
|
|
259
267
|
|
|
260
268
|
async updateIdentifier(
|
|
261
|
-
{
|
|
262
|
-
|
|
269
|
+
{
|
|
270
|
+
did,
|
|
271
|
+
document,
|
|
272
|
+
options,
|
|
273
|
+
}: {
|
|
274
|
+
did: string;
|
|
275
|
+
document: DIDDocument;
|
|
276
|
+
options: { kms: string; keys?: TImportableEd25519Key[]; versionId?: string; fee?: DidStdFee };
|
|
277
|
+
},
|
|
278
|
+
context: IContext
|
|
263
279
|
): Promise<IIdentifier> {
|
|
264
|
-
const sdk = await this.getCheqdSDK(options?.fee)
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
? function (){
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
280
|
+
const sdk = await this.getCheqdSDK(options?.fee);
|
|
281
|
+
const versionId = options.versionId || v4();
|
|
282
|
+
const signInputs: ISignInputs[] | SignInfo[] = options.keys
|
|
283
|
+
? (function () {
|
|
284
|
+
return options.keys.map((key) =>
|
|
285
|
+
createSignInputsFromImportableEd25519Key(key, document.verificationMethod || [])
|
|
286
|
+
);
|
|
287
|
+
})()
|
|
288
|
+
: await (async function (that: CheqdDIDProvider) {
|
|
289
|
+
const data = await createMsgCreateDidDocPayloadToSign(document, versionId);
|
|
290
|
+
return await that.signPayload(context, data, document.verificationMethod);
|
|
291
|
+
})(this);
|
|
274
292
|
|
|
275
293
|
const tx = await sdk.updateDidDocTx(
|
|
276
294
|
signInputs,
|
|
@@ -279,40 +297,40 @@ export class CheqdDIDProvider extends AbstractIdentifierProvider {
|
|
|
279
297
|
this?.fee,
|
|
280
298
|
undefined,
|
|
281
299
|
versionId,
|
|
282
|
-
{ sdk: sdk } satisfies ISDKContext
|
|
283
|
-
)
|
|
300
|
+
{ sdk: sdk } satisfies ISDKContext
|
|
301
|
+
);
|
|
284
302
|
|
|
285
|
-
assert(tx.code === 0, `cosmos_transaction: Failed to update DID. Reason: ${tx.rawLog}`)
|
|
303
|
+
assert(tx.code === 0, `cosmos_transaction: Failed to update DID. Reason: ${tx.rawLog}`);
|
|
286
304
|
|
|
287
305
|
//* Currently, only one controller key is supported.
|
|
288
306
|
//* We assume that the first key in the list is the controller key.
|
|
289
307
|
//* This is subject to change in the near future.
|
|
290
|
-
|
|
308
|
+
const keys: ManagedKeyInfo[] = options.keys
|
|
291
309
|
? await (async function (that: CheqdDIDProvider) {
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
310
|
+
const scopedKeys: ManagedKeyInfo[] = [];
|
|
311
|
+
for (const key of options.keys!) {
|
|
312
|
+
let managedKey: ManagedKeyInfo | undefined;
|
|
313
|
+
try {
|
|
314
|
+
managedKey = await context.agent.keyManagerImport({
|
|
315
|
+
...key,
|
|
316
|
+
kms: options.kms || that.defaultKms,
|
|
317
|
+
} satisfies MinimalImportableKey);
|
|
318
|
+
} catch (e) {
|
|
319
|
+
debug(`Failed to import key ${key.kid}. Reason: ${e}`);
|
|
320
|
+
|
|
321
|
+
// construct key, if it failed to import
|
|
322
|
+
managedKey = { ...key, kms: options.kms || that.defaultKms };
|
|
323
|
+
}
|
|
324
|
+
if (managedKey) {
|
|
325
|
+
scopedKeys.push(managedKey);
|
|
326
|
+
}
|
|
308
327
|
}
|
|
309
|
-
}
|
|
310
328
|
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
: await this.getKeysFromVerificationMethod(context, document.verificationMethod)
|
|
329
|
+
return scopedKeys;
|
|
330
|
+
})(this)
|
|
331
|
+
: await this.getKeysFromVerificationMethod(context, document.verificationMethod);
|
|
314
332
|
|
|
315
|
-
const controllerKey = keys[0]
|
|
333
|
+
const controllerKey = keys[0];
|
|
316
334
|
|
|
317
335
|
const identifier: IIdentifier = {
|
|
318
336
|
did: <string>document.id,
|
|
@@ -320,27 +338,37 @@ export class CheqdDIDProvider extends AbstractIdentifierProvider {
|
|
|
320
338
|
keys,
|
|
321
339
|
services: document.service || [],
|
|
322
340
|
provider: document.id.split(':').splice(0, 3).join(':'),
|
|
323
|
-
}
|
|
341
|
+
};
|
|
324
342
|
|
|
325
|
-
debug('Updated DID', did)
|
|
343
|
+
debug('Updated DID', did);
|
|
326
344
|
|
|
327
|
-
return identifier
|
|
345
|
+
return identifier;
|
|
328
346
|
}
|
|
329
347
|
|
|
330
348
|
async deactivateIdentifier(
|
|
331
|
-
{
|
|
332
|
-
|
|
349
|
+
{
|
|
350
|
+
did,
|
|
351
|
+
document,
|
|
352
|
+
options,
|
|
353
|
+
}: {
|
|
354
|
+
did: string;
|
|
355
|
+
document: DIDDocument;
|
|
356
|
+
options: { keys?: TImportableEd25519Key[]; fee?: DidStdFee; versionId?: string };
|
|
357
|
+
},
|
|
358
|
+
context: IContext
|
|
333
359
|
): Promise<boolean> {
|
|
334
|
-
const sdk = await this.getCheqdSDK(options?.fee)
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
? function (){
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
360
|
+
const sdk = await this.getCheqdSDK(options?.fee);
|
|
361
|
+
const versionId = options.versionId || v4();
|
|
362
|
+
const signInputs: ISignInputs[] | SignInfo[] = options.keys
|
|
363
|
+
? (function () {
|
|
364
|
+
return options.keys.map((key) =>
|
|
365
|
+
createSignInputsFromImportableEd25519Key(key, document.verificationMethod || [])
|
|
366
|
+
);
|
|
367
|
+
})()
|
|
368
|
+
: await (async function (that: CheqdDIDProvider) {
|
|
369
|
+
const data = await createMsgDeactivateDidDocPayloadToSign(document, versionId);
|
|
370
|
+
return await that.signPayload(context, data, document.verificationMethod);
|
|
371
|
+
})(this);
|
|
344
372
|
|
|
345
373
|
const tx = await sdk.deactivateDidDocTx(
|
|
346
374
|
signInputs,
|
|
@@ -349,155 +377,151 @@ export class CheqdDIDProvider extends AbstractIdentifierProvider {
|
|
|
349
377
|
this?.fee,
|
|
350
378
|
undefined,
|
|
351
379
|
versionId,
|
|
352
|
-
{ sdk: sdk } satisfies ISDKContext
|
|
353
|
-
)
|
|
380
|
+
{ sdk: sdk } satisfies ISDKContext
|
|
381
|
+
);
|
|
354
382
|
|
|
355
|
-
assert(tx.code === 0, `cosmos_transaction: Failed to update DID. Reason: ${tx.rawLog}`)
|
|
383
|
+
assert(tx.code === 0, `cosmos_transaction: Failed to update DID. Reason: ${tx.rawLog}`);
|
|
356
384
|
|
|
357
|
-
debug('Deactivated DID', did)
|
|
385
|
+
debug('Deactivated DID', did);
|
|
358
386
|
|
|
359
|
-
return true
|
|
387
|
+
return true;
|
|
360
388
|
}
|
|
361
389
|
|
|
362
390
|
async createResource(
|
|
363
|
-
{
|
|
364
|
-
|
|
391
|
+
{
|
|
392
|
+
options,
|
|
393
|
+
}: { options: { payload: ResourcePayload; signInputs?: ISignInputs[]; kms?: string; fee?: DidStdFee } },
|
|
394
|
+
context: IContext
|
|
365
395
|
): Promise<boolean> {
|
|
366
|
-
const sdk = await this.getCheqdSDK(options?.fee)
|
|
396
|
+
const sdk = await this.getCheqdSDK(options?.fee);
|
|
367
397
|
|
|
368
|
-
|
|
398
|
+
const signInputs: ISignInputs[] | SignInfo[] = options.signInputs
|
|
369
399
|
? options.signInputs
|
|
370
|
-
: await (async function (that: CheqdDIDProvider){
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
didDocument?.verificationMethod
|
|
381
|
-
)
|
|
382
|
-
}(this))
|
|
383
|
-
|
|
384
|
-
const tx = await sdk.createLinkedResourceTx(
|
|
385
|
-
signInputs,
|
|
386
|
-
options.payload,
|
|
387
|
-
'',
|
|
388
|
-
this?.fee,
|
|
389
|
-
undefined,
|
|
390
|
-
{ sdk: sdk }
|
|
391
|
-
)
|
|
400
|
+
: await (async function (that: CheqdDIDProvider) {
|
|
401
|
+
const did = `did:cheqd:${that.network}:${options.payload.collectionId}`;
|
|
402
|
+
const { didDocument } = await sdk.queryDidDoc(did, { sdk: sdk });
|
|
403
|
+
|
|
404
|
+
return await that.signPayload(
|
|
405
|
+
context,
|
|
406
|
+
MsgCreateResourcePayload.encode(MsgCreateResourcePayload.fromPartial(options.payload)).finish(),
|
|
407
|
+
didDocument?.verificationMethod
|
|
408
|
+
);
|
|
409
|
+
})(this);
|
|
392
410
|
|
|
393
|
-
|
|
411
|
+
const tx = await sdk.createLinkedResourceTx(signInputs, options.payload, '', this?.fee, undefined, {
|
|
412
|
+
sdk: sdk,
|
|
413
|
+
});
|
|
394
414
|
|
|
395
|
-
|
|
415
|
+
assert(tx.code === 0, `cosmos_transaction: Failed to create Resource. Reason: ${tx.rawLog}`);
|
|
416
|
+
|
|
417
|
+
const mapKeyType = (keyType: 'Ed25519' | 'Secp256k1' | 'P256' | undefined): TKeyType | undefined => {
|
|
396
418
|
switch (keyType) {
|
|
397
|
-
case
|
|
398
|
-
|
|
399
|
-
|
|
419
|
+
case 'Ed25519':
|
|
420
|
+
return 'Ed25519';
|
|
421
|
+
case 'Secp256k1':
|
|
422
|
+
return 'Secp256k1';
|
|
423
|
+
default:
|
|
424
|
+
return undefined;
|
|
425
|
+
}
|
|
426
|
+
};
|
|
427
|
+
|
|
428
|
+
if (options.signInputs) {
|
|
429
|
+
const signInput = options.signInputs.filter((input) => mapKeyType(input.keyType) !== undefined);
|
|
430
|
+
|
|
431
|
+
const keys: ManagedKeyInfo[] = [];
|
|
432
|
+
for (const input of signInput) {
|
|
433
|
+
let managedKey: ManagedKeyInfo | undefined;
|
|
434
|
+
try {
|
|
435
|
+
// get public key from private key in hex
|
|
436
|
+
const publicKey = toString(
|
|
437
|
+
(await Ed25519.makeKeypair(fromString(input.privateKeyHex, 'hex'))).pubkey,
|
|
438
|
+
'hex'
|
|
439
|
+
);
|
|
440
|
+
managedKey = await context.agent.keyManagerImport({
|
|
441
|
+
kid: publicKey,
|
|
442
|
+
publicKeyHex: publicKey,
|
|
443
|
+
privateKeyHex: input.privateKeyHex,
|
|
444
|
+
type: mapKeyType(input.keyType) as TSupportedKeyType,
|
|
445
|
+
kms: options.kms || this.defaultKms,
|
|
446
|
+
} satisfies MinimalImportableKey);
|
|
447
|
+
} catch (e) {
|
|
448
|
+
debug(`Failed to import key ${input.verificationMethodId}. Reason: ${e}`);
|
|
449
|
+
}
|
|
450
|
+
if (managedKey) {
|
|
451
|
+
keys.push(managedKey);
|
|
452
|
+
}
|
|
400
453
|
}
|
|
401
454
|
}
|
|
402
455
|
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
const keys: ManagedKeyInfo[] = []
|
|
407
|
-
for (const input of signInput) {
|
|
408
|
-
let managedKey: ManagedKeyInfo | undefined
|
|
409
|
-
try {
|
|
410
|
-
// get public key from private key in hex
|
|
411
|
-
const publicKey = toString((await Ed25519.makeKeypair(fromString(input.privateKeyHex, 'hex'))).pubkey, 'hex')
|
|
412
|
-
managedKey = await context.agent.keyManagerImport({
|
|
413
|
-
kid: publicKey,
|
|
414
|
-
publicKeyHex: publicKey,
|
|
415
|
-
privateKeyHex: input.privateKeyHex,
|
|
416
|
-
type: mapKeyType(input.keyType) as TSupportedKeyType,
|
|
417
|
-
kms: options.kms || this.defaultKms,
|
|
418
|
-
} satisfies MinimalImportableKey)
|
|
419
|
-
} catch (e) {
|
|
420
|
-
debug(`Failed to import key ${input.verificationMethodId}. Reason: ${e}`)
|
|
421
|
-
}
|
|
422
|
-
if (managedKey) {
|
|
423
|
-
keys.push(managedKey)
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
debug('Created Resource', options.payload)
|
|
429
|
-
|
|
430
|
-
return true
|
|
456
|
+
debug('Created Resource', options.payload);
|
|
457
|
+
|
|
458
|
+
return true;
|
|
431
459
|
}
|
|
432
460
|
|
|
433
|
-
async deleteIdentifier(
|
|
434
|
-
identity: IIdentifier,
|
|
435
|
-
context: IContext,
|
|
436
|
-
): Promise<boolean> {
|
|
461
|
+
async deleteIdentifier(identity: IIdentifier, context: IContext): Promise<boolean> {
|
|
437
462
|
for (const { kid } of identity.keys) {
|
|
438
|
-
await context.agent.keyManagerDelete({ kid })
|
|
463
|
+
await context.agent.keyManagerDelete({ kid });
|
|
439
464
|
}
|
|
440
|
-
return true
|
|
465
|
+
return true;
|
|
441
466
|
}
|
|
442
467
|
|
|
443
468
|
async addKey(
|
|
444
|
-
{
|
|
445
|
-
|
|
446
|
-
key,
|
|
447
|
-
options,
|
|
448
|
-
}: { identifier: IIdentifier; key: IKey; options?: any },
|
|
449
|
-
context: IContext,
|
|
469
|
+
{ identifier, key, options }: { identifier: IIdentifier; key: IKey; options?: any },
|
|
470
|
+
context: IContext
|
|
450
471
|
): Promise<any> {
|
|
451
|
-
throw Error('CheqdDIDProvider addKey is not supported.')
|
|
472
|
+
throw Error('CheqdDIDProvider addKey is not supported.');
|
|
452
473
|
}
|
|
453
474
|
|
|
454
475
|
async addService(
|
|
455
|
-
{
|
|
456
|
-
|
|
457
|
-
service,
|
|
458
|
-
options,
|
|
459
|
-
}: { identifier: IIdentifier; service: IService; options?: any },
|
|
460
|
-
context: IContext,
|
|
476
|
+
{ identifier, service, options }: { identifier: IIdentifier; service: IService; options?: any },
|
|
477
|
+
context: IContext
|
|
461
478
|
): Promise<any> {
|
|
462
|
-
throw Error('CheqdDIDProvider addService is not supported.')
|
|
479
|
+
throw Error('CheqdDIDProvider addService is not supported.');
|
|
463
480
|
}
|
|
464
481
|
|
|
465
482
|
async removeKey(
|
|
466
483
|
args: {
|
|
467
484
|
identifier: IIdentifier;
|
|
468
485
|
kid: string;
|
|
469
|
-
options?: any
|
|
486
|
+
options?: any;
|
|
470
487
|
},
|
|
471
|
-
context: IContext
|
|
488
|
+
context: IContext
|
|
472
489
|
): Promise<any> {
|
|
473
|
-
throw Error('CheqdDIDProvider removeKey is not supported.')
|
|
490
|
+
throw Error('CheqdDIDProvider removeKey is not supported.');
|
|
474
491
|
}
|
|
475
492
|
|
|
476
493
|
async removeService(
|
|
477
494
|
args: {
|
|
478
495
|
identifier: IIdentifier;
|
|
479
496
|
id: string;
|
|
480
|
-
options?: any
|
|
497
|
+
options?: any;
|
|
481
498
|
},
|
|
482
|
-
context: IContext
|
|
499
|
+
context: IContext
|
|
483
500
|
): Promise<any> {
|
|
484
|
-
throw Error('CheqdDIDProvider removeService is not supported.')
|
|
501
|
+
throw Error('CheqdDIDProvider removeService is not supported.');
|
|
485
502
|
}
|
|
486
503
|
|
|
487
|
-
async transactSendTokens(args: {
|
|
488
|
-
|
|
504
|
+
async transactSendTokens(args: {
|
|
505
|
+
recipientAddress: string;
|
|
506
|
+
amount: Coin;
|
|
507
|
+
memo?: string;
|
|
508
|
+
txBytes?: Uint8Array;
|
|
509
|
+
timeoutMs?: number;
|
|
510
|
+
pollIntervalMs?: number;
|
|
511
|
+
}): Promise<DeliverTxResponse> {
|
|
512
|
+
const sdk = await this.getCheqdSDK(undefined, CheqdDIDProvider.defaultGasPrice);
|
|
489
513
|
|
|
490
514
|
if (args?.txBytes) {
|
|
491
515
|
// broadcast txBytes
|
|
492
|
-
const tx = await sdk.signer.broadcastTx(args.txBytes, args?.timeoutMs, args?.pollIntervalMs)
|
|
516
|
+
const tx = await sdk.signer.broadcastTx(args.txBytes, args?.timeoutMs, args?.pollIntervalMs);
|
|
493
517
|
|
|
494
518
|
// assert tx code is 0, in other words, tx succeeded
|
|
495
|
-
assert(tx.code === 0, `cosmos_transaction: Failed to send tokens. Reason: ${tx.rawLog}`)
|
|
519
|
+
assert(tx.code === 0, `cosmos_transaction: Failed to send tokens. Reason: ${tx.rawLog}`);
|
|
496
520
|
|
|
497
521
|
// keep log
|
|
498
|
-
debug('Sent tokens', 'txBytes', toString(args.txBytes, 'hex'))
|
|
522
|
+
debug('Sent tokens', 'txBytes', toString(args.txBytes, 'hex'));
|
|
499
523
|
|
|
500
|
-
return tx
|
|
524
|
+
return tx;
|
|
501
525
|
}
|
|
502
526
|
|
|
503
527
|
const tx = await sdk.signer.sendTokens(
|
|
@@ -505,46 +529,58 @@ export class CheqdDIDProvider extends AbstractIdentifierProvider {
|
|
|
505
529
|
args.recipientAddress,
|
|
506
530
|
[args.amount],
|
|
507
531
|
'auto',
|
|
508
|
-
args.memo
|
|
509
|
-
)
|
|
532
|
+
args.memo
|
|
533
|
+
);
|
|
510
534
|
|
|
511
|
-
assert(tx.code === 0, `cosmos_transaction: Failed to send tokens. Reason: ${tx.rawLog}`)
|
|
535
|
+
assert(tx.code === 0, `cosmos_transaction: Failed to send tokens. Reason: ${tx.rawLog}`);
|
|
512
536
|
|
|
513
|
-
debug('Sent tokens', args.amount.amount, args.amount.denom, 'to', args.recipientAddress)
|
|
537
|
+
debug('Sent tokens', args.amount.amount, args.amount.denom, 'to', args.recipientAddress);
|
|
514
538
|
|
|
515
|
-
return tx
|
|
539
|
+
return tx;
|
|
516
540
|
}
|
|
517
541
|
|
|
518
|
-
|
|
519
|
-
|
|
542
|
+
private async signPayload(
|
|
543
|
+
context: IAgentContext<IKeyManager>,
|
|
544
|
+
data: Uint8Array,
|
|
545
|
+
verificationMethod: VerificationMethod[] = []
|
|
546
|
+
): Promise<SignInfo[]> {
|
|
547
|
+
return Promise.all(
|
|
520
548
|
verificationMethod.map(async (method) => {
|
|
521
|
-
const keyRef = extractPublicKeyHex(method)
|
|
549
|
+
const keyRef = extractPublicKeyHex(method);
|
|
522
550
|
return {
|
|
523
551
|
verificationMethodId: method.id,
|
|
524
|
-
signature: base64ToBytes(
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
552
|
+
signature: base64ToBytes(
|
|
553
|
+
await context.agent.keyManagerSign({
|
|
554
|
+
keyRef,
|
|
555
|
+
data: toString(data, 'hex'),
|
|
556
|
+
encoding: 'hex',
|
|
557
|
+
})
|
|
558
|
+
),
|
|
559
|
+
} satisfies SignInfo;
|
|
530
560
|
})
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
561
|
+
);
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
private async getKeysFromVerificationMethod(
|
|
565
|
+
context: IAgentContext<IKeyManager>,
|
|
566
|
+
verificationMethod: VerificationMethod[] = []
|
|
567
|
+
): Promise<ManagedKeyInfo[]> {
|
|
568
|
+
return Promise.all(
|
|
569
|
+
verificationMethod.map(async (method) => {
|
|
570
|
+
const kid = extractPublicKeyHex(method);
|
|
571
|
+
return await context.agent.keyManagerGet({ kid });
|
|
539
572
|
})
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
573
|
+
).catch((error) => {
|
|
574
|
+
throw new Error(`Failed to sign payload: ${error}`);
|
|
575
|
+
});
|
|
576
|
+
}
|
|
544
577
|
}
|
|
545
578
|
|
|
546
|
-
export async function createMsgCreateDidDocPayloadToSign(
|
|
547
|
-
|
|
579
|
+
export async function createMsgCreateDidDocPayloadToSign(
|
|
580
|
+
didPayload: DIDDocument,
|
|
581
|
+
versionId: string
|
|
582
|
+
): Promise<Uint8Array> {
|
|
583
|
+
const { protobufVerificationMethod, protobufService } = await DIDModule.validateSpecCompliantPayload(didPayload);
|
|
548
584
|
return MsgCreateDidDocPayload.encode(
|
|
549
585
|
MsgCreateDidDocPayload.fromPartial({
|
|
550
586
|
context: <string[]>didPayload?.['@context'],
|
|
@@ -560,14 +596,17 @@ export async function createMsgCreateDidDocPayloadToSign(didPayload: DIDDocument
|
|
|
560
596
|
alsoKnownAs: <string[]>didPayload.alsoKnownAs,
|
|
561
597
|
versionId,
|
|
562
598
|
})
|
|
563
|
-
).finish()
|
|
599
|
+
).finish();
|
|
564
600
|
}
|
|
565
601
|
|
|
566
|
-
export async function createMsgDeactivateDidDocPayloadToSign(
|
|
602
|
+
export async function createMsgDeactivateDidDocPayloadToSign(
|
|
603
|
+
didPayload: DIDDocument,
|
|
604
|
+
versionId?: string
|
|
605
|
+
): Promise<Uint8Array> {
|
|
567
606
|
return MsgDeactivateDidDocPayload.encode(
|
|
568
|
-
|
|
607
|
+
MsgDeactivateDidDocPayload.fromPartial({
|
|
569
608
|
id: didPayload.id,
|
|
570
609
|
versionId,
|
|
571
610
|
})
|
|
572
|
-
).finish()
|
|
573
|
-
}
|
|
611
|
+
).finish();
|
|
612
|
+
}
|