@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,25 +0,0 @@
1
- import { IBC as IBCCore, IDefaultChainLocal, TransactionResponse, required } from '@/multichain/core'
2
-
3
- export class IBC extends IBCCore implements IDefaultChainLocal {
4
- constructor(rpc_url: string) {
5
- super(rpc_url)
6
- }
7
-
8
- async sendTransaction(signed_tx: Uint8Array): Promise<TransactionResponse> {
9
- required(this.wallet, 'Wallet not connected')
10
-
11
- const hash = await this.wallet.broadcastTxSync(signed_tx)
12
- return {
13
- hash,
14
- result: 'success',
15
- }
16
- }
17
-
18
- async getInfo(): Promise<string> {
19
- throw new Error('Method not implemented.')
20
- }
21
-
22
- async createWallet(password?: string) {
23
- throw new Error('Method not implemented.')
24
- }
25
- }
@@ -1,4 +0,0 @@
1
- export { XRPL } from './xrp'
2
- export { EVM } from './evm'
3
- export { IBC } from './ibc'
4
- export { MULTIVERSX } from './multiversx'
@@ -1,66 +0,0 @@
1
- import {
2
- MULTIVERSX as EGLDCore,
3
- IDefaultChainLocal,
4
- TransactionResponse,
5
- required,
6
- } from '@/multichain/core'
7
-
8
- import { IPlainTransactionObject, Transaction } from '@multiversx/sdk-core'
9
- import { Mnemonic, UserWallet } from '@multiversx/sdk-wallet'
10
-
11
- export class MULTIVERSX extends EGLDCore implements IDefaultChainLocal {
12
- constructor(rpc_url: string) {
13
- super(rpc_url)
14
- }
15
-
16
- async getInfo() {
17
- throw new Error('Method not implemented.')
18
- }
19
-
20
- async createWallet(password: string, addressIndex?: number) {
21
- required(password, 'Password is required to encrypt the key file')
22
-
23
- const mnemonics = Mnemonic.generate()
24
-
25
- const words = mnemonics.getWords()
26
- const words_with_index = words.map((word, index) => index + '. ' + word)
27
-
28
- const secretKey = mnemonics.deriveKey(addressIndex, password)
29
- const wallet = UserWallet.fromSecretKey({ secretKey, password })
30
-
31
- const jsonWallet = wallet.toJSON()
32
-
33
- // NOTE: .bech32 is the address property
34
- const walletAddress: string = jsonWallet.bech32
35
-
36
- // TODO Return downloadable mnemonics & json files
37
- return {
38
- mnemonics: words,
39
- address: walletAddress,
40
- mnemonics_txt: words_with_index.join(''),
41
- wallet_keyfile: JSON.stringify(jsonWallet, null, 2),
42
- }
43
- }
44
-
45
- async sendTransaction(raw_tx: Transaction | IPlainTransactionObject) :Promise<TransactionResponse> {
46
- required(this.provider, 'Provider not connected')
47
- let signed_tx: Transaction
48
-
49
- // INFO: raw_tx is a plain object when it comes from the frontend
50
- if (!(raw_tx instanceof Transaction)) {
51
- signed_tx = Transaction.fromPlainObject(raw_tx)
52
- } else {
53
- signed_tx = raw_tx
54
- }
55
-
56
- // INFO: The provider can also send a list of transactions
57
- const tx_hash = await this.provider.sendTransaction(
58
- signed_tx as Transaction
59
- )
60
-
61
- return {
62
- result: 'success',
63
- hash: tx_hash,
64
- }
65
- }
66
- }
@@ -1,37 +0,0 @@
1
- import { Keypair, Transaction } from "@solana/web3.js"
2
- import { IDefaultChainLocal, SOLANA as SolanaCore, TransactionResponse } from "../core"
3
-
4
- export class SOLANA extends SolanaCore implements IDefaultChainLocal {
5
- constructor(rpc_url: string) {
6
- super(rpc_url)
7
- }
8
-
9
- async sendTransaction(
10
- signed_tx: Transaction,
11
- ): Promise<TransactionResponse> {
12
- const tx = signed_tx.serialize()
13
-
14
- try {
15
- const txhash = await this.provider.sendRawTransaction(tx)
16
- return {
17
- result: "success",
18
- hash: txhash,
19
- }
20
- } catch (error) {
21
- return {
22
- result: "error",
23
- error: error,
24
- }
25
- }
26
- }
27
-
28
- async getInfo(){
29
- throw new Error("Method not implemented.")
30
- }
31
-
32
- async createWallet(){
33
- const keypair = Keypair.generate()
34
- // REVIEW: Should
35
- throw new Error("Method not implemented.")
36
- }
37
- }
@@ -1,56 +0,0 @@
1
- import { IDefaultChainLocal, TransactionResponse, XRPL as XRPLSdkCore } from '@/multichain/core'
2
- import * as xrpl from 'xrpl'
3
-
4
- export class XRPL extends XRPLSdkCore implements IDefaultChainLocal {
5
- constructor(rpc_url: string) {
6
- super(rpc_url)
7
- }
8
-
9
- // INFO Creates a new wallet
10
- async createWallet(password: string) {
11
- // TODO: Review this implementation
12
- this.wallet = xrpl.Wallet.generate()
13
- }
14
-
15
- async getInfo() {
16
- throw new Error('Method not implemented.')
17
- }
18
-
19
- // INFO Generic account info
20
- async accountInfo(address: string): Promise<xrpl.AccountInfoResponse> {
21
- return await this.provider.request({
22
- command: 'account_info',
23
- account: address,
24
- ledger_index: 'validated',
25
- })
26
- }
27
-
28
- // INFO Generic sign, send and await (if not specified) a tx
29
- async sendTransaction(signed: any, wait: boolean = false) :Promise<TransactionResponse> {
30
- // Sending the tx
31
- console.log('[xrpl] sendtransaction')
32
-
33
- if (wait) {
34
- const res = await this.provider.submitAndWait(signed.tx_blob)
35
-
36
- // NOTE: The return type here might need to change
37
- return {
38
- result: 'success',
39
- hash: res.result.hash,
40
- }
41
- } else {
42
- const res = await this.provider.submit(signed.tx_blob)
43
-
44
- return {
45
- result: res.result.accepted ? 'success' : 'error',
46
- hash: res.result.tx_json.hash,
47
- extra: {
48
- accepted: res.result.accepted,
49
- result: res.result.engine_result,
50
- result_code: res.result.engine_result_code,
51
- result_message: res.result.engine_result_message,
52
- },
53
- }
54
- }
55
- }
56
- }
@@ -1 +0,0 @@
1
- # Multichain Web SDK
@@ -1,9 +0,0 @@
1
- import { EVM as EVMCoreSDK, IDefaultChainWeb } from '@/multichain/core'
2
-
3
- export class EVM extends EVMCoreSDK implements IDefaultChainWeb {
4
- constructor(rpc_url: string) {
5
- super(rpc_url)
6
- }
7
-
8
- // INFO: Add custom methods here
9
- }
@@ -1,10 +0,0 @@
1
- import { IBC as IBCCoreSDK, IDefaultChainWeb } from '@/multichain/core'
2
-
3
- // INFO: Websdk is the same as the core sdk
4
- export class IBC extends IBCCoreSDK implements IDefaultChainWeb {
5
- constructor(rpc_url: string) {
6
- super(rpc_url)
7
- }
8
-
9
- // INFO: Add custom methods here
10
- }
@@ -1,4 +0,0 @@
1
- export { XRPL } from './xrp'
2
- export { EVM } from './evm'
3
- export { IBC } from './ibc'
4
- export { MULTIVERSX } from './multiversx'
@@ -1,84 +0,0 @@
1
- import {
2
- MULTIVERSX as EGLDCore,
3
- EGLDSignTxOptions,
4
- IDefaultChainWeb,
5
- required,
6
- } from '@/multichain/core'
7
- import { IPlainTransactionObject, Transaction } from '@multiversx/sdk-core'
8
- import { ExtensionProvider } from '@multiversx/sdk-extension-provider'
9
- import { UserSigner } from '@multiversx/sdk-wallet'
10
-
11
- export class MULTIVERSX extends EGLDCore implements IDefaultChainWeb {
12
- constructor(rpc_url: string) {
13
- super(rpc_url)
14
- }
15
-
16
- /**
17
- * Connect a Multiversx wallet. Pass the `keyFile` JSON string as the `privateKey` and its `password` to override the De-Fi wallet prompt.
18
- */
19
- // @ts-expect-error // INFO: Return type error
20
- override async connectWallet(
21
- privateKey?: string,
22
- options?: {
23
- password: string
24
- }
25
- ) {
26
- if (privateKey && options?.password) {
27
- await this.connectKeyFileWallet(privateKey, options.password)
28
- return this.wallet as UserSigner
29
- }
30
-
31
- this.wallet = ExtensionProvider.getInstance()
32
- await this.wallet.init()
33
-
34
- // INFO: wallet.isInitialized() checks if the wallet is installed.
35
- // It's equivalent to checking for `window.elrondWallet` object which is injected by the extension
36
- // LINK to src: https://github.com/multiversx/mx-sdk-js-extension-provider/blob/36518d0fe0b295de8d2b977727f0c30cdc014c78/src/extensionProvider.ts#L45
37
-
38
- if (!this.wallet.isInitialized()) {
39
- throw new Error(
40
- 'Wallet not detected. Is the MultiversX DeFi Wallet extension installed?'
41
- )
42
- }
43
-
44
- await this.wallet.login()
45
- return this.wallet
46
- }
47
-
48
- override async signTransactions(
49
- transactions: Transaction[],
50
- options?: EGLDSignTxOptions
51
- ): Promise<IPlainTransactionObject[]> {
52
- required(this.wallet || options?.privateKey, 'Wallet not connected')
53
-
54
- // INFO: Override wallet connection
55
- if (options?.privateKey) {
56
- await this.connectWallet(options.privateKey, {
57
- password: options.password,
58
- })
59
- }
60
-
61
- transactions = await this.addTxNonces(transactions)
62
-
63
- try {
64
- // INFO: When wallet is loaded from Extension
65
- transactions = await (
66
- this.wallet as ExtensionProvider
67
- ).signTransactions(transactions)
68
- } catch (error) {
69
- for (const tx of transactions) {
70
- const serializedTx = tx.serializeForSigning()
71
- const txSign = await (this.wallet as UserSigner).sign(
72
- serializedTx
73
- )
74
-
75
- tx.applySignature(txSign)
76
- }
77
- }
78
-
79
- return transactions.map((tx) => {
80
- // INFO: Return plain objects
81
- return tx.toSendable()
82
- })
83
- }
84
- }
@@ -1,9 +0,0 @@
1
- import { IDefaultChainWeb, XRPL as XRPLCoreSDK } from '@/multichain/core'
2
-
3
- export class XRPL extends XRPLCoreSDK implements IDefaultChainWeb {
4
- constructor(rpc_url: string) {
5
- super(rpc_url)
6
- }
7
-
8
- // INFO: Add custom methods here
9
- }
@@ -1,32 +0,0 @@
1
- import { clusterApiUrl } from "@solana/web3.js"
2
-
3
- export default {
4
- eth: {
5
- mainnet: "https://rpc.ankr.com/eth",
6
- sepolia: "https://rpc.ankr.com/eth_sepolia",
7
- goerli: "https://ethereum-goerli.publicnode.com",
8
- },
9
- xrpl: {
10
- mainnet: "wss://s1.ripple.com:51234/",
11
- testnet: "wss://s.altnet.rippletest.net:51233/",
12
- },
13
- egld: {
14
- mainnet: "https://api.multiversx.com",
15
- testnet: "https://testnet-api.multiversx.com",
16
- },
17
- filecoin: {
18
- mainnet: "https://rpc.ankr.com/filecoin",
19
- calibration: "https://rpc.ankr.com/filecoin_testnet",
20
- testnet: "https://rpc.ankr.com/filecoin_testnet",
21
- },
22
- ibc: {
23
- mainnet: "",
24
- // Stargaze 👇
25
- testnet: "https://rpc.elgafar-1.stargaze-apis.com",
26
- },
27
- solana: {
28
- mainnet: clusterApiUrl("mainnet-beta"),
29
- // using devnet as testnet faucet is broken 👇
30
- devnet: clusterApiUrl("devnet"),
31
- },
32
- }
@@ -1,64 +0,0 @@
1
- import { Transaction } from 'ethers'
2
-
3
- import { EVM } from '@/multichain/core'
4
- import { getSampleTranfers, verifyNumberOrder } from '../utils'
5
- import { wallets } from '../utils/wallets'
6
- import chainProviders from './chainProviders'
7
-
8
- describe('EVM CHAIN TESTS', () => {
9
- const instance = new EVM(chainProviders.eth.sepolia)
10
-
11
- beforeAll(async () => {
12
- const connected = await instance.connect()
13
- await instance.connectWallet(wallets.evm.wallet)
14
-
15
- expect(connected).toBe(true)
16
- })
17
-
18
- test('preparePay returns a signed transaction', async () => {
19
- const address = instance.getAddress()
20
- const signed_tx = await instance.preparePay(address, '1')
21
-
22
- // INFO: Reconstruct the transaction from the signed transaction
23
- const tx = Transaction.from(signed_tx)
24
-
25
- // INFO: the r parameter is 32 bytes long
26
- // INFO: We assert with 66 because it's a hex string
27
- // (2 characters per byte + 2 for the 0x prefix)
28
- expect(tx.signature?.r.length).toEqual(66)
29
- })
30
-
31
- test('A tx is signed with the ledger nonce', async () => {
32
- const address = instance.getAddress()
33
- const ledgerNonce = await instance.provider.getTransactionCount(address)
34
-
35
- const signed_tx = await instance.preparePay(address, '1')
36
-
37
- // INFO: Reconstruct the transaction from the signed payload
38
- const tx = Transaction.from(signed_tx)
39
-
40
- expect(tx.nonce).toEqual(ledgerNonce)
41
- })
42
-
43
- test('Transactions are signed with increasing nonces', async () => {
44
- const address = instance.getAddress()
45
- const transfers = getSampleTranfers(address)
46
- const signed_txs = await instance.preparePays(transfers)
47
-
48
- const txs = signed_txs.map((tx) => Transaction.from(tx))
49
- const nonces_sorted = verifyNumberOrder(txs, 'nonce')
50
-
51
- expect(nonces_sorted).toBe(true)
52
- })
53
-
54
- test('Transactions are signed in order of appearance', async () => {
55
- const address = instance.getAddress()
56
- const transfers = getSampleTranfers(address)
57
- const signed_txs = await instance.preparePays(transfers)
58
-
59
- const txs = signed_txs.map((tx) => Transaction.from(tx))
60
- const values_sorted = verifyNumberOrder(txs, 'value')
61
-
62
- expect(values_sorted).toBe(true)
63
- })
64
- })
@@ -1,93 +0,0 @@
1
- import { decodeTxRaw, Registry } from '@cosmjs/proto-signing'
2
- import { defaultRegistryTypes } from '@cosmjs/stargate'
3
-
4
- import { IBC } from '@/multichain/core'
5
- import { getSampleTranfers, verifyNumberOrder } from '../utils'
6
- import { wallets } from '../utils/wallets'
7
- import chainProviders from './chainProviders'
8
-
9
- describe('IBC CHAIN TESTS', () => {
10
- let instance: IBC
11
- const chain_prefix = 'stars'
12
- const token_denom = 'ustars'
13
- const payment_options = { denom: token_denom }
14
-
15
- beforeAll(async () => {
16
- instance = await IBC.create(chainProviders.ibc.testnet)
17
- await instance.connectWallet(wallets.ibc.wallet, {
18
- prefix: chain_prefix,
19
- gasPrice: '0.012ustars',
20
- })
21
-
22
- expect(instance.connected).toBe(true)
23
- })
24
-
25
- test('preparePay returns a signed tx', async () => {
26
- const address = instance.getAddress()
27
- const tx_bytes = await instance.preparePay(
28
- address,
29
- '1',
30
- payment_options
31
- )
32
-
33
- // INFO: Decode the bytes to get the raw tx
34
- // LINK: https://cosmos.github.io/cosmjs/latest/proto-signing/modules.html#decodeTxRaw
35
- // Ctrl + click decodeTxRaw to see the decoded raw Tx interface
36
- const raw_tx = decodeTxRaw(tx_bytes)
37
- expect(raw_tx.signatures.length == 1).toBe(true)
38
- })
39
-
40
- test('A tx is signed with the ledger nonce', async () => {
41
- const address = instance.getAddress()
42
-
43
- // INFO: Get the current ledger sequence
44
- const ledger_sequence = (await instance.provider.getAccount(address))
45
- ?.sequence
46
-
47
- // INFO: Sign and decode the tx
48
- const tx_bytes = await instance.preparePay(
49
- address,
50
- '1',
51
- payment_options
52
- )
53
- const raw_tx = decodeTxRaw(tx_bytes)
54
-
55
- // INFO: Compare the sequences
56
- const tx_sequence = Number(raw_tx.authInfo.signerInfos[0].sequence)
57
- expect(tx_sequence).toEqual(ledger_sequence)
58
- })
59
-
60
- test('Transactions are signed with increasing nonces', async () => {
61
- const address = instance.getAddress()
62
- const payments = getSampleTranfers(address)
63
- const signed_txs = await instance.preparePays(payments, payment_options)
64
-
65
- // INFO: Get a list of objects containing the sequences
66
- const signer_infos = signed_txs.map((tx_bytes) => {
67
- const tx = decodeTxRaw(tx_bytes)
68
- return tx.authInfo.signerInfos[0]
69
- })
70
-
71
- const is_sorted = verifyNumberOrder(signer_infos, 'sequence')
72
- expect(is_sorted).toBe(true)
73
- })
74
-
75
- test('Transactions are signed in order of appearance', async () => {
76
- const address = instance.getAddress()
77
- const payments = getSampleTranfers(address)
78
- const signed_txs = await instance.preparePays(payments, payment_options)
79
-
80
- const amounts = signed_txs.map((tx_bytes) => {
81
- const tx = decodeTxRaw(tx_bytes)
82
-
83
- // INFO: Decode the message to get the amount
84
- // LINK: https://cosmos.github.io/cosmjs/latest/proto-signing/classes/Registry.html
85
- const registry = new Registry(defaultRegistryTypes)
86
- const message = registry.decode(tx.body.messages[0])
87
- return message['amount'][0]
88
- })
89
-
90
- const is_sorted = verifyNumberOrder(amounts, 'amount')
91
- expect(is_sorted).toBe(true)
92
- })
93
- })
@@ -1,105 +0,0 @@
1
- /*
2
- These are generic tests for each chain.
3
- They make sure all the sdks behave the same way.
4
- */
5
-
6
- import { JsonRpcProvider } from 'ethers'
7
- import { Client } from 'xrpl'
8
-
9
- import { StargateClient } from '@cosmjs/stargate'
10
- import { INetworkProvider } from '@multiversx/sdk-network-providers/out/interface'
11
-
12
- import { EVM, IBC, MULTIVERSX, XRPL } from '@/multichain/core'
13
- import chainProviders from './chainProviders'
14
-
15
- // INFO: Chains and their RPCs
16
- const chains = [
17
- {
18
- name: 'EGLD',
19
- sdk: MULTIVERSX,
20
- rpc: chainProviders.egld.testnet,
21
- },
22
- {
23
- name: 'XRPL',
24
- sdk: XRPL,
25
- rpc: chainProviders.xrpl.testnet,
26
- },
27
- {
28
- name: 'EVM',
29
- sdk: EVM,
30
- rpc: chainProviders.eth.sepolia,
31
- },
32
- {
33
- name: 'IBC',
34
- sdk: IBC,
35
- rpc: chainProviders.ibc.testnet,
36
- },
37
- ]
38
-
39
- // INFO: For loop to test each chain sdk
40
- describe.each(chains)('GENERIC CHAIN TESTS › $name', ({ name, rpc, sdk }) => {
41
- let instance: IBC | EVM | MULTIVERSX | XRPL
42
-
43
- beforeAll(async () => {
44
- // @ts-expect-error
45
- // Caused by the use of generics to determine the output of sdk.create
46
- instance = await sdk.create(rpc)
47
- })
48
-
49
- test('Chain has a valid name', () => {
50
- expect(instance.name).toBeTruthy()
51
- })
52
-
53
- test('Testnet RPC is up', async () => {
54
- const connected = await instance.connect()
55
-
56
- expect(instance.connected).toBe(true)
57
- expect(connected).toBe(true)
58
-
59
- // INFO: Max timeout for this test
60
- })
61
-
62
- test('On connect failure, .connected is false', async () => {
63
- const mock = jest.fn().mockRejectedValue(new Error('mock error'))
64
-
65
- // INFO: Mock the provider method that connects to the RPC to throw an error
66
- switch (name) {
67
- case 'EVM':
68
- ;(instance.provider as JsonRpcProvider).getNetwork = mock
69
- break
70
- case 'IBC':
71
- ;(instance.provider as StargateClient).getChainId = mock
72
- break
73
- case 'XRPL':
74
- ;(instance.provider as Client).connect = mock
75
- break
76
- case 'EGLD':
77
- ;(instance.provider as INetworkProvider).getNetworkConfig = mock
78
- break
79
-
80
- default:
81
- expect(true).toBe(false)
82
- }
83
-
84
- let isConnected: boolean
85
-
86
- if (name === 'IBC') {
87
- isConnected = await (instance as IBC).connect(instance.rpc_url)
88
- } else {
89
- // @ts-expect-error
90
- isConnected = await instance.connect(false)
91
- }
92
-
93
- expect(isConnected).toBe(false)
94
- })
95
-
96
- test('On disconnect, provider is reset', async () => {
97
- // INFO: Disconnecting allows us to exit tests without
98
- // leaving open handles for web socket providers (eg. XRPL)
99
- await instance.disconnect()
100
-
101
- expect(instance.connected).toBe(false)
102
- expect(instance.provider).toBe(null)
103
- expect(instance.wallet).toBe(null)
104
- })
105
- })
@@ -1,57 +0,0 @@
1
- import { Address } from '@multiversx/sdk-core'
2
-
3
- import { MULTIVERSX } from '@/multichain/core'
4
- import { getSampleTranfers, verifyNumberOrder } from '../utils'
5
- import { wallets } from '../utils/wallets'
6
- import chainProviders from './chainProviders'
7
-
8
- describe('EGLD CHAIN TESTS', () => {
9
- let instance: MULTIVERSX
10
-
11
- beforeAll(async () => {
12
- instance = await MULTIVERSX.create(chainProviders.egld.testnet)
13
- const connected = await instance.connect()
14
- expect(connected).toBe(true)
15
- })
16
-
17
- test('preparePay returns a signed transaction', async () => {
18
- await instance.connectWallet(wallets.egld.wallet, {
19
- password: wallets.egld.password,
20
- })
21
- const tx = await instance.preparePay(instance.getAddress(), '0.00001')
22
-
23
- // INFO: Signature should be a 128 bit string
24
- expect(tx.signature?.length).toEqual(128)
25
- })
26
-
27
- test('Transcation is signed with the ledger nonce', async () => {
28
- const address = new Address(instance.getAddress())
29
- // INFO: Get the user's account on the network
30
- const accountOnNetwork = await instance.provider.getAccount(address)
31
- const ledgerNonce = accountOnNetwork.nonce
32
-
33
- const tx = await instance.preparePay(instance.getAddress(), '0.00001')
34
-
35
- expect(tx.nonce).toEqual(ledgerNonce)
36
- })
37
-
38
- test('Transactions are signed with increasing nonces', async () => {
39
- const address = instance.getAddress()
40
- const txs = await instance.preparePays(getSampleTranfers(address))
41
-
42
- const is_sorted = verifyNumberOrder(txs, 'nonce')
43
-
44
- // INFO: Nonces should be sorted in ascending order
45
- expect(is_sorted).toBe(true)
46
- })
47
-
48
- test('Transactions are signed in order of appearance', async () => {
49
- const address = instance.getAddress()
50
- const txs = await instance.preparePays(getSampleTranfers(address))
51
-
52
- const is_sorted = verifyNumberOrder(txs, 'value')
53
-
54
- // INFO: Amounts should be sorted in ascending order
55
- expect(is_sorted).toEqual(true)
56
- })
57
- })