@kynesyslabs/demosdk 1.0.21 → 1.0.22

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 (177) hide show
  1. package/build/encryption/Cryptography.d.ts +18 -1
  2. package/build/encryption/Cryptography.js +182 -1
  3. package/build/encryption/Cryptography.js.map +1 -1
  4. package/build/encryption/Hashing.d.ts +1 -1
  5. package/build/encryption/Hashing.js +2 -1
  6. package/build/encryption/Hashing.js.map +1 -1
  7. package/build/encryption/index.d.ts +2 -2
  8. package/build/encryption/index.js +4 -2
  9. package/build/encryption/index.js.map +1 -1
  10. package/build/index.d.ts +1 -0
  11. package/build/index.js +2 -1
  12. package/build/index.js.map +1 -1
  13. package/build/multichain/core/solana.d.ts +16 -29
  14. package/build/multichain/core/solana.js +40 -126
  15. package/build/multichain/core/solana.js.map +1 -1
  16. package/build/multichain/core/types/defaultChain.d.ts +0 -18
  17. package/build/multichain/localsdk/index.d.ts +5 -4
  18. package/build/multichain/localsdk/index.js +3 -1
  19. package/build/multichain/localsdk/index.js.map +1 -1
  20. package/build/multichain/localsdk/solana.d.ts +1 -3
  21. package/build/multichain/localsdk/solana.js +5 -10
  22. package/build/multichain/localsdk/solana.js.map +1 -1
  23. package/build/multichain/websdk/index.d.ts +1 -0
  24. package/build/multichain/websdk/index.js +3 -1
  25. package/build/multichain/websdk/index.js.map +1 -1
  26. package/build/multichain/websdk/solana.d.ts +4 -0
  27. package/build/multichain/websdk/solana.js +11 -0
  28. package/build/multichain/websdk/solana.js.map +1 -0
  29. package/build/types/blockchain/Confirmation.d.ts +9 -0
  30. package/build/types/blockchain/Confirmation.js +23 -0
  31. package/build/types/blockchain/Confirmation.js.map +1 -0
  32. package/build/types/blockchain/WalletTypes.d.ts +3 -0
  33. package/build/types/blockchain/WalletTypes.js +3 -0
  34. package/build/types/blockchain/WalletTypes.js.map +1 -0
  35. package/build/utils/getRemoteIP.d.ts +1 -0
  36. package/build/utils/getRemoteIP.js +19 -0
  37. package/build/utils/getRemoteIP.js.map +1 -0
  38. package/build/wallet/Wallet.d.ts +25 -0
  39. package/build/wallet/Wallet.js +94 -0
  40. package/build/wallet/Wallet.js.map +1 -0
  41. package/build/wallet/index.d.ts +1 -0
  42. package/build/wallet/index.js +28 -0
  43. package/build/wallet/index.js.map +1 -0
  44. package/build/websdk/DemosTransactions.d.ts +1 -1
  45. package/build/websdk/DemosTransactions.js +3 -2
  46. package/build/websdk/DemosTransactions.js.map +1 -1
  47. package/build/websdk/demos.d.ts +2 -2
  48. package/package.json +55 -57
  49. package/.eslintignore +0 -6
  50. package/.eslintrc.cjs +0 -31
  51. package/.gitattributes +0 -4
  52. package/.github/workflows/publish.yml +0 -43
  53. package/.github/workflows/test:multichain.yml +0 -35
  54. package/.gitignore +0 -8
  55. package/.prettierrc +0 -13
  56. package/build/tests/multichain/chainProviders.d.ts +0 -29
  57. package/build/tests/multichain/chainProviders.js +0 -34
  58. package/build/tests/multichain/chainProviders.js.map +0 -1
  59. package/build/tests/multichain/evm.test.d.ts +0 -1
  60. package/build/tests/multichain/evm.test.js +0 -53
  61. package/build/tests/multichain/evm.test.js.map +0 -1
  62. package/build/tests/multichain/ibc.test.d.ts +0 -1
  63. package/build/tests/multichain/ibc.test.js +0 -74
  64. package/build/tests/multichain/ibc.test.js.map +0 -1
  65. package/build/tests/multichain/index.d.ts +0 -1
  66. package/build/tests/multichain/index.js +0 -94
  67. package/build/tests/multichain/index.js.map +0 -1
  68. package/build/tests/multichain/multiversx.test.d.ts +0 -1
  69. package/build/tests/multichain/multiversx.test.js +0 -49
  70. package/build/tests/multichain/multiversx.test.js.map +0 -1
  71. package/build/tests/multichain/solana.spec.d.ts +0 -1
  72. package/build/tests/multichain/solana.spec.js +0 -50
  73. package/build/tests/multichain/solana.spec.js.map +0 -1
  74. package/build/tests/multichain/template.test.d.ts +0 -0
  75. package/build/tests/multichain/template.test.js +0 -33
  76. package/build/tests/multichain/template.test.js.map +0 -1
  77. package/build/tests/multichain/xrpl.test.d.ts +0 -1
  78. package/build/tests/multichain/xrpl.test.js +0 -57
  79. package/build/tests/multichain/xrpl.test.js.map +0 -1
  80. package/build/tests/utils/index.d.ts +0 -14
  81. package/build/tests/utils/index.js +0 -34
  82. package/build/tests/utils/index.js.map +0 -1
  83. package/build/tests/utils/wallets.d.ts +0 -21
  84. package/build/tests/utils/wallets.js +0 -48
  85. package/build/tests/utils/wallets.js.map +0 -1
  86. package/build/tests/utils.test.d.ts +0 -1
  87. package/build/tests/utils.test.js +0 -19
  88. package/build/tests/utils.test.js.map +0 -1
  89. package/documentation/multichain/README.md +0 -85
  90. package/documentation/multichain/ibc.md +0 -3
  91. package/documentation/multichain/solana.md +0 -13
  92. package/jest.config.ts +0 -20
  93. package/src/encryption/Cryptography.ts +0 -128
  94. package/src/encryption/FHE/index.ts +0 -35
  95. package/src/encryption/Hashing.ts +0 -20
  96. package/src/encryption/PQC/index.ts +0 -260
  97. package/src/encryption/index.ts +0 -5
  98. package/src/encryption/zK/index.ts +0 -1
  99. package/src/encryption/zK/interactive/index.ts +0 -47
  100. package/src/encryption/zK/primer.ts +0 -71
  101. package/src/index.ts +0 -8
  102. package/src/multichain/archive/btc.ts +0 -72
  103. package/src/multichain/archive/demos.ts +0 -51
  104. package/src/multichain/archive/tron.ts +0 -86
  105. package/src/multichain/archive/xlm.ts +0 -65
  106. package/src/multichain/core/README.md +0 -1
  107. package/src/multichain/core/evm.ts +0 -275
  108. package/src/multichain/core/ibc.ts +0 -318
  109. package/src/multichain/core/index.ts +0 -29
  110. package/src/multichain/core/multiversx.ts +0 -310
  111. package/src/multichain/core/solana.ts +0 -336
  112. package/src/multichain/core/types/defaultChain.ts +0 -254
  113. package/src/multichain/core/types/interfaces.ts +0 -102
  114. package/src/multichain/core/utils.ts +0 -22
  115. package/src/multichain/core/xrp.ts +0 -253
  116. package/src/multichain/index.ts +0 -3
  117. package/src/multichain/localsdk/README.md +0 -1
  118. package/src/multichain/localsdk/evm.ts +0 -77
  119. package/src/multichain/localsdk/ibc.ts +0 -25
  120. package/src/multichain/localsdk/index.ts +0 -4
  121. package/src/multichain/localsdk/multiversx.ts +0 -66
  122. package/src/multichain/localsdk/solana.ts +0 -37
  123. package/src/multichain/localsdk/xrp.ts +0 -56
  124. package/src/multichain/websdk/README.md +0 -1
  125. package/src/multichain/websdk/evm.ts +0 -9
  126. package/src/multichain/websdk/ibc.ts +0 -10
  127. package/src/multichain/websdk/index.ts +0 -4
  128. package/src/multichain/websdk/multiversx.ts +0 -84
  129. package/src/multichain/websdk/xrp.ts +0 -9
  130. package/src/tests/multichain/chainProviders.ts +0 -32
  131. package/src/tests/multichain/evm.test.ts +0 -64
  132. package/src/tests/multichain/ibc.test.ts +0 -93
  133. package/src/tests/multichain/index.ts +0 -105
  134. package/src/tests/multichain/multiversx.test.ts +0 -57
  135. package/src/tests/multichain/solana.spec.ts +0 -56
  136. package/src/tests/multichain/template.test.ts +0 -37
  137. package/src/tests/multichain/xrpl.test.ts +0 -71
  138. package/src/tests/utils/index.ts +0 -34
  139. package/src/tests/utils/wallets.ts +0 -46
  140. package/src/tests/utils.test.ts +0 -21
  141. package/src/types/blockchain/ISignature.ts +0 -6
  142. package/src/types/blockchain/Transaction.ts +0 -34
  143. package/src/types/blockchain/TxFee.ts +0 -5
  144. package/src/types/blockchain/ValidityData.ts +0 -15
  145. package/src/types/blockchain/addressInfo.ts +0 -7
  146. package/src/types/blockchain/blocks.ts +0 -29
  147. package/src/types/blockchain/genesisTypes.ts +0 -39
  148. package/src/types/blockchain/rawTransaction.ts +0 -27
  149. package/src/types/blockchain/statusNative.ts +0 -6
  150. package/src/types/blockchain/statusProperties.ts +0 -8
  151. package/src/types/communication/transmit.ts +0 -27
  152. package/src/types/gls/Operation.ts +0 -25
  153. package/src/types/gls/StateChange.ts +0 -33
  154. package/src/types/index.ts +0 -60
  155. package/src/types/network/ExecutionResult.ts +0 -9
  156. package/src/types/network/SecurityTypes.ts +0 -18
  157. package/src/types/peers/Peer.ts +0 -18
  158. package/src/types/web2/index.ts +0 -76
  159. package/src/types/xm/index.ts +0 -21
  160. package/src/utils/dataManipulation.ts +0 -37
  161. package/src/utils/index.ts +0 -1
  162. package/src/websdk/DemosTransactions.ts +0 -74
  163. package/src/websdk/DemosWebAuth.ts +0 -186
  164. package/src/websdk/Web2Transactions.ts +0 -41
  165. package/src/websdk/XMTransactions.ts +0 -140
  166. package/src/websdk/demos.ts +0 -461
  167. package/src/websdk/index.ts +0 -15
  168. package/src/websdk/rsa.ts +0 -85
  169. package/src/websdk/types/IBuffer.ts +0 -4
  170. package/src/websdk/types/KeyPair.ts +0 -9
  171. package/src/websdk/utils/bufferizer.ts +0 -16
  172. package/src/websdk/utils/forge_converter.ts +0 -72
  173. package/src/websdk/utils/required.ts +0 -44
  174. package/src/websdk/utils/sha256.ts +0 -13
  175. package/src/websdk/utils/skeletons.ts +0 -69
  176. package/tsconfig.json +0 -34
  177. package/yarn.lock +0 -3705
@@ -1,275 +0,0 @@
1
- import {
2
- Contract,
3
- JsonRpcProvider,
4
- TransactionReceipt,
5
- TransactionRequest,
6
- Wallet,
7
- formatEther,
8
- parseEther,
9
- } from 'ethers'
10
- import { DefaultChain, IEVMDefaultChain } from './types/defaultChain'
11
- import { IPayOptions } from './types/interfaces'
12
- import { required } from './utils'
13
-
14
- export class EVM extends DefaultChain implements IEVMDefaultChain {
15
- declare provider: JsonRpcProvider
16
- declare wallet: Wallet
17
-
18
- contracts: Map<string, Contract> = new Map()
19
- isEIP1559: boolean
20
- chainId: number
21
-
22
- constructor(
23
- rpc_url: string = '',
24
- eip1559: boolean = true,
25
- chainId: number = 11155111
26
- ) {
27
- super(rpc_url)
28
- this.name = 'evm'
29
-
30
- this.chainId = chainId
31
- this.isEIP1559 = eip1559
32
-
33
- if (rpc_url) {
34
- this.setRPC(rpc_url)
35
- }
36
- }
37
-
38
- // INFO Set of methods for connecting to an RPC while
39
- // retaining a granular control over the instance status
40
- async setRPC(rpc_url: string) {
41
- this.provider = new JsonRpcProvider(rpc_url)
42
- }
43
-
44
- async connect() {
45
- required(this.provider, 'Provider not connected')
46
-
47
- try {
48
- const network = await this.provider.getNetwork()
49
- this.connected = Boolean(network.name)
50
- } catch (error) {
51
- this.connected = false
52
- }
53
-
54
- return this.connected
55
- }
56
-
57
- // static override async create(
58
- // rpc_url: string = '',
59
- // eip1559: boolean = true,
60
- // chainId: number = 11155111
61
- // ): Promise<EVM> {
62
- // const instance = new EVM(rpc_url, eip1559, chainId)
63
- // if (rpc_url) {
64
- // await instance.connect()
65
- // }
66
- // return instance
67
- // }
68
-
69
- // INFO Connecting a wallet through a private key (string)
70
- // REVIEW should private key be a string or a Buffer?
71
- async connectWallet(privateKey: string) {
72
- required(this.provider, 'Provider not connected')
73
- this.wallet = new Wallet(privateKey, this.provider)
74
- }
75
-
76
- // INFO Signing a transaction
77
- // with a private key or by using our stored wallet
78
- // REVIEW should private key be a string or a Buffer?
79
- async signTransaction(
80
- transaction: TransactionRequest,
81
- options?: {
82
- privateKey?: string
83
- }
84
- ) {
85
- const txs = await this.signTransactions([transaction], options)
86
-
87
- return txs[0]
88
- }
89
-
90
- async signTransactions(
91
- transactions: TransactionRequest[],
92
- options?: {
93
- privateKey?: string
94
- }
95
- ) {
96
- required(this.wallet || options?.privateKey, 'Wallet not connected')
97
-
98
- if (options?.privateKey) {
99
- this.wallet = new Wallet(options.privateKey, this.provider)
100
- }
101
-
102
- // INFO: Get the current nonce
103
- const this_address = this.getAddress()
104
- let currentNonce = await this.provider.getTransactionCount(this_address)
105
-
106
- // INFO: Return a list of signed transactions
107
- return Promise.all(
108
- transactions.map(async (tx) => {
109
- tx.nonce = currentNonce
110
-
111
- // INFO: Increment the nonce for the next transaction
112
- currentNonce++
113
- return this.wallet.signTransaction(tx)
114
- })
115
- )
116
- }
117
-
118
- // SECTION Specific methods
119
-
120
- // REVIEW Should prepare methods be like:
121
- // prepare = { pay(), send(), ...}
122
-
123
- async preparePay(address: string, amount: string) {
124
- const tx = await this.preparePays([{ address, amount }])
125
- return tx[0]
126
- }
127
-
128
- async preparePays(payments: IPayOptions[]) {
129
- required(this.wallet, 'Wallet not connected')
130
-
131
- const baseTx = await this.prepareBaseTxWithType()
132
-
133
- const txs = payments.map((payment) => {
134
- const tx = {
135
- ...baseTx,
136
- to: payment.address,
137
- value: parseEther(payment.amount as string),
138
- }
139
-
140
- // INFO: wallet.checkTransaction was removed in ethers v6
141
- // const checkedTx = this.wallet.checkTransaction(tx);
142
- // console.log('checked', checkedTx);
143
-
144
- return tx
145
- })
146
-
147
- return this.signTransactions(txs)
148
- }
149
-
150
- async prepareTransfer(address: string, amount: string) {
151
- return this.preparePay(address, amount)
152
- }
153
-
154
- async prepareTransfers(payments: IPayOptions[]) {
155
- return this.preparePays(payments)
156
- }
157
-
158
- // SECTION EVM Specific methods
159
- // INFO Generic transaction skeleton for both EIP-1559 and legacy chains
160
- async prepareBaseTxWithType() {
161
- const feeData = await this.provider.getFeeData()
162
- // console.log({ baseFeePerGas: parseInt(feeData.lastBaseFeePerGas._hex, 16) });
163
-
164
- const baseTx = {
165
- // REVIEW: is there a way to get the gas limit from the provider?
166
- gasLimit: 21000,
167
- chainId: this.chainId,
168
- }
169
-
170
- if (this.isEIP1559) {
171
- return {
172
- ...baseTx,
173
- type: 2,
174
- maxFeePerGas: feeData.maxFeePerGas,
175
- maxPriorityFeePerGas: feeData.maxPriorityFeePerGas,
176
- }
177
- }
178
-
179
- return {
180
- ...baseTx,
181
- // INFO: ethers v5 used this line 👇
182
- // gasPrice: feeData.lastBaseFeePerGas
183
- gasPrice: feeData.gasPrice,
184
- }
185
- }
186
-
187
- // INFO Generic empty tx skeleton for this chain
188
- async getEmptyTransaction() {
189
- // NOTE This is a redirection to the prepareBaseTxWithType method as in a evm chain is like that
190
- return await this.prepareBaseTxWithType()
191
- }
192
-
193
- // megabudino was here – return the address of the wallet
194
- getAddress() {
195
- return this.wallet.address
196
- }
197
-
198
- async getBalance(address: string): Promise<string> {
199
- let balance_raw = await this.provider.getBalance(address)
200
- return formatEther(balance_raw)
201
- }
202
-
203
- // SECTION EVM Exclusive methods
204
- async createRawTransaction(tx_data: any): Promise<any> {
205
- throw new Error('Not implemented')
206
- }
207
-
208
- async waitForReceipt(tx_hash: string): Promise<any> {
209
- return await this.provider.getTransactionReceipt(tx_hash)
210
- }
211
- // SECTION Not implemented methods
212
-
213
- async getContractInstance(address: string, abi: string): Promise<Contract> {
214
- console.log(this)
215
- if (!this.provider) {
216
- throw new Error('Provider not connected')
217
- }
218
- let contract = new Contract(address, abi, this.provider)
219
- return contract
220
- }
221
-
222
- // REVIEW Reader for contracts
223
- // ANCHOR MVP
224
- async readFromContract(
225
- contract_instance: Contract,
226
- function_name: string,
227
- args: any
228
- ): Promise<any> {
229
- return await contract_instance[function_name](...args)
230
- }
231
-
232
- // REVIEW Writer for contracts
233
- async writeToContract(
234
- contract_instance: Contract,
235
- function_name: string,
236
- args: any
237
- ): Promise<any> {
238
- required(this.wallet)
239
- return await contract_instance[function_name](...args) // NOTE Ensure it is writeable i guess
240
- }
241
-
242
- // SECTION Event listener
243
- async listenForEvent(
244
- event: string,
245
- contract: string,
246
- abi: any[]
247
- ): Promise<any> {
248
- if (!this.provider) {
249
- throw new Error('Provider not connected')
250
- }
251
- let contractInstance = new Contract(contract, abi, this.provider)
252
- // REVIEW THis could work
253
- return contractInstance.on(event, (data: any) => {
254
- ////console.log(data)
255
- // TODO Do something with the data
256
- })
257
- }
258
-
259
- async listenForAllEvents(contract: string, abi: any[]): Promise<any> {
260
- if (!this.provider) {
261
- throw new Error('Provider not connected')
262
- }
263
- let contractInstance = new Contract(contract, abi, this.provider)
264
- // REVIEW 99% Won't work
265
- return contractInstance.on('*', (data: any) => {
266
- ////console.log(data)
267
- // TODO Do something with the data
268
- })
269
- }
270
-
271
- async disconnect() {
272
- this.resetInstance()
273
- return !this.connected
274
- }
275
- }
@@ -1,318 +0,0 @@
1
- import {
2
- DirectSecp256k1HdWallet,
3
- DirectSecp256k1Wallet,
4
- } from '@cosmjs/proto-signing'
5
- import {
6
- SigningStargateClient,
7
- StargateClient,
8
- calculateFee,
9
- } from '@cosmjs/stargate'
10
- import { TxRaw } from 'cosmjs-types/cosmos/tx/v1beta1/tx'
11
-
12
- import { DefaultChain, IBCDefaultChain } from './types/defaultChain'
13
- import {
14
- IBCConnectWalletOptions,
15
- IBCGetBalanceOptions,
16
- IBCPreparePayOptions,
17
- IBCSignTxOptions,
18
- IBCTransaction,
19
- IPayOptions,
20
- } from './types/interfaces'
21
- import { required } from './utils'
22
-
23
- export class IBC extends DefaultChain implements IBCDefaultChain {
24
- address: string = ''
25
- chainID: string = ''
26
- declare provider: StargateClient
27
- declare wallet: SigningStargateClient
28
- declare signer: DirectSecp256k1Wallet | DirectSecp256k1HdWallet
29
-
30
- // IBC options
31
- gasPrice: string = ''
32
- multiplier: number = 2.0
33
-
34
- constructor(rpc_url: string) {
35
- super(rpc_url)
36
- this.name = 'ibc'
37
-
38
- // INFO: We can't await here, so we call .setRPC in .create()
39
- // if (rpc_url) {
40
- // this.setRPC(rpc_url);
41
- // }
42
- }
43
-
44
- // override async setRpc(rpc_url: string) {
45
- // this.provider = await StargateClient.connect(rpc_url)
46
- // }
47
-
48
- // static override async create(rpc_url: string): Promise<IBC> {
49
- // const instance = new IBC(rpc_url)
50
-
51
- // if (rpc_url) {
52
- // // INFO: Set rpc url and ping it.
53
- // await instance.setRPC(rpc_url)
54
- // await instance.connect()
55
- // }
56
-
57
- // return instance
58
- // }
59
-
60
- // INFO: rpc_url used to avoid overwriting this.provider for test mocking
61
- async connect(rpc_url?: string) {
62
- if (rpc_url !== this.rpc_url) {
63
- this.provider = await StargateClient.connect(this.rpc_url)
64
- }
65
-
66
- try {
67
- const chain_id = await this.provider.getChainId()
68
- this.chainID = chain_id
69
-
70
- this.connected = Boolean(chain_id)
71
- } catch (error) {
72
- this.connected = false
73
- }
74
-
75
- return this.connected
76
- }
77
-
78
- async connectWallet(privateKey: string, options: IBCConnectWalletOptions) {
79
- required(options.prefix, 'Address prefix not provided')
80
- required(options.gasPrice, 'Gas price not provided')
81
-
82
- // INFO: Store the gasPrice for preparePays and other methods
83
- this.gasPrice = options.gasPrice
84
-
85
- // INFO: Check if privateKey is a mnemonic or a private key
86
- const isPrivateKey = privateKey.split(' ').length === 1
87
-
88
- // INFO: Create a signer using the appropriate wallet
89
- if (isPrivateKey) {
90
- // TODO: Test this block!
91
- const buffer = Buffer.from(privateKey, 'hex')
92
- this.signer = await DirectSecp256k1Wallet.fromKey(
93
- buffer,
94
- options.prefix
95
- )
96
- } else {
97
- this.signer = await DirectSecp256k1HdWallet.fromMnemonic(
98
- privateKey,
99
- {
100
- prefix: options.prefix,
101
- }
102
- )
103
- }
104
-
105
- // INFO: Store the address as .getAddress can't be async
106
- const wallet_accounts = await this.signer.getAccounts()
107
- const this_account = wallet_accounts.find((account) =>
108
- account.address.startsWith(options.prefix)
109
- )
110
-
111
- if (this_account) {
112
- this.address = this_account.address
113
- } else {
114
- throw new Error(`No account found for prefix: ${options.prefix}`)
115
- }
116
-
117
- this.wallet = await SigningStargateClient.connectWithSigner(
118
- this.rpc_url,
119
- this.signer
120
- )
121
- return this.wallet
122
- }
123
-
124
- getAddress() {
125
- return this.address
126
- }
127
-
128
- /**
129
- * Get the balance of the address
130
- * @param address The address
131
- * @returns The balance of the address in the specified denomination
132
- */
133
- async getBalance(address: string, options: IBCGetBalanceOptions) {
134
- required(this.provider, 'Provider not connected')
135
-
136
- const coins = await this.provider.getBalance(address, options.denom)
137
- return coins.amount
138
- }
139
-
140
- getEmptyTransaction(): IBCTransaction {
141
- return {
142
- signerAddress: this.getAddress(),
143
- messages: [
144
- {
145
- typeUrl: '/cosmos.bank.v1beta1.MsgSend',
146
- value: {
147
- fromAddress: this.getAddress(),
148
- toAddress: '',
149
- amount: [{ denom: '', amount: '' }],
150
- },
151
- },
152
- ],
153
- // INFO: Fees are to be estimated when filling the tx
154
- fee: null,
155
- memo: '',
156
- }
157
- }
158
-
159
- async preparePay(
160
- receiver: string,
161
- amount: string,
162
- options: IBCPreparePayOptions
163
- ) {
164
- // INFO: Call preparePays with a single payment
165
- const tx = await this.preparePays(
166
- [{ address: receiver, amount }],
167
- options
168
- )
169
- return tx[0]
170
- }
171
-
172
- prepareTransfer(
173
- receiver: string,
174
- amount: string,
175
- options: IBCPreparePayOptions
176
- ) {
177
- return this.preparePay(receiver, amount, options)
178
- }
179
-
180
- /**
181
- * Prepare multiple payments
182
- * @param payments An array of payments
183
- * @param options Specifies the denomination of the token
184
- * @returns An array of signed transactions
185
- */
186
- prepareTransfers(payments: IPayOptions[], options: IBCPreparePayOptions) {
187
- return this.preparePays(payments, options)
188
- }
189
-
190
- /**
191
- * Prepare multiple payments
192
- * @param payments An array of payments
193
- * @param options Specifies the denomination of the token
194
- * @returns An array of signed transactions
195
- */
196
- async preparePays(payments: IPayOptions[], options: IBCPreparePayOptions) {
197
- // INFO: Create an array of transactions
198
- const txs = payments.map((payment) => {
199
- const tx = this.getEmptyTransaction()
200
-
201
- // INFO: Fill the tx
202
- tx.messages[0].value.toAddress = payment.address
203
-
204
- tx.messages[0].value.amount = [
205
- {
206
- denom: options.denom,
207
- amount: payment.amount as string,
208
- },
209
- ]
210
- return tx
211
- })
212
-
213
- // INFO: Estimate the fee for the first tx
214
- const fees = await this.estimateTxFee(txs[0])
215
-
216
- // INFO: Since all txs here are similar, set same fee for all
217
- txs.forEach((tx) => {
218
- tx.fee = fees
219
- })
220
-
221
- // INFO: Sign and return the txs
222
- return await this.signTransactions(txs)
223
- }
224
-
225
- async signTransaction(tx: IBCTransaction, options?: IBCSignTxOptions) {
226
- // INFO: Call signTransactions with a single tx
227
- const signed_txs = await this.signTransactions([tx], options)
228
- return signed_txs[0]
229
- }
230
-
231
- /**
232
- * Estimate the fee for a transaction
233
- * @param tx The transaction
234
- * @returns The estimate fee for the transaction
235
- */
236
- private async estimateTxFee(tx: IBCTransaction) {
237
- const signerAddress = this.getAddress()
238
- const gasEstimate = await this.wallet.simulate(
239
- signerAddress,
240
- tx.messages,
241
- tx.memo
242
- )
243
-
244
- const gasLimit = Math.round(gasEstimate * this.multiplier)
245
- return calculateFee(gasLimit, this.gasPrice)
246
- }
247
-
248
- async signTransactions(
249
- transactions: IBCTransaction[],
250
- options?: IBCSignTxOptions
251
- ) {
252
- required(this.wallet, 'Wallet not connected')
253
-
254
- if (options?.privateKey) {
255
- const { privateKey, ...connectOptions } = options
256
- await this.connectWallet(privateKey, connectOptions)
257
- }
258
-
259
- // NOTE: Sequence management happens here
260
- // INFO: Get account on network
261
- const address = this.getAddress()
262
- const account = await this.wallet.getAccount(address)
263
-
264
- if (!account) {
265
- throw new Error(`Account ${address} not found`)
266
- }
267
-
268
- // INFO: Store the current sequence
269
- let current_sequence = account.sequence
270
-
271
- const signed_txs = transactions.map(async (tx) => {
272
- const signerInfo = {
273
- sequence: current_sequence,
274
- accountNumber: account.accountNumber,
275
- chainId: this.chainID,
276
- }
277
-
278
- if (tx.fee === null) {
279
- // INFO: Throw an error if fee is not set
280
- console.error('Fee not set for tx: ', tx)
281
- throw new Error('Fee not set for tx')
282
- }
283
-
284
- // INFO: Increment the sequence for next round
285
- current_sequence++
286
-
287
- // INFO: Sign the tx
288
- const signed_tx = await this.wallet.sign(
289
- tx.signerAddress,
290
- tx.messages,
291
- tx.fee,
292
- tx.memo,
293
- signerInfo
294
- )
295
-
296
- // INFO: Convert raw tx to bytes array (Ready for broadcast)
297
- const tx_bytes = TxRaw.encode(signed_tx).finish()
298
- return tx_bytes
299
- })
300
-
301
- // INFO: Return the signed transactions
302
- return await Promise.all(signed_txs)
303
- }
304
-
305
- async disconnect() {
306
- this.resetInstance()
307
- this.address = ''
308
- this.gasPrice = ''
309
- return !this.connected
310
- }
311
-
312
- // SECTION: Unimplemented methods
313
- async ibcSend() {
314
- // TODO: Implement IBC send
315
- // REFERENCE: https://github.com/cosmos/cosmjs/blob/33271bc51c/packages/stargate/src/signingstargateclient.ts#L246
316
- throw new Error('Method not implemented')
317
- }
318
- }
@@ -1,29 +0,0 @@
1
- export {
2
- DefaultChain,
3
- IBCDefaultChain,
4
- IDefaultChainLocal,
5
- IDefaultChainWeb,
6
- IEVMDefaultChain,
7
- } from './types/defaultChain'
8
-
9
- export {
10
- EGLDSignTxOptions,
11
- IBCConnectWalletOptions,
12
- IBCGetBalanceOptions,
13
- IBCPreparePayOptions,
14
- IBCSignTxOptions,
15
- IBCTransaction,
16
- IPayOptions,
17
- XmTransactionResponse as TransactionResponse,
18
- } from './types/interfaces'
19
-
20
- export { required } from './utils'
21
-
22
- // SECTION: Chain SDKs
23
- export { EVM } from './evm'
24
- export { IBC } from './ibc'
25
- export { SOLANA } from './solana'
26
- export { MULTIVERSX } from './multiversx'
27
-
28
- // The official XRPL Library is called "xrpl" which conflicts with the name of our XRPL SDK
29
- export { XRPL, xrplGetLastSequence } from './xrp'