@hashgraph/hedera-wallet-connect 2.0.4-canary.f71fa76.0 → 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.
- package/README.md +141 -8
- package/package.json +4 -2
- package/dist/index.d.ts +0 -2
- package/dist/index.js +0 -21
- package/dist/lib/dapp/DAppSigner.d.ts +0 -60
- package/dist/lib/dapp/DAppSigner.js +0 -301
- package/dist/lib/dapp/SessionNotFoundError.d.ts +0 -3
- package/dist/lib/dapp/SessionNotFoundError.js +0 -6
- package/dist/lib/dapp/index.d.ts +0 -216
- package/dist/lib/dapp/index.js +0 -580
- package/dist/lib/index.d.ts +0 -3
- package/dist/lib/index.js +0 -22
- package/dist/lib/shared/chainIds.d.ts +0 -11
- package/dist/lib/shared/chainIds.js +0 -31
- package/dist/lib/shared/errors.d.ts +0 -48
- package/dist/lib/shared/errors.js +0 -51
- package/dist/lib/shared/events.d.ts +0 -7
- package/dist/lib/shared/events.js +0 -27
- package/dist/lib/shared/extensionController.d.ts +0 -21
- package/dist/lib/shared/extensionController.js +0 -42
- package/dist/lib/shared/index.d.ts +0 -7
- package/dist/lib/shared/index.js +0 -26
- package/dist/lib/shared/logger.d.ts +0 -18
- package/dist/lib/shared/logger.js +0 -33
- package/dist/lib/shared/methods.d.ts +0 -12
- package/dist/lib/shared/methods.js +0 -32
- package/dist/lib/shared/payloads.d.ts +0 -101
- package/dist/lib/shared/payloads.js +0 -20
- package/dist/lib/shared/utils.d.ts +0 -275
- package/dist/lib/shared/utils.js +0 -420
- package/dist/lib/wallet/index.d.ts +0 -39
- package/dist/lib/wallet/index.js +0 -306
- package/dist/lib/wallet/provider.d.ts +0 -17
- package/dist/lib/wallet/provider.js +0 -58
- package/dist/lib/wallet/types.d.ts +0 -31
- package/dist/lib/wallet/types.js +0 -20
- package/dist/reown/adapter.d.ts +0 -59
- package/dist/reown/adapter.js +0 -261
- package/dist/reown/connectors/HederaConnector.d.ts +0 -31
- package/dist/reown/connectors/HederaConnector.js +0 -38
- package/dist/reown/connectors/index.d.ts +0 -1
- package/dist/reown/connectors/index.js +0 -1
- package/dist/reown/index.d.ts +0 -4
- package/dist/reown/index.js +0 -4
- package/dist/reown/providers/EIP155Provider.d.ts +0 -32
- package/dist/reown/providers/EIP155Provider.js +0 -187
- package/dist/reown/providers/HIP820Provider.d.ts +0 -26
- package/dist/reown/providers/HIP820Provider.js +0 -69
- package/dist/reown/providers/HederaProvider.d.ts +0 -164
- package/dist/reown/providers/HederaProvider.js +0 -471
- package/dist/reown/providers/index.d.ts +0 -3
- package/dist/reown/providers/index.js +0 -3
- package/dist/reown/utils/account.d.ts +0 -2
- package/dist/reown/utils/account.js +0 -20
- package/dist/reown/utils/chains.d.ts +0 -18
- package/dist/reown/utils/chains.js +0 -152
- package/dist/reown/utils/constants.d.ts +0 -16
- package/dist/reown/utils/constants.js +0 -18
- package/dist/reown/utils/helpers.d.ts +0 -12
- package/dist/reown/utils/helpers.js +0 -25
- package/dist/reown/utils/index.d.ts +0 -5
- package/dist/reown/utils/index.js +0 -5
- package/dist/reown/utils/types.d.ts +0 -9
- package/dist/reown/utils/types.js +0 -1
- package/dist/reown/wallets/EIP155Wallet.d.ts +0 -46
- package/dist/reown/wallets/EIP155Wallet.js +0 -124
- package/dist/reown/wallets/HIP820Wallet.d.ts +0 -53
- package/dist/reown/wallets/HIP820Wallet.js +0 -236
- package/dist/reown/wallets/index.d.ts +0 -2
- package/dist/reown/wallets/index.js +0 -2
|
@@ -1,275 +0,0 @@
|
|
|
1
|
-
import { AccountId, PublicKey, Transaction, LedgerId, Query, SignerSignature } from '@hashgraph/sdk';
|
|
2
|
-
import { ProposalTypes, SessionTypes } from '@walletconnect/types';
|
|
3
|
-
import { proto } from '@hashgraph/proto';
|
|
4
|
-
/**
|
|
5
|
-
* Converts `Transaction` to a Base64-string.
|
|
6
|
-
*
|
|
7
|
-
* Converts a transaction to bytes and then encodes it as a Base64-string. Allow incomplete transaction (HIP-745).
|
|
8
|
-
* @param transaction - Any instance of a class that extends `Transaction`
|
|
9
|
-
* @returns Base64 encoded representation of the input `Transaction` object
|
|
10
|
-
*/
|
|
11
|
-
export declare function transactionToBase64String<T extends Transaction>(transaction: T): string;
|
|
12
|
-
/**
|
|
13
|
-
* Recreates a `Transaction` from a base64 encoded string.
|
|
14
|
-
*
|
|
15
|
-
* Decodes the string to a buffer,
|
|
16
|
-
* then passes to `Transaction.fromBytes`. For greater flexibility, this function uses the base
|
|
17
|
-
* `Transaction` class, but takes an optional type parameter if the type of transaction is known,
|
|
18
|
-
* allowing stronger typeing.
|
|
19
|
-
* @param transactionBytes - a base64 encoded string
|
|
20
|
-
* @returns `Transaction`
|
|
21
|
-
* @example
|
|
22
|
-
* ```ts
|
|
23
|
-
* const txn1 = base64StringToTransaction(bytesString)
|
|
24
|
-
* const txn2 = base64StringToTransaction<TransferTransaction>(bytesString)
|
|
25
|
-
* // txn1 type: Transaction
|
|
26
|
-
* // txn2 type: TransferTransaction
|
|
27
|
-
* ```
|
|
28
|
-
*/
|
|
29
|
-
export declare function base64StringToTransaction<T extends Transaction>(transactionBytes: string): T;
|
|
30
|
-
/**
|
|
31
|
-
* @param transaction - a base64 encoded string of proto.TransactionBody.encode().finish()
|
|
32
|
-
* @param nodeAccountId - an optional `AccountId` to set the node account ID for the transaction
|
|
33
|
-
* @returns `string`
|
|
34
|
-
* */
|
|
35
|
-
export declare function transactionToTransactionBody<T extends Transaction>(transaction: T, nodeAccountId?: AccountId | null): proto.ITransactionBody;
|
|
36
|
-
export declare function transactionBodyToBase64String(transactionBody: proto.ITransactionBody): string;
|
|
37
|
-
/**
|
|
38
|
-
* @param transactionList - a proto.TransactionList object
|
|
39
|
-
* @returns `string`
|
|
40
|
-
* */
|
|
41
|
-
export declare function transactionListToBase64String(transactionList: proto.TransactionList): string;
|
|
42
|
-
/**
|
|
43
|
-
* Extracts the first signature from a proto.SignatureMap object.
|
|
44
|
-
* @param signatureMap - a proto.SignatureMap object
|
|
45
|
-
* @returns `Uint8Array`
|
|
46
|
-
* */
|
|
47
|
-
export declare const extractFirstSignature: (signatureMap: proto.ISignatureMap) => Uint8Array;
|
|
48
|
-
/**
|
|
49
|
-
* Decodes base64 encoded proto.TransactionBody bytes to a `proto.TransactionBody` object.
|
|
50
|
-
*
|
|
51
|
-
* @param transactionBody - a base64 encoded string of proto.TransactionBody.encode().finish()
|
|
52
|
-
* @returns `Transaction`
|
|
53
|
-
*
|
|
54
|
-
* */
|
|
55
|
-
export declare function base64StringToTransactionBody(transactionBody: string): proto.TransactionBody;
|
|
56
|
-
/**
|
|
57
|
-
* Converts a `proto.SignatureMap` to a base64 encoded string.
|
|
58
|
-
*
|
|
59
|
-
* First converts the `proto.SignatureMap` object to a JSON.
|
|
60
|
-
* Then encodes the JSON to a base64 encoded string.
|
|
61
|
-
* @param signatureMap - The `proto.SignatureMap` object to be converted
|
|
62
|
-
* @returns Base64-encoded string representation of the input `proto.SignatureMap`
|
|
63
|
-
*/
|
|
64
|
-
export declare function signatureMapToBase64String(signatureMap: proto.SignatureMap): string;
|
|
65
|
-
/**
|
|
66
|
-
* Converts a Base64-encoded string to a `proto.SignatureMap`.
|
|
67
|
-
* @param base64string - Base64-encoded string
|
|
68
|
-
* @returns `proto.SignatureMap`
|
|
69
|
-
*/
|
|
70
|
-
export declare function base64StringToSignatureMap(base64string: string): proto.SignatureMap;
|
|
71
|
-
/**
|
|
72
|
-
* Encodes the binary data represented by the `Uint8Array` to a Base64 string.
|
|
73
|
-
* @param binary - The `Uint8Array` containing binary data to be converted
|
|
74
|
-
* @returns Base64-encoded string representation of the input `Uint8Array`
|
|
75
|
-
*/
|
|
76
|
-
export declare function Uint8ArrayToBase64String(binary: Uint8Array): string;
|
|
77
|
-
/**
|
|
78
|
-
* Encodes the binary data represented by the `Uint8Array` to a UTF-8 string.
|
|
79
|
-
* @param binary - The `Uint8Array` containing binary data to be converted
|
|
80
|
-
* @returns UTF-8 string representation of the input `Uint8Array`
|
|
81
|
-
*/
|
|
82
|
-
export declare function Uint8ArrayToString(binary: Uint8Array): string;
|
|
83
|
-
/**
|
|
84
|
-
* Converts a Base64-encoded string to a `Uint8Array`.
|
|
85
|
-
* @param base64string - Base64-encoded string to be converted
|
|
86
|
-
* @returns A `Uint8Array` representing the decoded binary data
|
|
87
|
-
*/
|
|
88
|
-
export declare function base64StringToUint8Array(base64string: string): Uint8Array;
|
|
89
|
-
/**
|
|
90
|
-
* Converts a `Query` object to a Base64-encoded string.
|
|
91
|
-
* First utilizes the `toBytes` method of the `Query` instance to obtain its binary `Uint8Array` representation.
|
|
92
|
-
* Then encodes the binary `Uint8Array` to a Base64 string representation.
|
|
93
|
-
* @param query - A `Query` object to be converted
|
|
94
|
-
* @returns Base64 encoded representation of the input `Query` object
|
|
95
|
-
*/
|
|
96
|
-
export declare function queryToBase64String<T, Q extends Query<T>>(query: Q): string;
|
|
97
|
-
/**
|
|
98
|
-
* Recreates a `Query` from a Base64-encoded string. First decodes the string to a buffer,
|
|
99
|
-
* then passes to `Query.fromBytes`. For greater flexibility, this function uses the base
|
|
100
|
-
* `Query` class, but takes an optional type parameter if the type of query is known,
|
|
101
|
-
* allowing stronger typeing.
|
|
102
|
-
* @param bytesString - Base64-encoded string
|
|
103
|
-
* @returns `Query<T>`
|
|
104
|
-
* @example
|
|
105
|
-
* ```ts
|
|
106
|
-
* const query1 = base64StringToQuery(bytesString)
|
|
107
|
-
* const query2 = base64StringToQuery<AccountInfoQuery>(bytesString)
|
|
108
|
-
* // query1 type: Query<any>
|
|
109
|
-
* // query2 type: AccountInfoQuery
|
|
110
|
-
* ```
|
|
111
|
-
*/
|
|
112
|
-
export declare function base64StringToQuery<Q extends Query<any>>(bytesString: string): Q;
|
|
113
|
-
export declare function prefixMessageToSign(message: string): string;
|
|
114
|
-
/**
|
|
115
|
-
* Incorporates additional data (salt) into the message to alter the output signature.
|
|
116
|
-
* This alteration ensures that passing a transaction here for signing will yield an invalid signature,
|
|
117
|
-
* as the additional data modifies the signature text.
|
|
118
|
-
*
|
|
119
|
-
* @param message - A plain text string
|
|
120
|
-
* @returns An array of Uint8Array containing the prepared message for signing
|
|
121
|
-
*/
|
|
122
|
-
export declare function stringToSignerMessage(message: string): Uint8Array[];
|
|
123
|
-
/**
|
|
124
|
-
* This implementation expects a plain text string, which is prefixed and then signed by a wallet.
|
|
125
|
-
* Because the spec calls for 1 message to be signed and 1 signer, this function expects a single
|
|
126
|
-
* signature and used the first item in the sigPair array.
|
|
127
|
-
*
|
|
128
|
-
* @param message - A plain text string
|
|
129
|
-
* @param base64SignatureMap - A base64 encoded proto.SignatureMap object
|
|
130
|
-
* @param publicKey - A PublicKey object use to verify the signature
|
|
131
|
-
* @returns boolean - whether or not the first signature in the sigPair is valid for the message and public key
|
|
132
|
-
*/
|
|
133
|
-
export declare function verifyMessageSignature(message: string, base64SignatureMap: string, publicKey: PublicKey): boolean;
|
|
134
|
-
/**
|
|
135
|
-
* This implementation expects a plain text string, which is prefixed and then signed by a wallet.
|
|
136
|
-
* Because the spec calls for 1 message to be signed and 1 signer, this function expects a single
|
|
137
|
-
* signature and used the first item in the sigPair array.
|
|
138
|
-
*
|
|
139
|
-
* @param message - A plain text string
|
|
140
|
-
* @param signerSignature - A SignerSignature object
|
|
141
|
-
* @param publicKey - A PublicKey object use to verify the signature
|
|
142
|
-
* @returns boolean - whether or not the first signature in the sigPair is valid for the message and public key
|
|
143
|
-
*/
|
|
144
|
-
export declare function verifySignerSignature(message: string, signerSignature: SignerSignature, publicKey: PublicKey): boolean;
|
|
145
|
-
/**
|
|
146
|
-
*
|
|
147
|
-
* https://github.com/hashgraph/hedera-sdk-js/blob/c78512b1d43eedf1d8bf2926a5b7ed3368fc39d1/src/PublicKey.js#L258
|
|
148
|
-
* 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
|
|
149
|
-
* @param signerSignatures - An array of `SignerSignature` objects
|
|
150
|
-
* @returns `proto.SignatureMap` object
|
|
151
|
-
*/
|
|
152
|
-
export declare function signerSignaturesToSignatureMap(signerSignatures: SignerSignature[]): proto.SignatureMap;
|
|
153
|
-
/**
|
|
154
|
-
* A mapping of `LedgerId` to EIP chain id and CAIP-2 network name.
|
|
155
|
-
*
|
|
156
|
-
* Structure: [`LedgerId`, `number` (EIP155 chain id), `string` (CAIP-2 chain id)][]
|
|
157
|
-
*
|
|
158
|
-
* @see {@link https://namespaces.chainagnostic.org/hedera/README | Hedera Namespaces}
|
|
159
|
-
* @see {@link https://hips.hedera.com/hip/hip-30 | CAIP Identifiers for the Hedera Network (HIP-30)}
|
|
160
|
-
*/
|
|
161
|
-
export declare const LEDGER_ID_MAPPINGS: [LedgerId, number, string][];
|
|
162
|
-
/**
|
|
163
|
-
* Converts an EIP chain id to a LedgerId object.
|
|
164
|
-
*
|
|
165
|
-
* If no mapping is found, returns `LedgerId.LOCAL_NODE`.
|
|
166
|
-
*
|
|
167
|
-
* @param chainId - The EIP chain ID (number) to be converted
|
|
168
|
-
* @returns A `LedgerId` corresponding to the provided chain ID
|
|
169
|
-
* @example
|
|
170
|
-
* ```ts
|
|
171
|
-
* const localnodeLedgerId = EIPChainIdToLedgerId(298)
|
|
172
|
-
* console.log(localnodeLedgerId) // LedgerId.LOCAL_NODE
|
|
173
|
-
* const mainnetLedgerId = EIPChainIdToLedgerId(295)
|
|
174
|
-
* console.log(mainnetLedgerId) // LedgerId.MAINNET
|
|
175
|
-
* ```
|
|
176
|
-
*/
|
|
177
|
-
export declare function EIPChainIdToLedgerId(chainId: number): LedgerId;
|
|
178
|
-
/**
|
|
179
|
-
* Converts a LedgerId object to an EIP chain id.
|
|
180
|
-
*
|
|
181
|
-
* If no mapping is found, returns the EIP chain id for `LedgerId.LOCAL_NODE`.
|
|
182
|
-
*
|
|
183
|
-
* @param ledgerId - The `LedgerId` object to be converted
|
|
184
|
-
* @returns A `number` representing the EIP chain id for the provided `LedgerId`
|
|
185
|
-
* @example
|
|
186
|
-
* ```ts
|
|
187
|
-
* const previewnetChainId = ledgerIdToEIPChainId(LedgerId.PREVIEWNET)
|
|
188
|
-
* console.log(previewnetChainId) // 297
|
|
189
|
-
* const testnetChainId = ledgerIdToEIPChainId(LedgerId.TESTNET)
|
|
190
|
-
* console.log(testnetChainId) // 296
|
|
191
|
-
* ```
|
|
192
|
-
*/
|
|
193
|
-
export declare function ledgerIdToEIPChainId(ledgerId: LedgerId): number;
|
|
194
|
-
/**
|
|
195
|
-
* Converts a network name to an EIP chain id.
|
|
196
|
-
* If no mapping is found, returns the EIP chain id for `LedgerId.LOCAL_NODE`.
|
|
197
|
-
*
|
|
198
|
-
* @param networkName - The network name (string) to be converted
|
|
199
|
-
* @returns A `number` representing the EIP chain id for the provided network name
|
|
200
|
-
* @example
|
|
201
|
-
* ```ts
|
|
202
|
-
* const mainnetChainId = networkNameToEIPChainId('mainnet')
|
|
203
|
-
* console.log(mainnetChainId) // 295
|
|
204
|
-
* const testnetChainId = networkNameToEIPChainId('testnet')
|
|
205
|
-
* console.log(mainnetChainId) // 296
|
|
206
|
-
* ```
|
|
207
|
-
*/
|
|
208
|
-
export declare function networkNameToEIPChainId(networkName: string): number;
|
|
209
|
-
/**
|
|
210
|
-
* Converts a CAIP chain id to a LedgerId object.
|
|
211
|
-
*
|
|
212
|
-
* If no mapping is found, returns `LedgerId.LOCAL_NODE`.
|
|
213
|
-
*
|
|
214
|
-
* @param chainId - The CAIP chain ID (string) to be converted
|
|
215
|
-
* @returns A `LedgerId` corresponding to the provided CAIP chain ID
|
|
216
|
-
* @example
|
|
217
|
-
* ```ts
|
|
218
|
-
* const previewnetLedgerId = CAIPChainIdToLedgerId(HederaChainId.Previewnet)
|
|
219
|
-
* console.log(previewnetLedgerId) // LedgerId.PREVIEWNET
|
|
220
|
-
* const testnetLedgerId = CAIPChainIdToLedgerId(HederaChainId.Testnet)
|
|
221
|
-
* console.log(testnetLedgerId) // LedgerId.TESTNET
|
|
222
|
-
* ```
|
|
223
|
-
*/
|
|
224
|
-
export declare function CAIPChainIdToLedgerId(chainId: string): LedgerId;
|
|
225
|
-
/**
|
|
226
|
-
* Converts a LedgerId object to a CAIP chain id.
|
|
227
|
-
*
|
|
228
|
-
* If no mapping is found, returns the CAIP chain id for `LedgerId.LOCAL_NODE`.
|
|
229
|
-
*
|
|
230
|
-
* @param ledgerId - The `LedgerId` object to be converted
|
|
231
|
-
* @returns A `string` representing the CAIP chain id for the provided `LedgerId`
|
|
232
|
-
* @example
|
|
233
|
-
* ```ts
|
|
234
|
-
* const mainnetChainId = ledgerIdToCAIPChainId(HederaChainId.Mainnet)
|
|
235
|
-
* console.log(mainnetChainId) // LedgerId.PREVIEWNET
|
|
236
|
-
* const testnetChainId = ledgerIdToCAIPChainId(HederaChainId.Testnet)
|
|
237
|
-
* console.log(testnetChainId) // LedgerId.TESTNET
|
|
238
|
-
* ```
|
|
239
|
-
*/
|
|
240
|
-
export declare function ledgerIdToCAIPChainId(ledgerId: LedgerId): string;
|
|
241
|
-
/**
|
|
242
|
-
* Converts a network name to a CAIP chain id.
|
|
243
|
-
*
|
|
244
|
-
* If no mapping is found, returns the CAIP chain id for `LedgerId.LOCAL_NODE`.
|
|
245
|
-
*
|
|
246
|
-
* @param networkName - The network name (string) to be converted
|
|
247
|
-
* @returns A `string` representing the CAIP chain id for the provided network name
|
|
248
|
-
* @example
|
|
249
|
-
* ```ts
|
|
250
|
-
* const previewnetChainId = networkNameToCAIPChainId('previewnet')
|
|
251
|
-
* console.log(previewnetChainId) // HederaChainId.Previewnet
|
|
252
|
-
* const devnetChainId = networkNameToCAIPChainId('devnet')
|
|
253
|
-
* console.log(devnetChainId) // HederaChainId.Devnet
|
|
254
|
-
* ```
|
|
255
|
-
*/
|
|
256
|
-
export declare function networkNameToCAIPChainId(networkName: string): string;
|
|
257
|
-
/**
|
|
258
|
-
* Create a `ProposalTypes.RequiredNamespaces` object for a given ledgerId.
|
|
259
|
-
*
|
|
260
|
-
* @param ledgerId - The `LedgerId` for which the namespaces are created
|
|
261
|
-
* @param methods - An array of strings representing methods
|
|
262
|
-
* @param events - An array of strings representing events
|
|
263
|
-
* @returns A `ProposalTypes.RequiredNamespaces` object
|
|
264
|
-
*/
|
|
265
|
-
export declare const networkNamespaces: (ledgerId: LedgerId, methods: string[], events: string[]) => ProposalTypes.RequiredNamespaces;
|
|
266
|
-
/**
|
|
267
|
-
* Get the account and ledger from a `SessionTypes.Struct` object.
|
|
268
|
-
*
|
|
269
|
-
* @param session - The `SessionTypes.Struct` object containing namespaces
|
|
270
|
-
* @returns `ProposalTypes.RequiredNamespaces` - an array of objects containing network (LedgerId) and account (AccountId)
|
|
271
|
-
*/
|
|
272
|
-
export declare const accountAndLedgerFromSession: (session: SessionTypes.Struct) => {
|
|
273
|
-
network: LedgerId;
|
|
274
|
-
account: AccountId;
|
|
275
|
-
}[];
|
package/dist/lib/shared/utils.js
DELETED
|
@@ -1,420 +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
|
-
};
|