@alephium/ledger-app 0.3.0 → 0.4.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.
@@ -1,132 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const hw_transport_node_hid_1 = __importDefault(require("@ledgerhq/hw-transport-node-hid"));
7
- const logs_1 = require("@ledgerhq/logs");
8
- const web3_1 = require("@alephium/web3");
9
- const src_1 = __importDefault(require("../src"));
10
- const web3_test_1 = require("@alephium/web3-test");
11
- const web3_wallet_1 = require("@alephium/web3-wallet");
12
- describe.skip('Integration', () => {
13
- const path = `m/44'/1234'/0'/0/0`;
14
- const nodeProvider = new web3_1.NodeProvider("http://127.0.0.1:22973");
15
- web3_1.web3.setCurrentNodeProvider(nodeProvider);
16
- function randomP2PKHAddress(groupIndex) {
17
- return web3_wallet_1.PrivateKeyWallet.Random(groupIndex, nodeProvider).address;
18
- }
19
- async function getALPHBalance(address) {
20
- const balances = await nodeProvider.addresses.getAddressesAddressBalance(address);
21
- return BigInt(balances.balance);
22
- }
23
- async function transferToTestAccount(address) {
24
- const fromAccount = await (0, web3_test_1.getSigner)();
25
- const transferResult = await (0, web3_test_1.transfer)(fromAccount, address, web3_1.ALPH_TOKEN_ID, web3_1.ONE_ALPH * 10n);
26
- await (0, web3_1.waitForTxConfirmation)(transferResult.txId, 1, 1000);
27
- }
28
- // enable this for integration test
29
- it('should transfer ALPH', async () => {
30
- const transport = await hw_transport_node_hid_1.default.open('');
31
- (0, logs_1.listen)((log) => console.log(log));
32
- const app = new src_1.default(transport);
33
- const [testAccount] = await app.getAccount(path);
34
- await transferToTestAccount(testAccount.address);
35
- const balance0 = await getALPHBalance(testAccount.address);
36
- const buildTxResult = await nodeProvider.transactions.postTransactionsBuild({
37
- fromPublicKey: testAccount.publicKey,
38
- destinations: [
39
- {
40
- address: randomP2PKHAddress(0),
41
- attoAlphAmount: (web3_1.ONE_ALPH * 2n).toString(),
42
- },
43
- {
44
- address: randomP2PKHAddress(0),
45
- attoAlphAmount: (web3_1.ONE_ALPH * 3n).toString(),
46
- },
47
- ]
48
- });
49
- const signature = await app.signUnsignedTx(path, Buffer.from(buildTxResult.unsignedTx, 'hex'));
50
- expect((0, web3_1.transactionVerifySignature)(buildTxResult.txId, testAccount.publicKey, signature)).toBe(true);
51
- const submitResult = await nodeProvider.transactions.postTransactionsSubmit({
52
- unsignedTx: buildTxResult.unsignedTx,
53
- signature: signature
54
- });
55
- await (0, web3_1.waitForTxConfirmation)(submitResult.txId, 1, 1000);
56
- const balance1 = await getALPHBalance(testAccount.address);
57
- const gasFee = BigInt(buildTxResult.gasAmount) * BigInt(buildTxResult.gasPrice);
58
- expect(balance1).toEqual(balance0 - gasFee - web3_1.ONE_ALPH * 5n);
59
- await app.close();
60
- }, 120000);
61
- it('should transfer token', async () => {
62
- const transport = await hw_transport_node_hid_1.default.open('');
63
- (0, logs_1.listen)((log) => console.log(log));
64
- const app = new src_1.default(transport);
65
- const [testAccount] = await app.getAccount(path);
66
- await transferToTestAccount(testAccount.address);
67
- const tokenAmount = 2222222222222222222222222n;
68
- const tokenInfo = await (0, web3_test_1.mintToken)(testAccount.address, tokenAmount);
69
- const balances0 = await nodeProvider.addresses.getAddressesAddressBalance(testAccount.address);
70
- const transferAmount = 2222222222222222222222222n / 2n;
71
- const buildTxResult = await nodeProvider.transactions.postTransactionsBuild({
72
- fromPublicKey: testAccount.publicKey,
73
- destinations: [
74
- {
75
- address: '1BmVCLrjttchZMW7i6df7mTdCKzHpy38bgDbVL1GqV6P7',
76
- attoAlphAmount: (web3_1.ONE_ALPH * 2n).toString(),
77
- tokens: [{ id: tokenInfo.contractId, amount: transferAmount.toString() }]
78
- }
79
- ]
80
- });
81
- const signature = await app.signUnsignedTx(path, Buffer.from(buildTxResult.unsignedTx, 'hex'));
82
- expect((0, web3_1.transactionVerifySignature)(buildTxResult.txId, testAccount.publicKey, signature)).toBe(true);
83
- const submitResult = await nodeProvider.transactions.postTransactionsSubmit({
84
- unsignedTx: buildTxResult.unsignedTx,
85
- signature: signature
86
- });
87
- await (0, web3_1.waitForTxConfirmation)(submitResult.txId, 1, 1000);
88
- const balances1 = await nodeProvider.addresses.getAddressesAddressBalance(testAccount.address);
89
- const gasFee = BigInt(buildTxResult.gasAmount) * BigInt(buildTxResult.gasPrice);
90
- const alphBalance = BigInt(balances1.balance);
91
- expect(alphBalance).toEqual(BigInt(balances0.balance) - gasFee - web3_1.ONE_ALPH * 2n);
92
- const tokenBalance = balances1.tokenBalances.find((t) => t.id === tokenInfo.contractId);
93
- expect(tokenBalance.amount).toEqual((tokenAmount - transferAmount).toString());
94
- await app.close();
95
- }, 120000);
96
- it('should transfer to multisig address', async () => {
97
- const transport = await hw_transport_node_hid_1.default.open('');
98
- (0, logs_1.listen)((log) => console.log(log));
99
- const app = new src_1.default(transport);
100
- const [testAccount] = await app.getAccount(path);
101
- await transferToTestAccount(testAccount.address);
102
- const tokenAmount = 2222222222222222222222222n;
103
- const tokenInfo = await (0, web3_test_1.mintToken)(testAccount.address, tokenAmount);
104
- const balances0 = await nodeProvider.addresses.getAddressesAddressBalance(testAccount.address);
105
- const transferAmount = 2222222222222222222222222n / 2n;
106
- const multiSigAddress = 'X3KYVteDjsKuUP1F68Nv9iEUecnnkMuwjbC985AnA6MvciDFJ5bAUEso2Sd7sGrwZ5rfNLj7Rp4n9XjcyzDiZsrPxfhNkPYcDm3ce8pQ9QasNFByEufMi3QJ3cS9Vk6cTpqNcq';
107
- const buildTxResult = await nodeProvider.transactions.postTransactionsBuild({
108
- fromPublicKey: testAccount.publicKey,
109
- destinations: [
110
- {
111
- address: multiSigAddress,
112
- attoAlphAmount: (web3_1.ONE_ALPH * 2n).toString(),
113
- tokens: [{ id: tokenInfo.contractId, amount: transferAmount.toString() }]
114
- }
115
- ]
116
- });
117
- const signature = await app.signUnsignedTx(path, Buffer.from(buildTxResult.unsignedTx, 'hex'));
118
- expect((0, web3_1.transactionVerifySignature)(buildTxResult.txId, testAccount.publicKey, signature)).toBe(true);
119
- const submitResult = await nodeProvider.transactions.postTransactionsSubmit({
120
- unsignedTx: buildTxResult.unsignedTx,
121
- signature: signature
122
- });
123
- await (0, web3_1.waitForTxConfirmation)(submitResult.txId, 1, 1000);
124
- const balances1 = await nodeProvider.addresses.getAddressesAddressBalance(testAccount.address);
125
- const gasFee = BigInt(buildTxResult.gasAmount) * BigInt(buildTxResult.gasPrice);
126
- const alphBalance = BigInt(balances1.balance);
127
- expect(alphBalance).toEqual(BigInt(balances0.balance) - gasFee - web3_1.ONE_ALPH * 2n);
128
- const tokenBalance = balances1.tokenBalances.find((t) => t.id === tokenInfo.contractId);
129
- expect(tokenBalance.amount).toEqual((tokenAmount - transferAmount).toString());
130
- await app.close();
131
- }, 120000);
132
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,152 +0,0 @@
1
- import NodeTransport from '@ledgerhq/hw-transport-node-hid'
2
- import { listen } from '@ledgerhq/logs'
3
-
4
- import { ALPH_TOKEN_ID, Address, NodeProvider, ONE_ALPH, transactionVerifySignature, web3, waitForTxConfirmation } from '@alephium/web3'
5
-
6
- import AlephiumApp from '../src'
7
- import { getSigner, mintToken, transfer } from '@alephium/web3-test'
8
- import { PrivateKeyWallet } from '@alephium/web3-wallet'
9
-
10
- describe.skip('Integration', () => {
11
- const path = `m/44'/1234'/0'/0/0`
12
- const nodeProvider = new NodeProvider("http://127.0.0.1:22973")
13
- web3.setCurrentNodeProvider(nodeProvider)
14
-
15
- function randomP2PKHAddress(groupIndex: number): string {
16
- return PrivateKeyWallet.Random(groupIndex, nodeProvider).address
17
- }
18
-
19
- async function getALPHBalance(address: Address) {
20
- const balances = await nodeProvider.addresses.getAddressesAddressBalance(address)
21
- return BigInt(balances.balance)
22
- }
23
-
24
- async function transferToTestAccount(address: Address) {
25
- const fromAccount = await getSigner()
26
- const transferResult = await transfer(fromAccount, address, ALPH_TOKEN_ID, ONE_ALPH * 10n)
27
- await waitForTxConfirmation(transferResult.txId, 1, 1000)
28
- }
29
-
30
- // enable this for integration test
31
- it('should transfer ALPH', async () => {
32
- const transport = await NodeTransport.open('')
33
- listen((log) => console.log(log))
34
- const app = new AlephiumApp(transport)
35
- const [testAccount] = await app.getAccount(path)
36
- await transferToTestAccount(testAccount.address)
37
-
38
- const balance0 = await getALPHBalance(testAccount.address)
39
- const buildTxResult = await nodeProvider.transactions.postTransactionsBuild({
40
- fromPublicKey: testAccount.publicKey,
41
- destinations: [
42
- {
43
- address: randomP2PKHAddress(0),
44
- attoAlphAmount: (ONE_ALPH * 2n).toString(),
45
- },
46
- {
47
- address: randomP2PKHAddress(0),
48
- attoAlphAmount: (ONE_ALPH * 3n).toString(),
49
- },
50
- ]
51
- })
52
-
53
- const signature = await app.signUnsignedTx(path, Buffer.from(buildTxResult.unsignedTx, 'hex'))
54
- expect(transactionVerifySignature(buildTxResult.txId, testAccount.publicKey, signature)).toBe(true)
55
-
56
- const submitResult = await nodeProvider.transactions.postTransactionsSubmit({
57
- unsignedTx: buildTxResult.unsignedTx,
58
- signature: signature
59
- })
60
- await waitForTxConfirmation(submitResult.txId, 1, 1000)
61
- const balance1 = await getALPHBalance(testAccount.address)
62
- const gasFee = BigInt(buildTxResult.gasAmount) * BigInt(buildTxResult.gasPrice)
63
- expect(balance1).toEqual(balance0 - gasFee - ONE_ALPH * 5n)
64
-
65
- await app.close()
66
- }, 120000)
67
-
68
- it('should transfer token', async () => {
69
- const transport = await NodeTransport.open('')
70
- listen((log) => console.log(log))
71
- const app = new AlephiumApp(transport)
72
- const [testAccount] = await app.getAccount(path)
73
- await transferToTestAccount(testAccount.address)
74
-
75
- const tokenAmount = 2222222222222222222222222n
76
- const tokenInfo = await mintToken(testAccount.address, tokenAmount)
77
- const balances0 = await nodeProvider.addresses.getAddressesAddressBalance(testAccount.address)
78
-
79
- const transferAmount = 2222222222222222222222222n / 2n
80
- const buildTxResult = await nodeProvider.transactions.postTransactionsBuild({
81
- fromPublicKey: testAccount.publicKey,
82
- destinations: [
83
- {
84
- address: '1BmVCLrjttchZMW7i6df7mTdCKzHpy38bgDbVL1GqV6P7',
85
- attoAlphAmount: (ONE_ALPH * 2n).toString(),
86
- tokens: [{ id: tokenInfo.contractId, amount: transferAmount.toString() }]
87
- }
88
- ]
89
- })
90
-
91
- const signature = await app.signUnsignedTx(path, Buffer.from(buildTxResult.unsignedTx, 'hex'))
92
- expect(transactionVerifySignature(buildTxResult.txId, testAccount.publicKey, signature)).toBe(true)
93
-
94
- const submitResult = await nodeProvider.transactions.postTransactionsSubmit({
95
- unsignedTx: buildTxResult.unsignedTx,
96
- signature: signature
97
- })
98
- await waitForTxConfirmation(submitResult.txId, 1, 1000)
99
- const balances1 = await nodeProvider.addresses.getAddressesAddressBalance(testAccount.address)
100
- const gasFee = BigInt(buildTxResult.gasAmount) * BigInt(buildTxResult.gasPrice)
101
- const alphBalance = BigInt(balances1.balance)
102
- expect(alphBalance).toEqual(BigInt(balances0.balance) - gasFee - ONE_ALPH * 2n)
103
-
104
- const tokenBalance = balances1.tokenBalances!.find((t) => t.id === tokenInfo.contractId)!
105
- expect(tokenBalance.amount).toEqual((tokenAmount - transferAmount).toString())
106
-
107
- await app.close()
108
- }, 120000)
109
-
110
- it('should transfer to multisig address', async () => {
111
- const transport = await NodeTransport.open('')
112
- listen((log) => console.log(log))
113
- const app = new AlephiumApp(transport)
114
- const [testAccount] = await app.getAccount(path)
115
- await transferToTestAccount(testAccount.address)
116
-
117
- const tokenAmount = 2222222222222222222222222n
118
- const tokenInfo = await mintToken(testAccount.address, tokenAmount)
119
- const balances0 = await nodeProvider.addresses.getAddressesAddressBalance(testAccount.address)
120
-
121
- const transferAmount = 2222222222222222222222222n / 2n
122
- const multiSigAddress = 'X3KYVteDjsKuUP1F68Nv9iEUecnnkMuwjbC985AnA6MvciDFJ5bAUEso2Sd7sGrwZ5rfNLj7Rp4n9XjcyzDiZsrPxfhNkPYcDm3ce8pQ9QasNFByEufMi3QJ3cS9Vk6cTpqNcq';
123
- const buildTxResult = await nodeProvider.transactions.postTransactionsBuild({
124
- fromPublicKey: testAccount.publicKey,
125
- destinations: [
126
- {
127
- address: multiSigAddress,
128
- attoAlphAmount: (ONE_ALPH * 2n).toString(),
129
- tokens: [{ id: tokenInfo.contractId, amount: transferAmount.toString() }]
130
- }
131
- ]
132
- })
133
-
134
- const signature = await app.signUnsignedTx(path, Buffer.from(buildTxResult.unsignedTx, 'hex'))
135
- expect(transactionVerifySignature(buildTxResult.txId, testAccount.publicKey, signature)).toBe(true)
136
-
137
- const submitResult = await nodeProvider.transactions.postTransactionsSubmit({
138
- unsignedTx: buildTxResult.unsignedTx,
139
- signature: signature
140
- })
141
- await waitForTxConfirmation(submitResult.txId, 1, 1000)
142
- const balances1 = await nodeProvider.addresses.getAddressesAddressBalance(testAccount.address)
143
- const gasFee = BigInt(buildTxResult.gasAmount) * BigInt(buildTxResult.gasPrice)
144
- const alphBalance = BigInt(balances1.balance)
145
- expect(alphBalance).toEqual(BigInt(balances0.balance) - gasFee - ONE_ALPH * 2n)
146
-
147
- const tokenBalance = balances1.tokenBalances!.find((t) => t.id === tokenInfo.contractId)!
148
- expect(tokenBalance.amount).toEqual((tokenAmount - transferAmount).toString())
149
-
150
- await app.close()
151
- }, 120000)
152
- })