@hashgraph/hedera-wallet-connect 1.3.1 → 1.3.2-1
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +11 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +20 -0
- package/dist/{types/src → src}/lib/dapp/DAppSigner.d.ts +0 -1
- package/dist/src/lib/dapp/DAppSigner.js +214 -0
- package/dist/{types/src → src}/lib/dapp/index.d.ts +0 -1
- package/dist/src/lib/dapp/index.js +431 -0
- package/dist/{types/src → src}/lib/index.d.ts +0 -1
- package/dist/src/lib/index.js +22 -0
- package/dist/{types/src → src}/lib/shared/chainIds.d.ts +0 -1
- package/dist/src/lib/shared/chainIds.js +31 -0
- package/dist/{types/src → src}/lib/shared/errors.d.ts +0 -1
- package/dist/src/lib/shared/errors.js +51 -0
- package/dist/{types/src → src}/lib/shared/events.d.ts +0 -1
- package/dist/src/lib/shared/events.js +27 -0
- package/dist/{types/src → src}/lib/shared/extensionController.d.ts +0 -1
- package/dist/src/lib/shared/extensionController.js +42 -0
- package/dist/{types/src → src}/lib/shared/index.d.ts +0 -1
- package/dist/src/lib/shared/index.js +26 -0
- package/dist/{types/src → src}/lib/shared/methods.d.ts +0 -1
- package/dist/src/lib/shared/methods.js +32 -0
- package/dist/{types/src → src}/lib/shared/payloads.d.ts +0 -1
- package/dist/src/lib/shared/payloads.js +20 -0
- package/dist/{types/src → src}/lib/shared/utils.d.ts +0 -1
- package/dist/src/lib/shared/utils.js +424 -0
- package/dist/{types/src → src}/lib/wallet/index.d.ts +0 -1
- package/dist/src/lib/wallet/index.js +301 -0
- package/dist/{types/src → src}/lib/wallet/provider.d.ts +0 -1
- package/dist/src/lib/wallet/provider.js +58 -0
- package/dist/{types/src → src}/lib/wallet/types.d.ts +0 -1
- package/dist/src/lib/wallet/types.js +20 -0
- package/dist/{types/test → test}/_helpers.d.ts +0 -1
- package/dist/test/_helpers.js +95 -0
- package/dist/test/dapp/DAppConnector.test.d.ts +1 -0
- package/dist/test/dapp/DAppConnector.test.js +236 -0
- package/dist/test/dapp/DAppSigner.test.d.ts +1 -0
- package/dist/test/dapp/DAppSigner.test.js +155 -0
- package/dist/test/utils.test.d.ts +1 -0
- package/dist/test/utils.test.js +202 -0
- package/dist/test/wallet/methods/wallet-executeTransaction.test.d.ts +1 -0
- package/dist/test/wallet/methods/wallet-executeTransaction.test.js +43 -0
- package/dist/test/wallet/methods/wallet-getNodeAddresses.test.d.ts +1 -0
- package/dist/test/wallet/methods/wallet-getNodeAddresses.test.js +40 -0
- package/dist/test/wallet/methods/wallet-signAndExecuteQuery.test.d.ts +1 -0
- package/dist/test/wallet/methods/wallet-signAndExecuteQuery.test.js +41 -0
- package/dist/test/wallet/methods/wallet-signAndExecuteTransaction.test.d.ts +1 -0
- package/dist/test/wallet/methods/wallet-signAndExecuteTransaction.test.js +48 -0
- package/dist/test/wallet/methods/wallet-signMessage.test.d.ts +1 -0
- package/dist/test/wallet/methods/wallet-signMessage.test.js +60 -0
- package/dist/test/wallet/methods/wallet-signTransaction.test.d.ts +1 -0
- package/dist/test/wallet/methods/wallet-signTransaction.test.js +45 -0
- package/dist/test/wallet/wallet-init.test.d.ts +1 -0
- package/dist/test/wallet/wallet-init.test.js +53 -0
- package/package.json +13 -19
- package/dist/browser-cjs-metafile.json +0 -1
- package/dist/browser-cjs.js +0 -250
- package/dist/browser-esm-metafile.json +0 -1
- package/dist/browser-esm.js +0 -250
- package/dist/node-cjs-metafile.json +0 -1
- package/dist/node-cjs.js +0 -11404
- package/dist/node-esm-metafile.json +0 -1
- package/dist/node-esm.js +0 -11404
- package/dist/types/src/index.d.ts +0 -2
- package/dist/types/src/index.d.ts.map +0 -1
- package/dist/types/src/lib/dapp/DAppSigner.d.ts.map +0 -1
- package/dist/types/src/lib/dapp/index.d.ts.map +0 -1
- package/dist/types/src/lib/index.d.ts.map +0 -1
- package/dist/types/src/lib/shared/chainIds.d.ts.map +0 -1
- package/dist/types/src/lib/shared/errors.d.ts.map +0 -1
- package/dist/types/src/lib/shared/events.d.ts.map +0 -1
- package/dist/types/src/lib/shared/extensionController.d.ts.map +0 -1
- package/dist/types/src/lib/shared/index.d.ts.map +0 -1
- package/dist/types/src/lib/shared/methods.d.ts.map +0 -1
- package/dist/types/src/lib/shared/payloads.d.ts.map +0 -1
- package/dist/types/src/lib/shared/utils.d.ts.map +0 -1
- package/dist/types/src/lib/wallet/index.d.ts.map +0 -1
- package/dist/types/src/lib/wallet/provider.d.ts.map +0 -1
- package/dist/types/src/lib/wallet/types.d.ts.map +0 -1
- package/dist/types/test/_helpers.d.ts.map +0 -1
- package/dist/types/test/dapp/DAppConnector.test.d.ts +0 -2
- package/dist/types/test/dapp/DAppConnector.test.d.ts.map +0 -1
- package/dist/types/test/dapp/DAppSigner.test.d.ts +0 -2
- package/dist/types/test/dapp/DAppSigner.test.d.ts.map +0 -1
- package/dist/types/test/utils.test.d.ts +0 -2
- package/dist/types/test/utils.test.d.ts.map +0 -1
- package/dist/types/test/wallet/methods/wallet-executeTransaction.test.d.ts +0 -2
- package/dist/types/test/wallet/methods/wallet-executeTransaction.test.d.ts.map +0 -1
- package/dist/types/test/wallet/methods/wallet-getNodeAddresses.test.d.ts +0 -2
- package/dist/types/test/wallet/methods/wallet-getNodeAddresses.test.d.ts.map +0 -1
- package/dist/types/test/wallet/methods/wallet-signAndExecuteQuery.test.d.ts +0 -2
- package/dist/types/test/wallet/methods/wallet-signAndExecuteQuery.test.d.ts.map +0 -1
- package/dist/types/test/wallet/methods/wallet-signAndExecuteTransaction.test.d.ts +0 -2
- package/dist/types/test/wallet/methods/wallet-signAndExecuteTransaction.test.d.ts.map +0 -1
- package/dist/types/test/wallet/methods/wallet-signMessage.test.d.ts +0 -2
- package/dist/types/test/wallet/methods/wallet-signMessage.test.d.ts.map +0 -1
- package/dist/types/test/wallet/methods/wallet-signTransaction.test.d.ts +0 -2
- package/dist/types/test/wallet/methods/wallet-signTransaction.test.d.ts.map +0 -1
- package/dist/types/test/wallet/wallet-init.test.d.ts +0 -2
- package/dist/types/test/wallet/wallet-init.test.d.ts.map +0 -1
@@ -0,0 +1,301 @@
|
|
1
|
+
/*
|
2
|
+
*
|
3
|
+
* Hedera Wallet Connect
|
4
|
+
*
|
5
|
+
* Copyright (C) 2023 Hedera Hashgraph, LLC
|
6
|
+
*
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
* you may not use this file except in compliance with the License.
|
9
|
+
* You may obtain a copy of the License at
|
10
|
+
*
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
*
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
* See the License for the specific language governing permissions and
|
17
|
+
* limitations under the License.
|
18
|
+
*
|
19
|
+
*/
|
20
|
+
import { Buffer } from 'buffer';
|
21
|
+
import { Core } from '@walletconnect/core';
|
22
|
+
import { Web3Wallet } from '@walletconnect/web3wallet';
|
23
|
+
import { buildApprovedNamespaces, getSdkError } from '@walletconnect/utils';
|
24
|
+
import { Wallet as HederaWallet, Client, AccountId } from '@hashgraph/sdk';
|
25
|
+
import { HederaChainId, HederaSessionEvent, HederaJsonRpcMethod, base64StringToQuery, Uint8ArrayToBase64String, stringToSignerMessage, signatureMapToBase64String, signerSignaturesToSignatureMap, base64StringToTransaction, getHederaError, } from '../shared';
|
26
|
+
import { proto } from '@hashgraph/proto';
|
27
|
+
import Provider from './provider';
|
28
|
+
export { default as WalletProvider } from './provider';
|
29
|
+
/*
|
30
|
+
*
|
31
|
+
* @see {@link https://github.com/WalletConnect/walletconnect-monorepo/blob/v2.0/packages/web3wallet/src/client.ts}
|
32
|
+
*/
|
33
|
+
export class HederaWeb3Wallet extends Web3Wallet {
|
34
|
+
/*
|
35
|
+
* Set default values for chains, methods, events
|
36
|
+
*/
|
37
|
+
constructor(opts, chains = Object.values(HederaChainId), methods = Object.values(HederaJsonRpcMethod), sessionEvents = Object.values(HederaSessionEvent)) {
|
38
|
+
super(opts);
|
39
|
+
this.chains = chains;
|
40
|
+
this.methods = methods;
|
41
|
+
this.sessionEvents = sessionEvents;
|
42
|
+
}
|
43
|
+
// wrapper to reduce needing to instantiate Core object on client, also add hedera sensible defaults
|
44
|
+
static async create(projectId, metadata, chains, methods, sessionEvents) {
|
45
|
+
const wallet = new HederaWeb3Wallet({ core: new Core({ projectId }), metadata }, chains, methods, sessionEvents);
|
46
|
+
//https://github.com/WalletConnect/walletconnect-monorepo/blob/14f54684c3d89a5986a68f4dd700a79a958f1604/packages/web3wallet/src/client.ts#L178
|
47
|
+
wallet.logger.trace(`Initialized`);
|
48
|
+
try {
|
49
|
+
await wallet.engine.init();
|
50
|
+
wallet.logger.info(`Web3Wallet Initialization Success`);
|
51
|
+
}
|
52
|
+
catch (error) {
|
53
|
+
wallet.logger.info(`Web3Wallet Initialization Failure`);
|
54
|
+
wallet.logger.error(error.message);
|
55
|
+
throw error;
|
56
|
+
}
|
57
|
+
return wallet;
|
58
|
+
}
|
59
|
+
/*
|
60
|
+
* Hedera Wallet Signer
|
61
|
+
*/
|
62
|
+
getHederaWallet(chainId, accountId, privateKey, _provider) {
|
63
|
+
const network = chainId.split(':')[1];
|
64
|
+
const client = Client.forName(network);
|
65
|
+
const provider = _provider !== null && _provider !== void 0 ? _provider : new Provider(client);
|
66
|
+
return new HederaWallet(accountId, privateKey, provider);
|
67
|
+
}
|
68
|
+
/*
|
69
|
+
* Session proposal
|
70
|
+
*/
|
71
|
+
async buildAndApproveSession(accounts, { id, params }) {
|
72
|
+
// filter to get unique chains
|
73
|
+
const chains = accounts
|
74
|
+
.map((account) => account.split(':').slice(0, 2).join(':'))
|
75
|
+
.filter((x, i, a) => a.indexOf(x) == i);
|
76
|
+
return await this.approveSession({
|
77
|
+
id,
|
78
|
+
namespaces: buildApprovedNamespaces({
|
79
|
+
proposal: params,
|
80
|
+
supportedNamespaces: {
|
81
|
+
hedera: {
|
82
|
+
chains,
|
83
|
+
methods: this.methods,
|
84
|
+
events: this.sessionEvents,
|
85
|
+
accounts,
|
86
|
+
},
|
87
|
+
},
|
88
|
+
}),
|
89
|
+
});
|
90
|
+
}
|
91
|
+
/*
|
92
|
+
* Session Requests
|
93
|
+
*/
|
94
|
+
validateParam(name, value, expectedType) {
|
95
|
+
if (expectedType === 'array' && Array.isArray(value))
|
96
|
+
return;
|
97
|
+
if (typeof value === expectedType)
|
98
|
+
return;
|
99
|
+
throw getHederaError('INVALID_PARAMS', `Invalid paramameter value for ${name}, expected ${expectedType} but got ${typeof value}`);
|
100
|
+
}
|
101
|
+
parseSessionRequest(event,
|
102
|
+
// optional arg to throw error if request is invalid, call with shouldThrow = false when calling from rejectSessionRequest as we only need id and top to send reject response
|
103
|
+
shouldThrow = true) {
|
104
|
+
const { id, topic } = event;
|
105
|
+
const { request: { method, params }, chainId, } = event.params;
|
106
|
+
let body;
|
107
|
+
// get account id from optional second param for transactions and queries or from transaction id
|
108
|
+
// this allows for the case where the requested signer is not the payer, but defaults to the payer if a second param is not provided
|
109
|
+
let signerAccountId;
|
110
|
+
// First test for valid params for each method
|
111
|
+
// then convert params to a body that the respective function expects
|
112
|
+
try {
|
113
|
+
switch (method) {
|
114
|
+
case HederaJsonRpcMethod.GetNodeAddresses: {
|
115
|
+
// 1
|
116
|
+
if (params)
|
117
|
+
throw getHederaError('INVALID_PARAMS');
|
118
|
+
break;
|
119
|
+
}
|
120
|
+
case HederaJsonRpcMethod.ExecuteTransaction: {
|
121
|
+
// 2
|
122
|
+
const { transactionList } = params;
|
123
|
+
this.validateParam('transactionList', transactionList, 'string');
|
124
|
+
body = base64StringToTransaction(transactionList);
|
125
|
+
break;
|
126
|
+
}
|
127
|
+
case HederaJsonRpcMethod.SignMessage: {
|
128
|
+
// 3
|
129
|
+
const { signerAccountId: _accountId, message } = params;
|
130
|
+
this.validateParam('signerAccountId', _accountId, 'string');
|
131
|
+
this.validateParam('message', message, 'string');
|
132
|
+
signerAccountId = AccountId.fromString(_accountId.replace(chainId + ':', ''));
|
133
|
+
body = message;
|
134
|
+
break;
|
135
|
+
}
|
136
|
+
case HederaJsonRpcMethod.SignAndExecuteQuery: {
|
137
|
+
// 4
|
138
|
+
const { signerAccountId: _accountId, query } = params;
|
139
|
+
this.validateParam('signerAccountId', _accountId, 'string');
|
140
|
+
this.validateParam('query', query, 'string');
|
141
|
+
signerAccountId = AccountId.fromString(_accountId.replace(chainId + ':', ''));
|
142
|
+
body = base64StringToQuery(query);
|
143
|
+
break;
|
144
|
+
}
|
145
|
+
case HederaJsonRpcMethod.SignAndExecuteTransaction: {
|
146
|
+
// 5
|
147
|
+
const { signerAccountId: _accountId, transactionList } = params;
|
148
|
+
this.validateParam('signerAccountId', _accountId, 'string');
|
149
|
+
this.validateParam('transactionList', transactionList, 'string');
|
150
|
+
signerAccountId = AccountId.fromString(_accountId.replace(chainId + ':', ''));
|
151
|
+
body = base64StringToTransaction(transactionList);
|
152
|
+
break;
|
153
|
+
}
|
154
|
+
case HederaJsonRpcMethod.SignTransaction: {
|
155
|
+
// 6
|
156
|
+
const { signerAccountId: _accountId, transactionBody } = params;
|
157
|
+
this.validateParam('signerAccountId', _accountId, 'string');
|
158
|
+
this.validateParam('transactionBody', transactionBody, 'string');
|
159
|
+
signerAccountId = AccountId.fromString(_accountId.replace(chainId + ':', ''));
|
160
|
+
body = Buffer.from(transactionBody, 'base64');
|
161
|
+
break;
|
162
|
+
}
|
163
|
+
default:
|
164
|
+
throw getSdkError('INVALID_METHOD');
|
165
|
+
}
|
166
|
+
// error parsing request params
|
167
|
+
}
|
168
|
+
catch (e) {
|
169
|
+
if (shouldThrow)
|
170
|
+
throw e;
|
171
|
+
}
|
172
|
+
return {
|
173
|
+
method: method,
|
174
|
+
chainId: chainId,
|
175
|
+
id,
|
176
|
+
topic,
|
177
|
+
body,
|
178
|
+
accountId: signerAccountId,
|
179
|
+
};
|
180
|
+
}
|
181
|
+
async executeSessionRequest(event, hederaWallet) {
|
182
|
+
const { method, id, topic, body } = this.parseSessionRequest(event);
|
183
|
+
return await this[method](id, topic, body, hederaWallet);
|
184
|
+
}
|
185
|
+
// https://docs.walletconnect.com/web3wallet/wallet-usage#responding-to-session-requests
|
186
|
+
async rejectSessionRequest(event, error) {
|
187
|
+
const { id, topic } = this.parseSessionRequest(event, false);
|
188
|
+
return await this.respondSessionRequest({
|
189
|
+
topic,
|
190
|
+
response: { id, error, jsonrpc: '2.0' },
|
191
|
+
});
|
192
|
+
}
|
193
|
+
/*
|
194
|
+
* JSON RPC Methods
|
195
|
+
*/
|
196
|
+
// 1. hedera_getNodeAddresses
|
197
|
+
async hedera_getNodeAddresses(id, topic, _, // ignore this param to be consistent call signature with other functions
|
198
|
+
signer) {
|
199
|
+
const nodesAccountIds = signer.getNetwork();
|
200
|
+
const nodes = Object.values(nodesAccountIds).map((nodeAccountId) => nodeAccountId.toString());
|
201
|
+
const response = {
|
202
|
+
topic,
|
203
|
+
response: {
|
204
|
+
jsonrpc: '2.0',
|
205
|
+
id,
|
206
|
+
result: {
|
207
|
+
nodes,
|
208
|
+
},
|
209
|
+
},
|
210
|
+
};
|
211
|
+
return await this.respondSessionRequest(response);
|
212
|
+
}
|
213
|
+
// 2. hedera_executeTransaction
|
214
|
+
async hedera_executeTransaction(id, topic, body, signer) {
|
215
|
+
const response = {
|
216
|
+
topic,
|
217
|
+
response: {
|
218
|
+
id,
|
219
|
+
result: (await signer.call(body)).toJSON(),
|
220
|
+
jsonrpc: '2.0',
|
221
|
+
},
|
222
|
+
};
|
223
|
+
return await this.respondSessionRequest(response);
|
224
|
+
}
|
225
|
+
// 3. hedera_signMessage
|
226
|
+
async hedera_signMessage(id, topic, body, signer) {
|
227
|
+
// signer takes an array of Uint8Arrays though spec allows for 1 message to be signed
|
228
|
+
const signerSignatures = await signer.sign(stringToSignerMessage(body));
|
229
|
+
const _signatureMap = proto.SignatureMap.create(signerSignaturesToSignatureMap(signerSignatures));
|
230
|
+
const signatureMap = signatureMapToBase64String(_signatureMap);
|
231
|
+
const response = {
|
232
|
+
topic,
|
233
|
+
response: {
|
234
|
+
jsonrpc: '2.0',
|
235
|
+
id,
|
236
|
+
result: {
|
237
|
+
signatureMap,
|
238
|
+
},
|
239
|
+
},
|
240
|
+
};
|
241
|
+
return await this.respondSessionRequest(response);
|
242
|
+
}
|
243
|
+
// 4. hedera_signAndExecuteQuery
|
244
|
+
async hedera_signAndExecuteQuery(id, topic, body, signer) {
|
245
|
+
/*
|
246
|
+
* Can be used with return values the have a toBytes method implemented
|
247
|
+
* For example:
|
248
|
+
* https://github.com/hashgraph/hedera-sdk-js/blob/c4438cbaa38074d8bfc934dba84e3b430344ed89/src/account/AccountInfo.js#L402
|
249
|
+
*/
|
250
|
+
const queryResult = await body.executeWithSigner(signer);
|
251
|
+
let queryResponse = '';
|
252
|
+
if (Array.isArray(queryResult)) {
|
253
|
+
queryResponse = queryResult.map((qr) => Uint8ArrayToBase64String(qr.toBytes())).join(',');
|
254
|
+
}
|
255
|
+
else {
|
256
|
+
queryResponse = Uint8ArrayToBase64String(queryResult.toBytes());
|
257
|
+
}
|
258
|
+
const response = {
|
259
|
+
topic,
|
260
|
+
response: {
|
261
|
+
jsonrpc: '2.0',
|
262
|
+
id,
|
263
|
+
result: {
|
264
|
+
response: queryResponse,
|
265
|
+
},
|
266
|
+
},
|
267
|
+
};
|
268
|
+
return await this.respondSessionRequest(response);
|
269
|
+
}
|
270
|
+
// 5. hedera_signAndExecuteTransaction
|
271
|
+
async hedera_signAndExecuteTransaction(id, topic, body, signer) {
|
272
|
+
const signedTransaction = await signer.signTransaction(body);
|
273
|
+
const response = {
|
274
|
+
topic,
|
275
|
+
response: {
|
276
|
+
id,
|
277
|
+
result: (await signer.call(signedTransaction)).toJSON(),
|
278
|
+
jsonrpc: '2.0',
|
279
|
+
},
|
280
|
+
};
|
281
|
+
return await this.respondSessionRequest(response);
|
282
|
+
}
|
283
|
+
// 6. hedera_signTransaction
|
284
|
+
async hedera_signTransaction(id, topic, body, signer) {
|
285
|
+
const signerSignatures = await signer.sign([body]);
|
286
|
+
const _signatureMap = proto.SignatureMap.create(signerSignaturesToSignatureMap(signerSignatures));
|
287
|
+
const signatureMap = signatureMapToBase64String(_signatureMap);
|
288
|
+
const response = {
|
289
|
+
topic,
|
290
|
+
response: {
|
291
|
+
jsonrpc: '2.0',
|
292
|
+
id,
|
293
|
+
result: {
|
294
|
+
signatureMap,
|
295
|
+
},
|
296
|
+
},
|
297
|
+
};
|
298
|
+
return await this.respondSessionRequest(response);
|
299
|
+
}
|
300
|
+
}
|
301
|
+
export default HederaWeb3Wallet;
|
@@ -15,4 +15,3 @@ export default class Provider implements HederaWalletProvider {
|
|
15
15
|
waitForReceipt(response: TransactionResponse): Promise<TransactionReceipt>;
|
16
16
|
call<Request, Response, Output>(request: Executable<Request, Response, Output>): Promise<Output>;
|
17
17
|
}
|
18
|
-
//# sourceMappingURL=provider.d.ts.map
|
@@ -0,0 +1,58 @@
|
|
1
|
+
/*
|
2
|
+
*
|
3
|
+
* Hedera Wallet Connect
|
4
|
+
*
|
5
|
+
* Copyright (C) 2023 Hedera Hashgraph, LLC
|
6
|
+
*
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
* you may not use this file except in compliance with the License.
|
9
|
+
* You may obtain a copy of the License at
|
10
|
+
*
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
*
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
* See the License for the specific language governing permissions and
|
17
|
+
* limitations under the License.
|
18
|
+
*
|
19
|
+
*/
|
20
|
+
import { AccountBalanceQuery, AccountInfoQuery, AccountRecordsQuery, TransactionReceiptQuery, } from '@hashgraph/sdk';
|
21
|
+
export default class Provider {
|
22
|
+
constructor(client) {
|
23
|
+
this.client = client;
|
24
|
+
}
|
25
|
+
static fromClient(client) {
|
26
|
+
return new Provider(client);
|
27
|
+
}
|
28
|
+
getLedgerId() {
|
29
|
+
return this.client.ledgerId;
|
30
|
+
}
|
31
|
+
getNetwork() {
|
32
|
+
return this.client.network;
|
33
|
+
}
|
34
|
+
getMirrorNetwork() {
|
35
|
+
return this.client.mirrorNetwork;
|
36
|
+
}
|
37
|
+
getAccountBalance(accountId) {
|
38
|
+
return new AccountBalanceQuery().setAccountId(accountId).execute(this.client);
|
39
|
+
}
|
40
|
+
getAccountInfo(accountId) {
|
41
|
+
return new AccountInfoQuery().setAccountId(accountId).execute(this.client);
|
42
|
+
}
|
43
|
+
getAccountRecords(accountId) {
|
44
|
+
return new AccountRecordsQuery().setAccountId(accountId).execute(this.client);
|
45
|
+
}
|
46
|
+
getTransactionReceipt(transactionId) {
|
47
|
+
return new TransactionReceiptQuery().setTransactionId(transactionId).execute(this.client);
|
48
|
+
}
|
49
|
+
waitForReceipt(response) {
|
50
|
+
return new TransactionReceiptQuery()
|
51
|
+
.setNodeAccountIds([response.nodeId])
|
52
|
+
.setTransactionId(response.transactionId)
|
53
|
+
.execute(this.client);
|
54
|
+
}
|
55
|
+
call(request) {
|
56
|
+
return request.execute(this.client);
|
57
|
+
}
|
58
|
+
}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
/*
|
2
|
+
*
|
3
|
+
* Hedera Wallet Connect
|
4
|
+
*
|
5
|
+
* Copyright (C) 2023 Hedera Hashgraph, LLC
|
6
|
+
*
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
* you may not use this file except in compliance with the License.
|
9
|
+
* You may obtain a copy of the License at
|
10
|
+
*
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
*
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
* See the License for the specific language governing permissions and
|
17
|
+
* limitations under the License.
|
18
|
+
*
|
19
|
+
*/
|
20
|
+
export {};
|
@@ -36,4 +36,3 @@ export declare const testPrivateKeyED25519 = "302e020100300506032b65700422042013
|
|
36
36
|
export declare function useJsonFixture(filename: string): any;
|
37
37
|
export declare function writeJsonFixture(filename: string, data: any): void;
|
38
38
|
export {};
|
39
|
-
//# sourceMappingURL=_helpers.d.ts.map
|
@@ -0,0 +1,95 @@
|
|
1
|
+
/*
|
2
|
+
*
|
3
|
+
* Hedera Wallet Connect
|
4
|
+
*
|
5
|
+
* Copyright (C) 2023 Hedera Hashgraph, LLC
|
6
|
+
*
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
* you may not use this file except in compliance with the License.
|
9
|
+
* You may obtain a copy of the License at
|
10
|
+
*
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
*
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
* See the License for the specific language governing permissions and
|
17
|
+
* limitations under the License.
|
18
|
+
*
|
19
|
+
*/
|
20
|
+
import fs from 'fs';
|
21
|
+
import path from 'path';
|
22
|
+
import { AccountId, TransactionId } from '@hashgraph/sdk';
|
23
|
+
export const projectId = 'ce06497abf4102004138a10edd29c921';
|
24
|
+
export const walletMetadata = {
|
25
|
+
name: 'Wallet Test',
|
26
|
+
url: 'https://dapp.hedera.app',
|
27
|
+
description: 'Hedera Hashgraph Wallet Example.',
|
28
|
+
icons: [
|
29
|
+
'https://cdn-assets-cloud.frontify.com/s3/frontify-cloud-files-us/eyJwYXRoIjoiZnJvbnRpZnlcL2FjY291bnRzXC8xNFwvMTQzMTI3XC9wcm9qZWN0c1wvMTgwMjE1XC9hc3NldHNcL2M3XC8zNDU0ODY3XC85ZjM1NDliYmE5MGQ2NDA0OGU0NzlhZTNiMzkyYzY4Yy0xNTY2NTkxOTQ4LmpwZyJ9:frontify:v_zJvQTCjtNploUvnSpk8S5NJB4R5eei6f7ERL2KSeQ?width=800',
|
30
|
+
],
|
31
|
+
};
|
32
|
+
export const dAppMetadata = {
|
33
|
+
name: 'dApp Test',
|
34
|
+
url: 'https://dapp.hedera.app',
|
35
|
+
description: 'Hedera Hashgraph dApp Example.',
|
36
|
+
icons: [
|
37
|
+
'https://cdn-assets-cloud.frontify.com/s3/frontify-cloud-files-us/eyJwYXRoIjoiZnJvbnRpZnlcL2FjY291bnRzXC8xNFwvMTQzMTI3XC9wcm9qZWN0c1wvMTgwMjE1XC9hc3NldHNcL2M3XC8zNDU0ODY3XC85ZjM1NDliYmE5MGQ2NDA0OGU0NzlhZTNiMzkyYzY4Yy0xNTY2NTkxOTQ4LmpwZyJ9:frontify:v_zJvQTCjtNploUvnSpk8S5NJB4R5eei6f7ERL2KSeQ?width=800',
|
38
|
+
],
|
39
|
+
};
|
40
|
+
export const requestId = 1;
|
41
|
+
export const requestTopic = 'test-topic';
|
42
|
+
export const defaultAccountNumber = 12345;
|
43
|
+
export const defaultNodeId = 3;
|
44
|
+
export const testUserAccountId = new AccountId(defaultAccountNumber);
|
45
|
+
export const testNodeAccountId = new AccountId(defaultNodeId);
|
46
|
+
/** Fixed to a specific timestamp */
|
47
|
+
export const testTransactionId = TransactionId.fromString(`0.0.${defaultAccountNumber}@1691705630.325343432`);
|
48
|
+
export function prepareTestTransaction(transaction, options) {
|
49
|
+
const selectedOptions = Object.assign({
|
50
|
+
// defaults
|
51
|
+
freeze: false, setNodeAccountIds: true, setTransactionId: true, operatorAccountId: defaultAccountNumber }, options);
|
52
|
+
if (selectedOptions.setNodeAccountIds) {
|
53
|
+
transaction.setNodeAccountIds([testNodeAccountId]);
|
54
|
+
}
|
55
|
+
if (selectedOptions.setTransactionId) {
|
56
|
+
let transactionId = testTransactionId;
|
57
|
+
if (selectedOptions.operatorAccountId &&
|
58
|
+
selectedOptions.operatorAccountId !== defaultAccountNumber) {
|
59
|
+
transactionId = TransactionId.generate(new AccountId(selectedOptions.operatorAccountId));
|
60
|
+
}
|
61
|
+
transaction.setTransactionId(transactionId);
|
62
|
+
}
|
63
|
+
if (selectedOptions.freeze) {
|
64
|
+
transaction.freeze();
|
65
|
+
}
|
66
|
+
return transaction;
|
67
|
+
}
|
68
|
+
export function prepareTestQuery(query, options) {
|
69
|
+
const selectedOptions = Object.assign({
|
70
|
+
// defaults
|
71
|
+
setNodeAccountIds: true }, options);
|
72
|
+
if (selectedOptions.setNodeAccountIds) {
|
73
|
+
query.setNodeAccountIds([testNodeAccountId]);
|
74
|
+
}
|
75
|
+
return query;
|
76
|
+
}
|
77
|
+
// from PrivateKey.generateECDSA().toStringDer()
|
78
|
+
export const testPrivateKeyECDSA = '3030020100300706052b8104000a042204203ce31ffad30d6db47c315bbea08232aad2266d8800a12aa3d8a812486e782759';
|
79
|
+
// from PrivateKey.generateED25519().toStringDer()
|
80
|
+
export const testPrivateKeyED25519 = '302e020100300506032b657004220420133eefea772add1f995c96bccf42b08b76daf67665f0c4c5ae308fae9275c142';
|
81
|
+
/** JSON fixture helpers */
|
82
|
+
const FIXTURES_PATH = 'test/_fixtures';
|
83
|
+
const filenameWithJsonExtension = (filename) => {
|
84
|
+
const file = /\.json$/.test(filename) ? filename : filename + '.json';
|
85
|
+
return path.join(FIXTURES_PATH, file);
|
86
|
+
};
|
87
|
+
export function useJsonFixture(filename) {
|
88
|
+
const filepath = filenameWithJsonExtension(filename);
|
89
|
+
const data = fs.readFileSync(filepath).toString();
|
90
|
+
return JSON.parse(data);
|
91
|
+
}
|
92
|
+
export function writeJsonFixture(filename, data) {
|
93
|
+
const filepath = filenameWithJsonExtension(filename);
|
94
|
+
fs.writeFileSync(filepath, JSON.stringify(data, null, 2));
|
95
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|