@hashgraph/hedera-wallet-connect 2.0.4 → 2.0.5-canary.09073be.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.
Files changed (69) hide show
  1. package/package.json +1 -1
  2. package/dist/index.d.ts +0 -2
  3. package/dist/index.js +0 -21
  4. package/dist/lib/dapp/DAppSigner.d.ts +0 -60
  5. package/dist/lib/dapp/DAppSigner.js +0 -344
  6. package/dist/lib/dapp/SessionNotFoundError.d.ts +0 -3
  7. package/dist/lib/dapp/SessionNotFoundError.js +0 -6
  8. package/dist/lib/dapp/index.d.ts +0 -216
  9. package/dist/lib/dapp/index.js +0 -588
  10. package/dist/lib/index.d.ts +0 -3
  11. package/dist/lib/index.js +0 -22
  12. package/dist/lib/shared/chainIds.d.ts +0 -11
  13. package/dist/lib/shared/chainIds.js +0 -31
  14. package/dist/lib/shared/errors.d.ts +0 -48
  15. package/dist/lib/shared/errors.js +0 -51
  16. package/dist/lib/shared/events.d.ts +0 -7
  17. package/dist/lib/shared/events.js +0 -27
  18. package/dist/lib/shared/extensionController.d.ts +0 -21
  19. package/dist/lib/shared/extensionController.js +0 -42
  20. package/dist/lib/shared/index.d.ts +0 -7
  21. package/dist/lib/shared/index.js +0 -26
  22. package/dist/lib/shared/logger.d.ts +0 -21
  23. package/dist/lib/shared/logger.js +0 -63
  24. package/dist/lib/shared/methods.d.ts +0 -12
  25. package/dist/lib/shared/methods.js +0 -32
  26. package/dist/lib/shared/payloads.d.ts +0 -101
  27. package/dist/lib/shared/payloads.js +0 -20
  28. package/dist/lib/shared/utils.d.ts +0 -280
  29. package/dist/lib/shared/utils.js +0 -461
  30. package/dist/lib/wallet/index.d.ts +0 -39
  31. package/dist/lib/wallet/index.js +0 -306
  32. package/dist/lib/wallet/provider.d.ts +0 -17
  33. package/dist/lib/wallet/provider.js +0 -58
  34. package/dist/lib/wallet/types.d.ts +0 -31
  35. package/dist/lib/wallet/types.js +0 -20
  36. package/dist/reown/adapter.d.ts +0 -59
  37. package/dist/reown/adapter.js +0 -290
  38. package/dist/reown/connectors/HederaConnector.d.ts +0 -29
  39. package/dist/reown/connectors/HederaConnector.js +0 -32
  40. package/dist/reown/connectors/index.d.ts +0 -1
  41. package/dist/reown/connectors/index.js +0 -1
  42. package/dist/reown/index.d.ts +0 -4
  43. package/dist/reown/index.js +0 -4
  44. package/dist/reown/providers/EIP155Provider.d.ts +0 -33
  45. package/dist/reown/providers/EIP155Provider.js +0 -187
  46. package/dist/reown/providers/HIP820Provider.d.ts +0 -26
  47. package/dist/reown/providers/HIP820Provider.js +0 -67
  48. package/dist/reown/providers/HederaProvider.d.ts +0 -166
  49. package/dist/reown/providers/HederaProvider.js +0 -506
  50. package/dist/reown/providers/index.d.ts +0 -3
  51. package/dist/reown/providers/index.js +0 -3
  52. package/dist/reown/utils/account.d.ts +0 -2
  53. package/dist/reown/utils/account.js +0 -41
  54. package/dist/reown/utils/chains.d.ts +0 -18
  55. package/dist/reown/utils/chains.js +0 -152
  56. package/dist/reown/utils/constants.d.ts +0 -16
  57. package/dist/reown/utils/constants.js +0 -18
  58. package/dist/reown/utils/helpers.d.ts +0 -12
  59. package/dist/reown/utils/helpers.js +0 -25
  60. package/dist/reown/utils/index.d.ts +0 -5
  61. package/dist/reown/utils/index.js +0 -5
  62. package/dist/reown/utils/types.d.ts +0 -9
  63. package/dist/reown/utils/types.js +0 -1
  64. package/dist/reown/wallets/EIP155Wallet.d.ts +0 -46
  65. package/dist/reown/wallets/EIP155Wallet.js +0 -124
  66. package/dist/reown/wallets/HIP820Wallet.d.ts +0 -53
  67. package/dist/reown/wallets/HIP820Wallet.js +0 -236
  68. package/dist/reown/wallets/index.d.ts +0 -2
  69. package/dist/reown/wallets/index.js +0 -2
@@ -1,461 +0,0 @@
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 { AccountId, Transaction, LedgerId, Query, } from '@hashgraph/sdk';
22
- import { proto } from '@hashgraph/proto';
23
- /**
24
- * Converts `Transaction` to a Base64-string.
25
- *
26
- * Converts a transaction to bytes and then encodes it as a Base64-string. Allow incomplete transaction (HIP-745).
27
- * @param transaction - Any instance of a class that extends `Transaction`
28
- * @returns Base64 encoded representation of the input `Transaction` object
29
- */
30
- export function transactionToBase64String(transaction) {
31
- const transactionBytes = transaction.toBytes();
32
- return Buffer.from(transactionBytes).toString('base64');
33
- }
34
- /**
35
- * Recreates a `Transaction` from a base64 encoded string.
36
- *
37
- * Decodes the string to a buffer,
38
- * then passes to `Transaction.fromBytes`. For greater flexibility, this function uses the base
39
- * `Transaction` class, but takes an optional type parameter if the type of transaction is known,
40
- * allowing stronger typeing.
41
- * @param transactionBytes - a base64 encoded string
42
- * @returns `Transaction`
43
- * @example
44
- * ```ts
45
- * const txn1 = base64StringToTransaction(bytesString)
46
- * const txn2 = base64StringToTransaction<TransferTransaction>(bytesString)
47
- * // txn1 type: Transaction
48
- * // txn2 type: TransferTransaction
49
- * ```
50
- */
51
- export function base64StringToTransaction(transactionBytes) {
52
- const decoded = Buffer.from(transactionBytes, 'base64');
53
- return Transaction.fromBytes(decoded);
54
- }
55
- /**
56
- * @param transaction - a base64 encoded string of proto.TransactionBody.encode().finish()
57
- * @param nodeAccountId - an optional `AccountId` to set the node account ID for the transaction
58
- * @returns `string`
59
- * */
60
- export function transactionToTransactionBody(transaction, nodeAccountId = null) {
61
- // This is a private function, though provides the capabilities to construct a proto.TransactionBody
62
- //@ts-ignore
63
- return transaction._makeTransactionBody(nodeAccountId);
64
- }
65
- export function transactionBodyToBase64String(transactionBody) {
66
- return Uint8ArrayToBase64String(proto.TransactionBody.encode(transactionBody).finish());
67
- }
68
- /**
69
- * @param transactionList - a proto.TransactionList object
70
- * @returns `string`
71
- * */
72
- export function transactionListToBase64String(transactionList) {
73
- const encoded = proto.TransactionList.encode(transactionList).finish();
74
- return Uint8ArrayToBase64String(encoded);
75
- }
76
- /**
77
- * Extracts the first signature from a proto.SignatureMap object.
78
- * @param signatureMap - a proto.SignatureMap object
79
- * @returns `Uint8Array`
80
- * */
81
- export const extractFirstSignature = (signatureMap) => {
82
- var _a;
83
- const firstPair = (_a = signatureMap === null || signatureMap === void 0 ? void 0 : signatureMap.sigPair) === null || _a === void 0 ? void 0 : _a[0];
84
- const firstSignature = (firstPair === null || firstPair === void 0 ? void 0 : firstPair.ed25519) || (firstPair === null || firstPair === void 0 ? void 0 : firstPair.ECDSASecp256k1) || (firstPair === null || firstPair === void 0 ? void 0 : firstPair.ECDSA_384);
85
- if (!firstSignature) {
86
- throw new Error('No signatures found in response');
87
- }
88
- return firstSignature;
89
- };
90
- /**
91
- * Decodes base64 encoded proto.TransactionBody bytes to a `proto.TransactionBody` object.
92
- *
93
- * @param transactionBody - a base64 encoded string of proto.TransactionBody.encode().finish()
94
- * @returns `Transaction`
95
- *
96
- * */
97
- export function base64StringToTransactionBody(transactionBody) {
98
- const bytes = Buffer.from(transactionBody, 'base64');
99
- return proto.TransactionBody.decode(bytes);
100
- }
101
- /**
102
- * Converts a `proto.SignatureMap` to a base64 encoded string.
103
- *
104
- * First converts the `proto.SignatureMap` object to a JSON.
105
- * Then encodes the JSON to a base64 encoded string.
106
- * @param signatureMap - The `proto.SignatureMap` object to be converted
107
- * @returns Base64-encoded string representation of the input `proto.SignatureMap`
108
- */
109
- export function signatureMapToBase64String(signatureMap) {
110
- const encoded = proto.SignatureMap.encode(signatureMap).finish();
111
- return Uint8ArrayToBase64String(encoded);
112
- }
113
- /**
114
- * Converts a Base64-encoded string to a `proto.SignatureMap`.
115
- * @param base64string - Base64-encoded string
116
- * @returns `proto.SignatureMap`
117
- */
118
- export function base64StringToSignatureMap(base64string) {
119
- const encoded = Buffer.from(base64string, 'base64');
120
- return proto.SignatureMap.decode(encoded);
121
- }
122
- /**
123
- * Encodes the binary data represented by the `Uint8Array` to a Base64 string.
124
- * @param binary - The `Uint8Array` containing binary data to be converted
125
- * @returns Base64-encoded string representation of the input `Uint8Array`
126
- */
127
- export function Uint8ArrayToBase64String(binary) {
128
- return Buffer.from(binary).toString('base64');
129
- }
130
- /**
131
- * Encodes the binary data represented by the `Uint8Array` to a UTF-8 string.
132
- * @param binary - The `Uint8Array` containing binary data to be converted
133
- * @returns UTF-8 string representation of the input `Uint8Array`
134
- */
135
- export function Uint8ArrayToString(binary) {
136
- return Buffer.from(binary).toString('utf-8');
137
- }
138
- /**
139
- * Converts a Base64-encoded string to a `Uint8Array`.
140
- * @param base64string - Base64-encoded string to be converted
141
- * @returns A `Uint8Array` representing the decoded binary data
142
- */
143
- export function base64StringToUint8Array(base64string) {
144
- const encoded = Buffer.from(base64string, 'base64');
145
- return new Uint8Array(encoded);
146
- }
147
- /**
148
- * Converts a `Query` object to a Base64-encoded string.
149
- * First utilizes the `toBytes` method of the `Query` instance to obtain its binary `Uint8Array` representation.
150
- * Then encodes the binary `Uint8Array` to a Base64 string representation.
151
- * @param query - A `Query` object to be converted
152
- * @returns Base64 encoded representation of the input `Query` object
153
- */
154
- export function queryToBase64String(query) {
155
- const queryBytes = query.toBytes();
156
- return Buffer.from(queryBytes).toString('base64');
157
- }
158
- /**
159
- * Recreates a `Query` from a Base64-encoded string. First decodes the string to a buffer,
160
- * then passes to `Query.fromBytes`. For greater flexibility, this function uses the base
161
- * `Query` class, but takes an optional type parameter if the type of query is known,
162
- * allowing stronger typeing.
163
- * @param bytesString - Base64-encoded string
164
- * @returns `Query<T>`
165
- * @example
166
- * ```ts
167
- * const query1 = base64StringToQuery(bytesString)
168
- * const query2 = base64StringToQuery<AccountInfoQuery>(bytesString)
169
- * // query1 type: Query<any>
170
- * // query2 type: AccountInfoQuery
171
- * ```
172
- */
173
- export function base64StringToQuery(bytesString) {
174
- const decoded = Buffer.from(bytesString, 'base64');
175
- return Query.fromBytes(decoded);
176
- }
177
- export function prefixMessageToSign(message) {
178
- return '\x19Hedera Signed Message:\n' + message.length + message;
179
- }
180
- /**
181
- * Incorporates additional data (salt) into the message to alter the output signature.
182
- * This alteration ensures that passing a transaction here for signing will yield an invalid signature,
183
- * as the additional data modifies the signature text.
184
- *
185
- * @param message - A plain text string
186
- * @returns An array of Uint8Array containing the prepared message for signing
187
- */
188
- export function stringToSignerMessage(message) {
189
- return [Buffer.from(prefixMessageToSign(message))];
190
- }
191
- /**
192
- * This implementation expects a plain text string, which is prefixed and then signed by a wallet.
193
- * Because the spec calls for 1 message to be signed and 1 signer, this function expects a single
194
- * signature and used the first item in the sigPair array.
195
- *
196
- * @param message - A plain text string
197
- * @param base64SignatureMap - A base64 encoded proto.SignatureMap object
198
- * @param publicKey - A PublicKey object use to verify the signature
199
- * @returns boolean - whether or not the first signature in the sigPair is valid for the message and public key
200
- */
201
- export function verifyMessageSignature(message, base64SignatureMap, publicKey) {
202
- const signatureMap = base64StringToSignatureMap(base64SignatureMap);
203
- const signature = signatureMap.sigPair[0].ed25519 || signatureMap.sigPair[0].ECDSASecp256k1;
204
- if (!signature)
205
- throw new Error('Signature not found in signature map');
206
- return publicKey.verify(Buffer.from(prefixMessageToSign(message)), signature);
207
- }
208
- /**
209
- * This implementation expects a plain text string, which is prefixed and then signed by a wallet.
210
- * Because the spec calls for 1 message to be signed and 1 signer, this function expects a single
211
- * signature and used the first item in the sigPair array.
212
- *
213
- * @param message - A plain text string
214
- * @param signerSignature - A SignerSignature object
215
- * @param publicKey - A PublicKey object use to verify the signature
216
- * @returns boolean - whether or not the first signature in the sigPair is valid for the message and public key
217
- */
218
- export function verifySignerSignature(message, signerSignature, publicKey) {
219
- const signature = signerSignature.signature;
220
- if (!signature)
221
- throw new Error('Signature not found in signature map');
222
- return publicKey.verify(Buffer.from(prefixMessageToSign(message)), signature);
223
- }
224
- /**
225
- *
226
- * https://github.com/hashgraph/hedera-sdk-js/blob/c78512b1d43eedf1d8bf2926a5b7ed3368fc39d1/src/PublicKey.js#L258
227
- * a signature pair is a protobuf object with a signature and a public key, it is the responsibility of a dApp to ensure the public key matches the account id
228
- * @param signerSignatures - An array of `SignerSignature` objects
229
- * @returns `proto.SignatureMap` object
230
- */
231
- export function signerSignaturesToSignatureMap(signerSignatures) {
232
- const signatureMap = proto.SignatureMap.create({
233
- sigPair: signerSignatures.map((s) => s.publicKey._toProtobufSignature(s.signature)),
234
- });
235
- return signatureMap;
236
- }
237
- /**
238
- * A mapping of `LedgerId` to EIP chain id and CAIP-2 network name.
239
- *
240
- * Structure: [`LedgerId`, `number` (EIP155 chain id), `string` (CAIP-2 chain id)][]
241
- *
242
- * @see {@link https://namespaces.chainagnostic.org/hedera/README | Hedera Namespaces}
243
- * @see {@link https://hips.hedera.com/hip/hip-30 | CAIP Identifiers for the Hedera Network (HIP-30)}
244
- */
245
- export const LEDGER_ID_MAPPINGS = [
246
- [LedgerId.MAINNET, 295, 'hedera:mainnet'],
247
- [LedgerId.TESTNET, 296, 'hedera:testnet'],
248
- [LedgerId.PREVIEWNET, 297, 'hedera:previewnet'],
249
- [LedgerId.LOCAL_NODE, 298, 'hedera:devnet'],
250
- ];
251
- const DEFAULT_LEDGER_ID = LedgerId.LOCAL_NODE;
252
- const DEFAULT_EIP = LEDGER_ID_MAPPINGS[3][1];
253
- const DEFAULT_CAIP = LEDGER_ID_MAPPINGS[3][2];
254
- /**
255
- * Converts an EIP chain id to a LedgerId object.
256
- *
257
- * If no mapping is found, returns `LedgerId.LOCAL_NODE`.
258
- *
259
- * @param chainId - The EIP chain ID (number) to be converted
260
- * @returns A `LedgerId` corresponding to the provided chain ID
261
- * @example
262
- * ```ts
263
- * const localnodeLedgerId = EIPChainIdToLedgerId(298)
264
- * console.log(localnodeLedgerId) // LedgerId.LOCAL_NODE
265
- * const mainnetLedgerId = EIPChainIdToLedgerId(295)
266
- * console.log(mainnetLedgerId) // LedgerId.MAINNET
267
- * ```
268
- */
269
- export function EIPChainIdToLedgerId(chainId) {
270
- for (let i = 0; i < LEDGER_ID_MAPPINGS.length; i++) {
271
- const [ledgerId, chainId_] = LEDGER_ID_MAPPINGS[i];
272
- if (chainId === chainId_) {
273
- return ledgerId;
274
- }
275
- }
276
- return DEFAULT_LEDGER_ID;
277
- }
278
- /**
279
- * Converts a LedgerId object to an EIP chain id.
280
- *
281
- * If no mapping is found, returns the EIP chain id for `LedgerId.LOCAL_NODE`.
282
- *
283
- * @param ledgerId - The `LedgerId` object to be converted
284
- * @returns A `number` representing the EIP chain id for the provided `LedgerId`
285
- * @example
286
- * ```ts
287
- * const previewnetChainId = ledgerIdToEIPChainId(LedgerId.PREVIEWNET)
288
- * console.log(previewnetChainId) // 297
289
- * const testnetChainId = ledgerIdToEIPChainId(LedgerId.TESTNET)
290
- * console.log(testnetChainId) // 296
291
- * ```
292
- */
293
- export function ledgerIdToEIPChainId(ledgerId) {
294
- for (let i = 0; i < LEDGER_ID_MAPPINGS.length; i++) {
295
- const [ledgerId_, chainId] = LEDGER_ID_MAPPINGS[i];
296
- if (ledgerId === ledgerId_) {
297
- return chainId;
298
- }
299
- }
300
- return DEFAULT_EIP;
301
- }
302
- /**
303
- * Converts a network name to an EIP chain id.
304
- * If no mapping is found, returns the EIP chain id for `LedgerId.LOCAL_NODE`.
305
- *
306
- * @param networkName - The network name (string) to be converted
307
- * @returns A `number` representing the EIP chain id for the provided network name
308
- * @example
309
- * ```ts
310
- * const mainnetChainId = networkNameToEIPChainId('mainnet')
311
- * console.log(mainnetChainId) // 295
312
- * const testnetChainId = networkNameToEIPChainId('testnet')
313
- * console.log(mainnetChainId) // 296
314
- * ```
315
- */
316
- export function networkNameToEIPChainId(networkName) {
317
- const ledgerId = LedgerId.fromString(networkName.toLowerCase());
318
- return ledgerIdToEIPChainId(ledgerId);
319
- }
320
- /**
321
- * Converts a CAIP chain id to a LedgerId object.
322
- *
323
- * If no mapping is found, returns `LedgerId.LOCAL_NODE`.
324
- *
325
- * @param chainId - The CAIP chain ID (string) to be converted
326
- * @returns A `LedgerId` corresponding to the provided CAIP chain ID
327
- * @example
328
- * ```ts
329
- * const previewnetLedgerId = CAIPChainIdToLedgerId(HederaChainId.Previewnet)
330
- * console.log(previewnetLedgerId) // LedgerId.PREVIEWNET
331
- * const testnetLedgerId = CAIPChainIdToLedgerId(HederaChainId.Testnet)
332
- * console.log(testnetLedgerId) // LedgerId.TESTNET
333
- * ```
334
- */
335
- export function CAIPChainIdToLedgerId(chainId) {
336
- for (let i = 0; i < LEDGER_ID_MAPPINGS.length; i++) {
337
- const [ledgerId, _, chainId_] = LEDGER_ID_MAPPINGS[i];
338
- if (chainId === chainId_) {
339
- return ledgerId;
340
- }
341
- }
342
- return DEFAULT_LEDGER_ID;
343
- }
344
- /**
345
- * Converts a LedgerId object to a CAIP chain id.
346
- *
347
- * If no mapping is found, returns the CAIP chain id for `LedgerId.LOCAL_NODE`.
348
- *
349
- * @param ledgerId - The `LedgerId` object to be converted
350
- * @returns A `string` representing the CAIP chain id for the provided `LedgerId`
351
- * @example
352
- * ```ts
353
- * const mainnetChainId = ledgerIdToCAIPChainId(HederaChainId.Mainnet)
354
- * console.log(mainnetChainId) // LedgerId.PREVIEWNET
355
- * const testnetChainId = ledgerIdToCAIPChainId(HederaChainId.Testnet)
356
- * console.log(testnetChainId) // LedgerId.TESTNET
357
- * ```
358
- */
359
- export function ledgerIdToCAIPChainId(ledgerId) {
360
- for (let i = 0; i < LEDGER_ID_MAPPINGS.length; i++) {
361
- const [ledgerId_, _, chainId] = LEDGER_ID_MAPPINGS[i];
362
- if (ledgerId.toString() === ledgerId_.toString()) {
363
- return chainId;
364
- }
365
- }
366
- return DEFAULT_CAIP;
367
- }
368
- /**
369
- * Converts a network name to a CAIP chain id.
370
- *
371
- * If no mapping is found, returns the CAIP chain id for `LedgerId.LOCAL_NODE`.
372
- *
373
- * @param networkName - The network name (string) to be converted
374
- * @returns A `string` representing the CAIP chain id for the provided network name
375
- * @example
376
- * ```ts
377
- * const previewnetChainId = networkNameToCAIPChainId('previewnet')
378
- * console.log(previewnetChainId) // HederaChainId.Previewnet
379
- * const devnetChainId = networkNameToCAIPChainId('devnet')
380
- * console.log(devnetChainId) // HederaChainId.Devnet
381
- * ```
382
- */
383
- export function networkNameToCAIPChainId(networkName) {
384
- const ledgerId = LedgerId.fromString(networkName.toLowerCase());
385
- const chainId = ledgerIdToCAIPChainId(ledgerId);
386
- return chainId;
387
- }
388
- /**
389
- * Create a `ProposalTypes.RequiredNamespaces` object for a given ledgerId.
390
- *
391
- * @param ledgerId - The `LedgerId` for which the namespaces are created
392
- * @param methods - An array of strings representing methods
393
- * @param events - An array of strings representing events
394
- * @returns A `ProposalTypes.RequiredNamespaces` object
395
- */
396
- export const networkNamespaces = (ledgerId, methods, events) => ({
397
- hedera: {
398
- chains: [ledgerIdToCAIPChainId(ledgerId)],
399
- methods,
400
- events,
401
- },
402
- });
403
- /**
404
- * Get the account and ledger from a `SessionTypes.Struct` object.
405
- *
406
- * @param session - The `SessionTypes.Struct` object containing namespaces
407
- * @returns `ProposalTypes.RequiredNamespaces` - an array of objects containing network (LedgerId) and account (AccountId)
408
- */
409
- export const accountAndLedgerFromSession = (session) => {
410
- const hederaNamespace = session.namespaces.hedera;
411
- if (!hederaNamespace)
412
- throw new Error('No hedera namespace found');
413
- return hederaNamespace.accounts.map((account) => {
414
- const [chain, network, acc] = account.split(':');
415
- return {
416
- network: CAIPChainIdToLedgerId(chain + ':' + network),
417
- account: AccountId.fromString(acc),
418
- };
419
- });
420
- };
421
- /**
422
- * Adds an additional signature to an already-signed transaction.
423
- * Uses proto-level manipulation to preserve existing signatures.
424
- */
425
- export async function addSignatureToTransaction(transaction, privateKey) {
426
- const originalBytes = transaction.toBytes();
427
- const originalList = proto.TransactionList.decode(originalBytes);
428
- const firstTransaction = originalList.transactionList[0];
429
- let bodyBytes;
430
- if (firstTransaction.signedTransactionBytes) {
431
- const signedTx = proto.SignedTransaction.decode(firstTransaction.signedTransactionBytes);
432
- bodyBytes = signedTx.bodyBytes;
433
- }
434
- else {
435
- bodyBytes = firstTransaction.bodyBytes;
436
- }
437
- const signature = await privateKey.sign(bodyBytes);
438
- const publicKey = privateKey.publicKey;
439
- const signedTransactionList = originalList.transactionList.map((tx) => {
440
- const newSigPair = publicKey._toProtobufSignature(signature);
441
- if (tx.signedTransactionBytes) {
442
- const signedTx = proto.SignedTransaction.decode(tx.signedTransactionBytes);
443
- const existingSigMap = signedTx.sigMap || proto.SignatureMap.create({});
444
- const mergedSigPairs = [...(existingSigMap.sigPair || []), newSigPair];
445
- const updatedSignedTx = proto.SignedTransaction.encode({
446
- bodyBytes: signedTx.bodyBytes,
447
- sigMap: proto.SignatureMap.create({ sigPair: mergedSigPairs }),
448
- }).finish();
449
- return { signedTransactionBytes: updatedSignedTx };
450
- }
451
- else {
452
- const existingSigMap = tx.sigMap || proto.SignatureMap.create({});
453
- const mergedSigPairs = [...(existingSigMap.sigPair || []), newSigPair];
454
- return Object.assign(Object.assign({}, tx), { sigMap: Object.assign(Object.assign({}, existingSigMap), { sigPair: mergedSigPairs }) });
455
- }
456
- });
457
- const signedBytes = proto.TransactionList.encode({
458
- transactionList: signedTransactionList,
459
- }).finish();
460
- return Transaction.fromBytes(signedBytes);
461
- }
@@ -1,39 +0,0 @@
1
- import { WalletKit, WalletKitTypes } from '@reown/walletkit';
2
- import { SessionTypes } from '@walletconnect/types';
3
- import { Wallet as HederaWallet, AccountId, Transaction, Query } from '@hashgraph/sdk';
4
- import { HederaChainId, HederaSessionEvent, HederaJsonRpcMethod } from '../shared';
5
- import Provider from './provider';
6
- import type { HederaNativeWallet } from './types';
7
- export type { HederaNativeWallet } from './types';
8
- export { default as WalletProvider } from './provider';
9
- export declare class HederaWeb3Wallet extends WalletKit implements HederaNativeWallet {
10
- chains: HederaChainId[] | string[];
11
- methods: string[];
12
- sessionEvents: HederaSessionEvent[] | string[];
13
- constructor(opts: WalletKitTypes.Options, chains?: HederaChainId[] | string[], methods?: string[], sessionEvents?: HederaSessionEvent[] | string[]);
14
- static create(projectId: string, metadata: WalletKitTypes.Metadata, chains?: HederaChainId[], methods?: string[], sessionEvents?: HederaSessionEvent[] | string[]): Promise<HederaWeb3Wallet>;
15
- getHederaWallet(chainId: HederaChainId, accountId: AccountId | string, privateKey: string, _provider?: Provider): HederaWallet;
16
- buildAndApproveSession(accounts: string[], { id, params }: WalletKitTypes.SessionProposal): Promise<SessionTypes.Struct>;
17
- validateParam(name: string, value: any, expectedType: string): void;
18
- parseSessionRequest(event: WalletKitTypes.SessionRequest, shouldThrow?: boolean): {
19
- method: HederaJsonRpcMethod;
20
- chainId: HederaChainId;
21
- id: number;
22
- topic: string;
23
- body?: Transaction | Query<any> | string | Uint8Array | undefined;
24
- accountId?: AccountId;
25
- };
26
- executeSessionRequest(event: WalletKitTypes.SessionRequest, hederaWallet: HederaWallet): Promise<void>;
27
- rejectSessionRequest(event: WalletKitTypes.SessionRequest, error: {
28
- code: number;
29
- message: string;
30
- }): Promise<void>;
31
- hedera_getNodeAddresses(id: number, topic: string, _: any, // ignore this param to be consistent call signature with other functions
32
- signer: HederaWallet): Promise<void>;
33
- hedera_executeTransaction(id: number, topic: string, body: Transaction, signer: HederaWallet): Promise<void>;
34
- hedera_signMessage(id: number, topic: string, body: string, signer: HederaWallet): Promise<void>;
35
- hedera_signAndExecuteQuery(id: number, topic: string, body: Query<any>, signer: HederaWallet): Promise<void>;
36
- hedera_signAndExecuteTransaction(id: number, topic: string, body: Transaction, signer: HederaWallet): Promise<void>;
37
- hedera_signTransaction(id: number, topic: string, body: Uint8Array, signer: HederaWallet): Promise<void>;
38
- }
39
- export default HederaWeb3Wallet;