@hashgraph/hedera-wallet-connect 1.3.2-1 → 1.3.3
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +3 -3
- package/dist/src/lib/dapp/DAppSigner.js +6 -1
- package/dist/src/lib/dapp/index.d.ts +8 -0
- package/dist/src/lib/dapp/index.js +8 -0
- package/dist/src/lib/shared/utils.d.ts +2 -2
- package/dist/src/lib/shared/utils.js +2 -2
- package/dist/test/dapp/DAppConnector.test.js +1 -3
- package/dist/test/utils.test.js +0 -1
- package/dist/test/wallet/methods/wallet-signTransaction.test.js +3 -1
- package/package.json +15 -14
package/README.md
CHANGED
@@ -71,8 +71,8 @@ use this library’s functions to easily create and handle requests for the Hede
|
|
71
71
|
|
72
72
|
### Example code
|
73
73
|
|
74
|
-
- [Typescript dApp example code](
|
75
|
-
- [Typescript Wallet example code](
|
74
|
+
- [Typescript dApp example code](demos/typescript/dapp/main.ts)
|
75
|
+
- [Typescript Wallet example code](demos/typescript/wallet/main.ts)
|
76
76
|
- [React dApp example code](demos/react-dapp)
|
77
77
|
|
78
78
|
|
@@ -288,7 +288,7 @@ example useful for testing and development while integrating WalletConnect and H
|
|
288
288
|
The docs site utilizes [Typedoc](https://typedoc.org) to generate a library documentation site
|
289
289
|
at <https://wc.hgraph.app/docs/>
|
290
290
|
|
291
|
-
The demo source code lives in `./
|
291
|
+
The demo source code lives in `./demos/typescript` and is available at
|
292
292
|
<https://wc.hgraph.app>
|
293
293
|
|
294
294
|
## Passing tests
|
@@ -17,7 +17,7 @@
|
|
17
17
|
* limitations under the License.
|
18
18
|
*
|
19
19
|
*/
|
20
|
-
import { AccountBalance, AccountId, AccountInfo, LedgerId, SignerSignature, Transaction, TransactionRecord, Client, PublicKey, TransactionId, TransactionResponse, Query, AccountRecordsQuery, AccountInfoQuery, AccountBalanceQuery, TransactionReceiptQuery, TransactionReceipt, } from '@hashgraph/sdk';
|
20
|
+
import { AccountBalance, AccountId, AccountInfo, LedgerId, SignerSignature, Transaction, TransactionRecord, Client, PublicKey, TransactionId, TransactionResponse, Query, AccountRecordsQuery, AccountInfoQuery, AccountBalanceQuery, TransactionReceiptQuery, TransactionReceipt, TransactionRecordQuery, } from '@hashgraph/sdk';
|
21
21
|
import { proto } from '@hashgraph/proto';
|
22
22
|
import { HederaJsonRpcMethod, Uint8ArrayToBase64String, base64StringToSignatureMap, base64StringToUint8Array, ledgerIdToCAIPChainId, queryToBase64String, transactionBodyToBase64String, transactionToBase64String, transactionToTransactionBody, extensionOpen, } from '../shared';
|
23
23
|
const clients = {};
|
@@ -121,6 +121,8 @@ export class DAppSigner {
|
|
121
121
|
else
|
122
122
|
nodeAccountId = transaction.nodeAccountIds[0];
|
123
123
|
const transactionBody = transactionToTransactionBody(transaction, nodeAccountId);
|
124
|
+
if (!transactionBody)
|
125
|
+
throw new Error('Failed to serialize transaction body');
|
124
126
|
const transactionBodyBase64 = transactionBodyToBase64String(transactionBody);
|
125
127
|
const { signatureMap } = await this.request({
|
126
128
|
method: HederaJsonRpcMethod.SignTransaction,
|
@@ -166,6 +168,9 @@ export class DAppSigner {
|
|
166
168
|
else if (query instanceof TransactionReceiptQuery) {
|
167
169
|
return TransactionReceipt.fromBytes(data);
|
168
170
|
}
|
171
|
+
else if (query instanceof TransactionRecordQuery) {
|
172
|
+
return TransactionRecord.fromBytes(data);
|
173
|
+
}
|
169
174
|
else {
|
170
175
|
throw new Error('Unsupported query type');
|
171
176
|
}
|
@@ -36,9 +36,17 @@ export declare class DAppConnector {
|
|
36
36
|
init({ logger }?: {
|
37
37
|
logger?: BaseLogger;
|
38
38
|
}): Promise<void>;
|
39
|
+
/**
|
40
|
+
* Retrieves a DAppSigner for the specified Hedera Account ID.
|
41
|
+
*
|
42
|
+
* @param {AccountId} accountId - The Hedera Account ID to find the associated signer.
|
43
|
+
* @returns {DAppSigner} - The signer object of type {@link DAppSigner} corresponding to the provided account ID.
|
44
|
+
* @throws {Error} - If no signer is found for the provided account ID.
|
45
|
+
*/
|
39
46
|
getSigner(accountId: AccountId): DAppSigner;
|
40
47
|
/**
|
41
48
|
* Initiates the WalletConnect connection flow using a QR code.
|
49
|
+
* @deprecated Use `openModal` instead.
|
42
50
|
* @param pairingTopic - The pairing topic for the connection (optional).
|
43
51
|
* @returns A Promise that resolves when the connection process is complete.
|
44
52
|
*/
|
@@ -131,6 +131,13 @@ export class DAppConnector {
|
|
131
131
|
this.isInitializing = false;
|
132
132
|
}
|
133
133
|
}
|
134
|
+
/**
|
135
|
+
* Retrieves a DAppSigner for the specified Hedera Account ID.
|
136
|
+
*
|
137
|
+
* @param {AccountId} accountId - The Hedera Account ID to find the associated signer.
|
138
|
+
* @returns {DAppSigner} - The signer object of type {@link DAppSigner} corresponding to the provided account ID.
|
139
|
+
* @throws {Error} - If no signer is found for the provided account ID.
|
140
|
+
*/
|
134
141
|
getSigner(accountId) {
|
135
142
|
const signer = this.signers.find((signer) => signer.getAccountId().equals(accountId));
|
136
143
|
if (!signer)
|
@@ -139,6 +146,7 @@ export class DAppConnector {
|
|
139
146
|
}
|
140
147
|
/**
|
141
148
|
* Initiates the WalletConnect connection flow using a QR code.
|
149
|
+
* @deprecated Use `openModal` instead.
|
142
150
|
* @param pairingTopic - The pairing topic for the connection (optional).
|
143
151
|
* @returns A Promise that resolves when the connection process is complete.
|
144
152
|
*/
|
@@ -49,8 +49,8 @@ export declare function base64StringToTransaction<T extends Transaction>(transac
|
|
49
49
|
* @param transaction - a base64 encoded string of proto.TransactionBody.encode().finish()
|
50
50
|
* @returns `string`
|
51
51
|
* */
|
52
|
-
export declare function transactionToTransactionBody<T extends Transaction>(transaction: T, nodeAccountId: AccountId):
|
53
|
-
export declare function transactionBodyToBase64String(transactionBody:
|
52
|
+
export declare function transactionToTransactionBody<T extends Transaction>(transaction: T, nodeAccountId: AccountId): Uint8Array | null | undefined;
|
53
|
+
export declare function transactionBodyToBase64String(transactionBody: Uint8Array): string;
|
54
54
|
/**
|
55
55
|
* @param transactionList - a proto.TransactionList object
|
56
56
|
* @returns `string`
|
@@ -86,10 +86,10 @@ export function base64StringToTransaction(transactionBytes) {
|
|
86
86
|
export function transactionToTransactionBody(transaction, nodeAccountId) {
|
87
87
|
// This is a private function, though provides the capabilities to construct a proto.TransactionBody
|
88
88
|
//@ts-ignore
|
89
|
-
return transaction.
|
89
|
+
return transaction._signedTransactions.current.bodyBytes;
|
90
90
|
}
|
91
91
|
export function transactionBodyToBase64String(transactionBody) {
|
92
|
-
return Uint8ArrayToBase64String(
|
92
|
+
return Uint8ArrayToBase64String(transactionBody);
|
93
93
|
}
|
94
94
|
/**
|
95
95
|
* @param transactionList - a proto.TransactionList object
|
@@ -203,9 +203,7 @@ describe('DAppConnector', () => {
|
|
203
203
|
const transaction = prepareTestTransaction(new TopicCreateTransaction(), { freeze: true });
|
204
204
|
const params = {
|
205
205
|
signerAccountId: testUserAccountId.toString(),
|
206
|
-
transactionBody: transactionBodyToBase64String(
|
207
|
-
// must specify a node account id for the transaction body
|
208
|
-
transactionToTransactionBody(transaction, AccountId.fromString('0.0.3'))),
|
206
|
+
transactionBody: transactionBodyToBase64String(transactionToTransactionBody(transaction, AccountId.fromString('0.0.3'))),
|
209
207
|
};
|
210
208
|
it('should throw an error if there is no any signer', async () => {
|
211
209
|
connector.signers = [];
|
package/dist/test/utils.test.js
CHANGED
@@ -79,7 +79,6 @@ describe(`Uint8Array helpers`, () => {
|
|
79
79
|
it('should decode base64 string to Uint8Array', async () => {
|
80
80
|
const base64String = btoa('Hello World!');
|
81
81
|
uInt8Array = base64StringToUint8Array(base64String);
|
82
|
-
console.log(Array.from(uInt8Array));
|
83
82
|
expect(uInt8Array).toBeInstanceOf(Uint8Array);
|
84
83
|
expect(Array.from(uInt8Array)).toEqual([
|
85
84
|
72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 33,
|
@@ -17,7 +17,7 @@
|
|
17
17
|
* limitations under the License.
|
18
18
|
*
|
19
19
|
*/
|
20
|
-
import { TransferTransaction,
|
20
|
+
import { TransferTransaction, Hbar, AccountId } from '@hashgraph/sdk';
|
21
21
|
import { HederaChainId, Wallet, transactionToTransactionBody, } from '../../../src';
|
22
22
|
import { projectId, requestId, requestTopic, testPrivateKeyECDSA, testUserAccountId, useJsonFixture, walletMetadata, } from '../../_helpers';
|
23
23
|
describe(Wallet.name, () => {
|
@@ -31,6 +31,8 @@ describe(Wallet.name, () => {
|
|
31
31
|
.addHbarTransfer('0.0.123', new Hbar(10))
|
32
32
|
.addHbarTransfer('0.0.321', new Hbar(-10));
|
33
33
|
const transactionBody = transactionToTransactionBody(transaction, AccountId.fromString('0.0.3'));
|
34
|
+
if (!transactionBody)
|
35
|
+
throw new Error('Failed to create transaction body');
|
34
36
|
const respondSessionRequestSpy = jest.spyOn(wallet, 'respondSessionRequest');
|
35
37
|
const response = await wallet.hedera_signTransaction(requestId, requestTopic, transactionBody, hederaWallet);
|
36
38
|
console.log(response);
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@hashgraph/hedera-wallet-connect",
|
3
|
-
"version": "1.3.
|
3
|
+
"version": "1.3.3",
|
4
4
|
"description": "A library to facilitate integrating Hedera with WalletConnect",
|
5
5
|
"repository": {
|
6
6
|
"type": "git",
|
@@ -18,13 +18,13 @@
|
|
18
18
|
"devDependencies": {
|
19
19
|
"@hashgraph/hedera-wallet-connect": "^1.3.1",
|
20
20
|
"@types/jest": "^29.5.3",
|
21
|
-
"@types/node": "^
|
21
|
+
"@types/node": "^22.5.0",
|
22
22
|
"@types/react-dom": "^18.2.21",
|
23
|
-
"@walletconnect/modal": "^2.
|
24
|
-
"@walletconnect/sign-client": "^2.
|
25
|
-
"@walletconnect/types": "^2.
|
26
|
-
"concurrently": "^
|
27
|
-
"esbuild": "^0.
|
23
|
+
"@walletconnect/modal": "^2.7.0",
|
24
|
+
"@walletconnect/sign-client": "^2.17.0",
|
25
|
+
"@walletconnect/types": "^2.17.0",
|
26
|
+
"concurrently": "^9.0.1",
|
27
|
+
"esbuild": "^0.24.0",
|
28
28
|
"esbuild-plugin-copy": "^2.1.1",
|
29
29
|
"eslint-plugin-tsdoc": "^0.3.0",
|
30
30
|
"husky": "^9.0.6",
|
@@ -44,12 +44,13 @@
|
|
44
44
|
},
|
45
45
|
"scripts": {
|
46
46
|
"build": "rimraf dist && tsc",
|
47
|
-
"build:
|
48
|
-
"build:
|
47
|
+
"build:ts-demo": "node scripts/demos/typescript/build.mjs",
|
48
|
+
"build:react-demo": "node scripts/demos/react/build.mjs",
|
49
49
|
"build:docs": "typedoc --options typedoc.json",
|
50
50
|
"watch": "nodemon --watch src/lib/ --ext ts --exec \"npm run build\"",
|
51
|
-
"dev": "
|
52
|
-
"dev:
|
51
|
+
"dev": "npm run dev:ts-demo",
|
52
|
+
"dev:ts-demo": "rimraf dist && npm run build && concurrently --raw \"npm run watch\" \"node scripts/demos/typescript/dev.mjs\"",
|
53
|
+
"dev:react-demo": "rimraf dist && npm run build && concurrently --raw \"npm run watch\" \"node scripts/demos/react/dev.mjs\"",
|
53
54
|
"test": "jest",
|
54
55
|
"test:connect": "jest --testMatch '**/DAppConnector.test.ts' --verbose",
|
55
56
|
"test:signer": "jest --testMatch '**/DAppSigner.test.ts' --verbose",
|
@@ -62,8 +63,8 @@
|
|
62
63
|
"peerDependencies": {
|
63
64
|
"@hashgraph/sdk": "^2.40.0",
|
64
65
|
"@walletconnect/qrcode-modal": "^1.8.0",
|
65
|
-
"@walletconnect/types": "^2.
|
66
|
-
"@walletconnect/utils": "^2.
|
67
|
-
"@walletconnect/web3wallet": "^1.
|
66
|
+
"@walletconnect/types": "^2.17.0",
|
67
|
+
"@walletconnect/utils": "^2.17.0",
|
68
|
+
"@walletconnect/web3wallet": "^1.16.0"
|
68
69
|
}
|
69
70
|
}
|