@alephium/web3 0.2.0-rc.3 → 0.2.0-rc.31
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/.eslintignore +2 -2
- package/README.md +2 -135
- package/dist/alephium-web3.min.js +1 -1
- package/dist/alephium-web3.min.js.LICENSE.txt +0 -17
- package/dist/alephium-web3.min.js.map +1 -1
- package/dist/src/api/api-alephium.d.ts +117 -17
- package/dist/src/api/api-alephium.js +145 -79
- package/dist/src/api/api-explorer.d.ts +163 -48
- package/dist/src/api/api-explorer.js +157 -34
- package/dist/src/api/index.d.ts +14 -2
- package/dist/src/api/index.js +46 -4
- package/dist/src/api/types.d.ts +23 -0
- package/dist/src/api/types.js +240 -0
- package/dist/src/api/utils.d.ts +6 -0
- package/dist/{scripts/rename-gitignore.js → src/api/utils.js} +11 -6
- package/dist/src/contract/contract.d.ts +110 -73
- package/dist/src/contract/contract.js +395 -451
- package/dist/src/contract/events.d.ts +4 -4
- package/dist/src/contract/events.js +2 -1
- package/dist/src/contract/index.js +5 -1
- package/dist/src/contract/ralph.d.ts +5 -4
- package/dist/src/contract/ralph.js +27 -1
- package/dist/src/global.d.ts +4 -0
- package/dist/{scripts/stop-devnet.js → src/global.js} +17 -11
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.js +23 -1
- package/dist/src/signer/index.d.ts +0 -1
- package/dist/src/signer/index.js +5 -2
- package/dist/src/signer/signer.d.ts +35 -28
- package/dist/src/signer/signer.js +79 -47
- package/dist/src/transaction/index.d.ts +0 -1
- package/dist/src/transaction/index.js +5 -2
- package/dist/src/transaction/status.d.ts +2 -1
- package/dist/src/transaction/status.js +2 -1
- package/dist/src/utils/bs58.d.ts +1 -0
- package/dist/src/utils/bs58.js +13 -1
- package/dist/src/utils/index.d.ts +0 -1
- package/dist/src/utils/index.js +5 -2
- package/dist/src/utils/subscription.d.ts +0 -3
- package/dist/src/utils/subscription.js +0 -1
- package/dist/src/utils/utils.d.ts +4 -9
- package/dist/src/utils/utils.js +20 -24
- package/jest-config.json +11 -0
- package/package.json +11 -47
- package/src/api/api-alephium.ts +169 -25
- package/src/api/api-explorer.ts +234 -51
- package/src/api/index.ts +53 -3
- package/src/api/types.ts +233 -0
- package/{scripts/rename-gitignore.js → src/api/utils.ts} +7 -6
- package/src/contract/contract.ts +582 -550
- package/src/contract/events.ts +6 -5
- package/src/contract/ralph.ts +29 -4
- package/src/{transaction/sign-verify.ts → global.ts} +14 -15
- package/src/index.ts +7 -0
- package/src/signer/index.ts +0 -1
- package/src/signer/signer.ts +122 -85
- package/src/transaction/index.ts +0 -1
- package/src/transaction/status.ts +5 -2
- package/src/utils/bs58.ts +11 -0
- package/src/utils/index.ts +0 -1
- package/src/utils/subscription.ts +0 -4
- package/src/utils/utils.ts +11 -19
- package/.eslintrc.json +0 -21
- package/LICENSE +0 -165
- package/contracts/add/add.ral +0 -16
- package/contracts/greeter/greeter.ral +0 -7
- package/contracts/greeter/greeter_interface.ral +0 -3
- package/contracts/greeter_main.ral +0 -9
- package/contracts/main.ral +0 -6
- package/contracts/sub/sub.ral +0 -9
- package/contracts/test/metadata.ral +0 -17
- package/contracts/test/warnings.ral +0 -5
- package/dev/user.conf +0 -29
- package/dist/scripts/create-project.d.ts +0 -2
- package/dist/scripts/create-project.js +0 -125
- package/dist/scripts/rename-gitignore.d.ts +0 -1
- package/dist/scripts/start-devnet.d.ts +0 -1
- package/dist/scripts/start-devnet.js +0 -131
- package/dist/scripts/stop-devnet.d.ts +0 -1
- package/dist/src/signer/node-wallet.d.ts +0 -13
- package/dist/src/signer/node-wallet.js +0 -60
- package/dist/src/test/index.d.ts +0 -7
- package/dist/src/test/index.js +0 -41
- package/dist/src/test/privatekey-wallet.d.ts +0 -12
- package/dist/src/test/privatekey-wallet.js +0 -68
- package/dist/src/transaction/sign-verify.d.ts +0 -2
- package/dist/src/transaction/sign-verify.js +0 -58
- package/dist/src/utils/password-crypto.d.ts +0 -2
- package/dist/src/utils/password-crypto.js +0 -69
- package/gitignore +0 -10
- package/scripts/create-project.ts +0 -137
- package/scripts/start-devnet.js +0 -141
- package/scripts/stop-devnet.js +0 -32
- package/src/contract/ralph.test.ts +0 -178
- package/src/fixtures/address.json +0 -36
- package/src/fixtures/balance.json +0 -9
- package/src/fixtures/self-clique.json +0 -19
- package/src/fixtures/transaction.json +0 -13
- package/src/fixtures/transactions.json +0 -179
- package/src/signer/fixtures/genesis.json +0 -26
- package/src/signer/fixtures/wallets.json +0 -26
- package/src/signer/node-wallet.ts +0 -74
- package/src/test/index.ts +0 -32
- package/src/test/privatekey-wallet.ts +0 -58
- package/src/transaction/sign-verify.test.ts +0 -50
- package/src/utils/address.test.ts +0 -47
- package/src/utils/djb2.test.ts +0 -35
- package/src/utils/password-crypto.test.ts +0 -27
- package/src/utils/password-crypto.ts +0 -77
- package/src/utils/utils.test.ts +0 -161
- package/templates/base/README.md +0 -34
- package/templates/base/package.json +0 -35
- package/templates/base/src/greeter.ts +0 -41
- package/templates/base/tsconfig.json +0 -19
- package/templates/react/README.md +0 -34
- package/templates/react/config-overrides.js +0 -18
- package/templates/react/package.json +0 -66
- package/templates/react/src/App.tsx +0 -42
- package/templates/react/src/artifacts/greeter.ral.json +0 -26
- package/templates/react/src/artifacts/greeter_main.ral.json +0 -22
- package/templates/shared/.eslintrc.json +0 -12
- package/templates/shared/scripts/header.js +0 -0
- package/test/contract.test.ts +0 -197
- package/test/events.test.ts +0 -138
- package/test/transaction.test.ts +0 -72
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { NodeProvider } from '../api';
|
|
2
|
-
import { Account, SignerWithNodeProvider } from '../signer';
|
|
3
|
-
export declare class NodeWallet extends SignerWithNodeProvider {
|
|
4
|
-
walletName: string;
|
|
5
|
-
accounts: Account[] | undefined;
|
|
6
|
-
constructor(provider: NodeProvider, walletName: string, alwaysSubmitTx?: boolean);
|
|
7
|
-
getAccounts(): Promise<Account[]>;
|
|
8
|
-
private getAllAccounts;
|
|
9
|
-
static FromCliqueClient(provider: NodeProvider, walletName: string, alwaysSubmitTx?: boolean): Promise<NodeWallet>;
|
|
10
|
-
signRaw(signerAddress: string, hexString: string): Promise<string>;
|
|
11
|
-
unlock(password: string): Promise<void>;
|
|
12
|
-
lock(): Promise<void>;
|
|
13
|
-
}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
Copyright 2018 - 2022 The Alephium Authors
|
|
4
|
-
This file is part of the alephium project.
|
|
5
|
-
|
|
6
|
-
The library is free software: you can redistribute it and/or modify
|
|
7
|
-
it under the terms of the GNU Lesser General Public License as published by
|
|
8
|
-
the Free Software Foundation, either version 3 of the License, or
|
|
9
|
-
(at your option) any later version.
|
|
10
|
-
|
|
11
|
-
The library is distributed in the hope that it will be useful,
|
|
12
|
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14
|
-
GNU Lesser General Public License for more details.
|
|
15
|
-
|
|
16
|
-
You should have received a copy of the GNU Lesser General Public License
|
|
17
|
-
along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
18
|
-
*/
|
|
19
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.NodeWallet = void 0;
|
|
21
|
-
const signer_1 = require("../signer");
|
|
22
|
-
class NodeWallet extends signer_1.SignerWithNodeProvider {
|
|
23
|
-
constructor(provider, walletName, alwaysSubmitTx = true) {
|
|
24
|
-
super(provider, alwaysSubmitTx);
|
|
25
|
-
this.walletName = walletName;
|
|
26
|
-
}
|
|
27
|
-
async getAccounts() {
|
|
28
|
-
if (typeof this.accounts === 'undefined') {
|
|
29
|
-
this.accounts = await this.getAllAccounts();
|
|
30
|
-
}
|
|
31
|
-
return this.accounts;
|
|
32
|
-
}
|
|
33
|
-
async getAllAccounts() {
|
|
34
|
-
const walletAddresses = await this.provider.wallets.getWalletsWalletNameAddresses(this.walletName);
|
|
35
|
-
const accounts = walletAddresses.addresses.map((acc) => ({
|
|
36
|
-
publicKey: acc.publicKey,
|
|
37
|
-
address: acc.address,
|
|
38
|
-
group: acc.group
|
|
39
|
-
}));
|
|
40
|
-
return accounts;
|
|
41
|
-
}
|
|
42
|
-
static async FromCliqueClient(provider, walletName, alwaysSubmitTx = true) {
|
|
43
|
-
return new NodeWallet(provider, walletName, alwaysSubmitTx);
|
|
44
|
-
}
|
|
45
|
-
async signRaw(signerAddress, hexString) {
|
|
46
|
-
const currentActiveAddressResponse = await this.provider.wallets.getWalletsWalletNameAddresses(this.walletName);
|
|
47
|
-
const { activeAddress } = currentActiveAddressResponse;
|
|
48
|
-
await this.provider.wallets.postWalletsWalletNameChangeActiveAddress(this.walletName, { address: signerAddress });
|
|
49
|
-
const { signature } = await this.provider.wallets.postWalletsWalletNameSign(this.walletName, { data: hexString });
|
|
50
|
-
await this.provider.wallets.postWalletsWalletNameChangeActiveAddress(this.walletName, { address: activeAddress }); // set the address that's active back to previous state
|
|
51
|
-
return signature;
|
|
52
|
-
}
|
|
53
|
-
async unlock(password) {
|
|
54
|
-
return await this.provider.wallets.postWalletsWalletNameUnlock(this.walletName, { password });
|
|
55
|
-
}
|
|
56
|
-
async lock() {
|
|
57
|
-
return await this.provider.wallets.postWalletsWalletNameLock(this.walletName);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
exports.NodeWallet = NodeWallet;
|
package/dist/src/test/index.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { NodeProvider } from '../api';
|
|
2
|
-
import { NodeWallet } from '../signer';
|
|
3
|
-
export declare const testWalletName = "alephium-web3-test-only-wallet";
|
|
4
|
-
export declare const testAddress = "1DrDyTr9RpRsQnDnXo2YRiPzPW4ooHX5LLoqXrqfMrpQH";
|
|
5
|
-
export declare const testPassword = "alph";
|
|
6
|
-
export declare function testWallet(provider: NodeProvider): Promise<NodeWallet>;
|
|
7
|
-
export * from './privatekey-wallet';
|
package/dist/src/test/index.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
Copyright 2018 - 2022 The Alephium Authors
|
|
4
|
-
This file is part of the alephium project.
|
|
5
|
-
|
|
6
|
-
The library is free software: you can redistribute it and/or modify
|
|
7
|
-
it under the terms of the GNU Lesser General Public License as published by
|
|
8
|
-
the Free Software Foundation, either version 3 of the License, or
|
|
9
|
-
(at your option) any later version.
|
|
10
|
-
|
|
11
|
-
The library is distributed in the hope that it will be useful,
|
|
12
|
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14
|
-
GNU Lesser General Public License for more details.
|
|
15
|
-
|
|
16
|
-
You should have received a copy of the GNU Lesser General Public License
|
|
17
|
-
along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
18
|
-
*/
|
|
19
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
20
|
-
if (k2 === undefined) k2 = k;
|
|
21
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
22
|
-
}) : (function(o, m, k, k2) {
|
|
23
|
-
if (k2 === undefined) k2 = k;
|
|
24
|
-
o[k2] = m[k];
|
|
25
|
-
}));
|
|
26
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
27
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
28
|
-
};
|
|
29
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
-
exports.testWallet = exports.testPassword = exports.testAddress = exports.testWalletName = void 0;
|
|
31
|
-
const signer_1 = require("../signer");
|
|
32
|
-
exports.testWalletName = 'alephium-web3-test-only-wallet';
|
|
33
|
-
exports.testAddress = '1DrDyTr9RpRsQnDnXo2YRiPzPW4ooHX5LLoqXrqfMrpQH';
|
|
34
|
-
exports.testPassword = 'alph';
|
|
35
|
-
async function testWallet(provider) {
|
|
36
|
-
const wallet = new signer_1.NodeWallet(provider, exports.testWalletName);
|
|
37
|
-
await wallet.unlock(exports.testPassword);
|
|
38
|
-
return wallet;
|
|
39
|
-
}
|
|
40
|
-
exports.testWallet = testWallet;
|
|
41
|
-
__exportStar(require("./privatekey-wallet"), exports);
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { NodeProvider } from '../api';
|
|
2
|
-
import { Account, SignerWithNodeProvider } from '../signer';
|
|
3
|
-
export declare class PrivateKeyWallet extends SignerWithNodeProvider {
|
|
4
|
-
readonly privateKey: string;
|
|
5
|
-
readonly publicKey: string;
|
|
6
|
-
readonly address: string;
|
|
7
|
-
readonly group: number;
|
|
8
|
-
constructor(provider: NodeProvider, privateKey: string, alwaysSubmitTx?: boolean);
|
|
9
|
-
static Random(provider: NodeProvider, alwaysSubmitTx?: boolean): PrivateKeyWallet;
|
|
10
|
-
getAccounts(): Promise<Account[]>;
|
|
11
|
-
signRaw(signerAddress: string, hexString: string): Promise<string>;
|
|
12
|
-
}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
Copyright 2018 - 2022 The Alephium Authors
|
|
4
|
-
This file is part of the alephium project.
|
|
5
|
-
|
|
6
|
-
The library is free software: you can redistribute it and/or modify
|
|
7
|
-
it under the terms of the GNU Lesser General Public License as published by
|
|
8
|
-
the Free Software Foundation, either version 3 of the License, or
|
|
9
|
-
(at your option) any later version.
|
|
10
|
-
|
|
11
|
-
The library is distributed in the hope that it will be useful,
|
|
12
|
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14
|
-
GNU Lesser General Public License for more details.
|
|
15
|
-
|
|
16
|
-
You should have received a copy of the GNU Lesser General Public License
|
|
17
|
-
along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
18
|
-
*/
|
|
19
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
20
|
-
if (k2 === undefined) k2 = k;
|
|
21
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
22
|
-
}) : (function(o, m, k, k2) {
|
|
23
|
-
if (k2 === undefined) k2 = k;
|
|
24
|
-
o[k2] = m[k];
|
|
25
|
-
}));
|
|
26
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
27
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
28
|
-
}) : function(o, v) {
|
|
29
|
-
o["default"] = v;
|
|
30
|
-
});
|
|
31
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
32
|
-
if (mod && mod.__esModule) return mod;
|
|
33
|
-
var result = {};
|
|
34
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
35
|
-
__setModuleDefault(result, mod);
|
|
36
|
-
return result;
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.PrivateKeyWallet = void 0;
|
|
40
|
-
const elliptic_1 = require("elliptic");
|
|
41
|
-
const signer_1 = require("../signer");
|
|
42
|
-
const utils = __importStar(require("../utils"));
|
|
43
|
-
const ec = new elliptic_1.ec('secp256k1');
|
|
44
|
-
class PrivateKeyWallet extends signer_1.SignerWithNodeProvider {
|
|
45
|
-
constructor(provider, privateKey, alwaysSubmitTx = true) {
|
|
46
|
-
super(provider, alwaysSubmitTx);
|
|
47
|
-
this.privateKey = privateKey;
|
|
48
|
-
this.publicKey = utils.publicKeyFromPrivateKey(privateKey);
|
|
49
|
-
this.address = utils.addressFromPublicKey(this.publicKey);
|
|
50
|
-
this.group = utils.groupOfAddress(this.address);
|
|
51
|
-
}
|
|
52
|
-
static Random(provider, alwaysSubmitTx = true) {
|
|
53
|
-
const keyPair = ec.genKeyPair();
|
|
54
|
-
return new PrivateKeyWallet(provider, keyPair.getPrivate().toString('hex'), alwaysSubmitTx);
|
|
55
|
-
}
|
|
56
|
-
async getAccounts() {
|
|
57
|
-
return [{ address: this.address, publicKey: this.publicKey, group: this.group }];
|
|
58
|
-
}
|
|
59
|
-
async signRaw(signerAddress, hexString) {
|
|
60
|
-
if (signerAddress !== this.address) {
|
|
61
|
-
throw Error('Unmatched signer address');
|
|
62
|
-
}
|
|
63
|
-
const key = ec.keyFromPrivate(this.privateKey);
|
|
64
|
-
const signature = key.sign(hexString);
|
|
65
|
-
return utils.signatureEncode(signature);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
exports.PrivateKeyWallet = PrivateKeyWallet;
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
Copyright 2018 - 2022 The Alephium Authors
|
|
4
|
-
This file is part of the alephium project.
|
|
5
|
-
|
|
6
|
-
The library is free software: you can redistribute it and/or modify
|
|
7
|
-
it under the terms of the GNU Lesser General Public License as published by
|
|
8
|
-
the Free Software Foundation, either version 3 of the License, or
|
|
9
|
-
(at your option) any later version.
|
|
10
|
-
|
|
11
|
-
The library is distributed in the hope that it will be useful,
|
|
12
|
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14
|
-
GNU Lesser General Public License for more details.
|
|
15
|
-
|
|
16
|
-
You should have received a copy of the GNU Lesser General Public License
|
|
17
|
-
along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
18
|
-
*/
|
|
19
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
20
|
-
if (k2 === undefined) k2 = k;
|
|
21
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
22
|
-
}) : (function(o, m, k, k2) {
|
|
23
|
-
if (k2 === undefined) k2 = k;
|
|
24
|
-
o[k2] = m[k];
|
|
25
|
-
}));
|
|
26
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
27
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
28
|
-
}) : function(o, v) {
|
|
29
|
-
o["default"] = v;
|
|
30
|
-
});
|
|
31
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
32
|
-
if (mod && mod.__esModule) return mod;
|
|
33
|
-
var result = {};
|
|
34
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
35
|
-
__setModuleDefault(result, mod);
|
|
36
|
-
return result;
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.transactionVerifySignature = exports.transactionSign = void 0;
|
|
40
|
-
const elliptic_1 = require("elliptic");
|
|
41
|
-
const utils = __importStar(require("../utils"));
|
|
42
|
-
const ec = new elliptic_1.ec('secp256k1');
|
|
43
|
-
function transactionSign(txHash, privateKey) {
|
|
44
|
-
const keyPair = ec.keyFromPrivate(privateKey);
|
|
45
|
-
const signature = keyPair.sign(txHash);
|
|
46
|
-
return utils.signatureEncode(signature);
|
|
47
|
-
}
|
|
48
|
-
exports.transactionSign = transactionSign;
|
|
49
|
-
function transactionVerifySignature(txHash, publicKey, signature) {
|
|
50
|
-
try {
|
|
51
|
-
const key = ec.keyFromPublic(publicKey, 'hex');
|
|
52
|
-
return key.verify(txHash, utils.signatureDecode(ec, signature));
|
|
53
|
-
}
|
|
54
|
-
catch (error) {
|
|
55
|
-
return false;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
exports.transactionVerifySignature = transactionVerifySignature;
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
Copyright 2018 - 2022 The Alephium Authors
|
|
4
|
-
This file is part of the alephium project.
|
|
5
|
-
|
|
6
|
-
The library is free software: you can redistribute it and/or modify
|
|
7
|
-
it under the terms of the GNU Lesser General Public License as published by
|
|
8
|
-
the Free Software Foundation, either version 3 of the License, or
|
|
9
|
-
(at your option) any later version.
|
|
10
|
-
|
|
11
|
-
The library is distributed in the hope that it will be useful,
|
|
12
|
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14
|
-
GNU Lesser General Public License for more details.
|
|
15
|
-
|
|
16
|
-
You should have received a copy of the GNU Lesser General Public License
|
|
17
|
-
along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
18
|
-
*/
|
|
19
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.decrypt = exports.encrypt = void 0;
|
|
21
|
-
const buffer_1 = require("buffer/");
|
|
22
|
-
const crypto_1 = require("crypto");
|
|
23
|
-
const saltByteLength = 64;
|
|
24
|
-
const ivByteLength = 64;
|
|
25
|
-
const authTagLength = 16;
|
|
26
|
-
const encrypt = (password, dataRaw) => {
|
|
27
|
-
const data = buffer_1.Buffer.from(dataRaw, 'utf8');
|
|
28
|
-
const salt = (0, crypto_1.randomBytes)(saltByteLength);
|
|
29
|
-
const derivedKey = keyFromPassword(password, salt);
|
|
30
|
-
const iv = (0, crypto_1.randomBytes)(ivByteLength);
|
|
31
|
-
const cipher = createCipher(derivedKey, iv);
|
|
32
|
-
const encrypted = buffer_1.Buffer.concat([cipher.update(data), cipher.final()]);
|
|
33
|
-
const authTag = cipher.getAuthTag();
|
|
34
|
-
const payload = {
|
|
35
|
-
salt: salt.toString('hex'),
|
|
36
|
-
iv: iv.toString('hex'),
|
|
37
|
-
encrypted: buffer_1.Buffer.concat([encrypted, authTag]).toString('hex'),
|
|
38
|
-
version: 1
|
|
39
|
-
};
|
|
40
|
-
return JSON.stringify(payload);
|
|
41
|
-
};
|
|
42
|
-
exports.encrypt = encrypt;
|
|
43
|
-
const decrypt = (password, payloadRaw) => {
|
|
44
|
-
const payload = JSON.parse(payloadRaw);
|
|
45
|
-
const version = payload.version;
|
|
46
|
-
if (version !== 1) {
|
|
47
|
-
throw new Error(`Invalid version: got ${version}, expected: 1`);
|
|
48
|
-
}
|
|
49
|
-
const salt = buffer_1.Buffer.from(payload.salt, 'hex');
|
|
50
|
-
const iv = buffer_1.Buffer.from(payload.iv, 'hex');
|
|
51
|
-
const encrypted = buffer_1.Buffer.from(payload.encrypted, 'hex');
|
|
52
|
-
const derivedKey = keyFromPassword(password, salt);
|
|
53
|
-
const decipher = createDecipher(derivedKey, iv);
|
|
54
|
-
const data = encrypted.slice(0, encrypted.length - authTagLength);
|
|
55
|
-
const authTag = encrypted.slice(encrypted.length - authTagLength, encrypted.length);
|
|
56
|
-
decipher.setAuthTag(authTag);
|
|
57
|
-
const decrypted = buffer_1.Buffer.concat([decipher.update(data), decipher.final()]);
|
|
58
|
-
return decrypted.toString('utf8');
|
|
59
|
-
};
|
|
60
|
-
exports.decrypt = decrypt;
|
|
61
|
-
const createCipher = (key, iv) => {
|
|
62
|
-
return (0, crypto_1.createCipheriv)('aes-256-gcm', key, iv);
|
|
63
|
-
};
|
|
64
|
-
const createDecipher = (key, iv) => {
|
|
65
|
-
return (0, crypto_1.createDecipheriv)('aes-256-gcm', key, iv);
|
|
66
|
-
};
|
|
67
|
-
const keyFromPassword = (password, salt) => {
|
|
68
|
-
return (0, crypto_1.pbkdf2Sync)(password, salt, 10000, 32, 'sha256');
|
|
69
|
-
};
|
package/gitignore
DELETED
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/*
|
|
3
|
-
Copyright 2018 - 2022 The Alephium Authors
|
|
4
|
-
This file is part of the alephium project.
|
|
5
|
-
|
|
6
|
-
The library is free software: you can redistribute it and/or modify
|
|
7
|
-
it under the terms of the GNU Lesser General Public License as published by
|
|
8
|
-
the Free Software Foundation, either version 3 of the License, or
|
|
9
|
-
(at your option) any later version.
|
|
10
|
-
|
|
11
|
-
The library is distributed in the hope that it will be useful,
|
|
12
|
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14
|
-
GNU Lesser General Public License for more details.
|
|
15
|
-
|
|
16
|
-
You should have received a copy of the GNU Lesser General Public License
|
|
17
|
-
along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
import fsExtra from 'fs-extra'
|
|
21
|
-
import process from 'process'
|
|
22
|
-
import path from 'path'
|
|
23
|
-
import findup from 'find-up'
|
|
24
|
-
import { execSync } from 'child_process'
|
|
25
|
-
import commander from 'commander'
|
|
26
|
-
|
|
27
|
-
function getPackageRoot(): string {
|
|
28
|
-
const packageJsonPath = findup.sync('package.json', { cwd: path.dirname(__filename) })
|
|
29
|
-
|
|
30
|
-
if (packageJsonPath) {
|
|
31
|
-
return path.dirname(packageJsonPath)
|
|
32
|
-
} else {
|
|
33
|
-
throw new Error('Cannot find `package.json`')
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function extractProjectType(projectType: string): string {
|
|
38
|
-
if (typeof projectType === 'undefined') {
|
|
39
|
-
return 'base'
|
|
40
|
-
} else if (['base', 'react'].includes(projectType)) {
|
|
41
|
-
return projectType
|
|
42
|
-
} else {
|
|
43
|
-
console.log(`Invalid project type: ${projectType}, expect: base or react`)
|
|
44
|
-
process.exit(1)
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function extractProjectRoot(): string {
|
|
49
|
-
const projectRoot = path.join(projectParent, projectName)
|
|
50
|
-
if (fsExtra.existsSync(projectRoot)) {
|
|
51
|
-
console.log(`Project ${projectName} already exists. Try a different name.`)
|
|
52
|
-
console.log()
|
|
53
|
-
process.exit(1)
|
|
54
|
-
}
|
|
55
|
-
return projectRoot
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function copy(dir: string, files: string[]) {
|
|
59
|
-
const packageDevDir = path.join(packageRoot, dir)
|
|
60
|
-
const projectDevDir = path.join(projectRoot, dir)
|
|
61
|
-
if (!fsExtra.existsSync(projectDevDir)) {
|
|
62
|
-
fsExtra.mkdirSync(projectDevDir)
|
|
63
|
-
}
|
|
64
|
-
for (const file of files) {
|
|
65
|
-
fsExtra.copyFileSync(path.join(packageDevDir, file), path.join(projectDevDir, file))
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
function prepareShared(packageRoot: string, projectRoot: string) {
|
|
70
|
-
console.log('Copying files')
|
|
71
|
-
console.log(` from ${packageRoot}`)
|
|
72
|
-
console.log(` to ${projectRoot}`)
|
|
73
|
-
console.log('...')
|
|
74
|
-
|
|
75
|
-
fsExtra.copySync(path.join(packageRoot, 'templates/shared'), projectRoot)
|
|
76
|
-
copy('', ['.editorconfig', '.eslintignore', '.gitattributes', 'LICENSE'])
|
|
77
|
-
copy('dev', ['user.conf'])
|
|
78
|
-
copy('scripts', ['start-devnet.js', 'stop-devnet.js'])
|
|
79
|
-
if (fsExtra.existsSync(path.join(packageRoot, 'gitignore'))) {
|
|
80
|
-
fsExtra.copySync(path.join(packageRoot, 'gitignore'), path.join(projectRoot, '.gitignore'))
|
|
81
|
-
} else {
|
|
82
|
-
fsExtra.copySync(path.join(packageRoot, '.gitignore'), path.join(projectRoot, '.gitignore'))
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
console.log()
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
function prepareBase(packageRoot: string, projectRoot: string) {
|
|
89
|
-
prepareShared(packageRoot, projectRoot)
|
|
90
|
-
copy('contracts', ['greeter_main.ral'])
|
|
91
|
-
copy('contracts/greeter', ['greeter.ral', 'greeter_interface.ral'])
|
|
92
|
-
fsExtra.copySync(path.join(packageRoot, 'templates/base'), projectRoot)
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
function prepareReact(packageRoot: string, projectRoot: string, projectName: string) {
|
|
96
|
-
console.log('Creating the React app')
|
|
97
|
-
execSync(`npx create-react-app ${projectName} --template typescript`)
|
|
98
|
-
|
|
99
|
-
prepareShared(packageRoot, projectRoot)
|
|
100
|
-
fsExtra.copySync(path.join(packageRoot, 'templates/react'), projectRoot)
|
|
101
|
-
|
|
102
|
-
console.log('Initialize the project')
|
|
103
|
-
execSync(
|
|
104
|
-
'npm install --save-dev react-app-rewired crypto-browserify stream-browserify buffer process eslint-config-prettier eslint-plugin-header eslint-plugin-prettier eslint-plugin-react',
|
|
105
|
-
{ cwd: projectRoot }
|
|
106
|
-
)
|
|
107
|
-
execSync('npm install && npm run prettier', { cwd: projectRoot })
|
|
108
|
-
console.log()
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
const program = new commander.Command('Create sample project')
|
|
112
|
-
.arguments('<project-directory>')
|
|
113
|
-
.option('-t, --template <path-to-template>', 'specify a template for the project: either base or react')
|
|
114
|
-
.parse(process.argv)
|
|
115
|
-
|
|
116
|
-
const projectName = program.processedArgs[0]
|
|
117
|
-
const projectType = program.opts()['template']
|
|
118
|
-
|
|
119
|
-
const packageRoot = getPackageRoot()
|
|
120
|
-
const projectParent = process.cwd()
|
|
121
|
-
const projectRoot = extractProjectRoot()
|
|
122
|
-
|
|
123
|
-
switch (extractProjectType(projectType)) {
|
|
124
|
-
case 'base':
|
|
125
|
-
prepareBase(packageRoot, projectRoot)
|
|
126
|
-
break
|
|
127
|
-
case 'react':
|
|
128
|
-
prepareReact(packageRoot, projectRoot, projectName)
|
|
129
|
-
break
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
console.log('✅ Done.')
|
|
133
|
-
console.log()
|
|
134
|
-
console.log('✨ Project is initialized!')
|
|
135
|
-
console.log()
|
|
136
|
-
console.log(`Next step: checkout the readme under <${projectName}>`)
|
|
137
|
-
console.log()
|
package/scripts/start-devnet.js
DELETED
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2018 - 2022 The Alephium Authors
|
|
3
|
-
This file is part of the alephium project.
|
|
4
|
-
|
|
5
|
-
The library is free software: you can redistribute it and/or modify
|
|
6
|
-
it under the terms of the GNU Lesser General Public License as published by
|
|
7
|
-
the Free Software Foundation, either version 3 of the License, or
|
|
8
|
-
(at your option) any later version.
|
|
9
|
-
|
|
10
|
-
The library is distributed in the hope that it will be useful,
|
|
11
|
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
-
GNU Lesser General Public License for more details.
|
|
14
|
-
|
|
15
|
-
You should have received a copy of the GNU Lesser General Public License
|
|
16
|
-
along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
const fs = require('fs')
|
|
20
|
-
const process = require('process')
|
|
21
|
-
const path = require('path')
|
|
22
|
-
const fetch = require('cross-fetch')
|
|
23
|
-
const spawn = require('child_process').spawn
|
|
24
|
-
|
|
25
|
-
async function _downloadFullNode(tag, fileName) {
|
|
26
|
-
const url = `https://github.com/alephium/alephium/releases/download/v${tag}/alephium-${tag}.jar`
|
|
27
|
-
const res0 = await fetch(url)
|
|
28
|
-
const fileUrl = res0.url
|
|
29
|
-
const res1 = await fetch(fileUrl)
|
|
30
|
-
await new Promise((resolve) => {
|
|
31
|
-
console.log(`Downloading jar file to: ${fileName}`)
|
|
32
|
-
const file = fs.createWriteStream(fileName)
|
|
33
|
-
res1.body.pipe(file)
|
|
34
|
-
file.on('finish', function () {
|
|
35
|
-
resolve()
|
|
36
|
-
})
|
|
37
|
-
})
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
async function downloadFullNode(tag, devDir, jarFile) {
|
|
41
|
-
if (!fs.existsSync(devDir)) {
|
|
42
|
-
fs.mkdirSync(devDir)
|
|
43
|
-
}
|
|
44
|
-
const jarExisted = fs.existsSync(jarFile)
|
|
45
|
-
if (!jarExisted) {
|
|
46
|
-
await _downloadFullNode(tag, jarFile)
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function launchDevnet(devDir, jarFile) {
|
|
51
|
-
const pidFile = devDir + path.sep + 'alephium.pid'
|
|
52
|
-
try {
|
|
53
|
-
const pid = parseInt(fs.readFileSync(pidFile).toString())
|
|
54
|
-
if (pid) {
|
|
55
|
-
console.log(`Clearing the running devnet: ${pid}`)
|
|
56
|
-
process.kill(pid)
|
|
57
|
-
}
|
|
58
|
-
} catch (e) {
|
|
59
|
-
console.log(`Error in clearing the running devnet: ${e}`)
|
|
60
|
-
}
|
|
61
|
-
fs.rmSync(devDir + path.sep + 'logs', { recursive: true, force: true })
|
|
62
|
-
fs.rmSync(devDir + path.sep + 'network-4', { recursive: true, force: true })
|
|
63
|
-
|
|
64
|
-
const p = spawn('java', ['-jar', jarFile], {
|
|
65
|
-
detached: true,
|
|
66
|
-
stdio: 'ignore',
|
|
67
|
-
env: { ...process.env, ALEPHIUM_HOME: devDir, ALEPHIUM_ENABLE_DEBUG_LOGGING: 'true' }
|
|
68
|
-
})
|
|
69
|
-
p.unref()
|
|
70
|
-
console.log(`Devnet is launching with pid: ${p.pid}`)
|
|
71
|
-
fs.writeFileSync(devDir + path.sep + 'alephium.pid', p.pid.toString(), { falg: 'w' })
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const testWallet = 'alephium-web3-test-only-wallet'
|
|
75
|
-
const password = 'alph'
|
|
76
|
-
const mnemonic =
|
|
77
|
-
'vault alarm sad mass witness property virus style good flower rice alpha viable evidence run glare pretty scout evil judge enroll refuse another lava'
|
|
78
|
-
|
|
79
|
-
async function prepareWallet() {
|
|
80
|
-
const wallets = await fetch('http://127.0.0.1:22973/wallets', { method: 'Get' }).then((res) => res.json())
|
|
81
|
-
if (wallets.find((wallet) => wallet.walletName === testWallet)) {
|
|
82
|
-
unlockWallet()
|
|
83
|
-
} else {
|
|
84
|
-
createWallet()
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
async function createWallet() {
|
|
89
|
-
console.log('Create the test wallet')
|
|
90
|
-
await fetch('http://127.0.0.1:22973/wallets', {
|
|
91
|
-
method: 'Put',
|
|
92
|
-
body: `{"password":"${password}","mnemonic":"${mnemonic}","walletName":"${testWallet}"}`
|
|
93
|
-
})
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
async function unlockWallet() {
|
|
97
|
-
console.log('Unlock the test wallet')
|
|
98
|
-
await fetch('http://127.0.0.1:22973/wallets/alephium-web3-test-only-wallet/unlock', {
|
|
99
|
-
method: 'POST',
|
|
100
|
-
body: '{ "password": "alph" }'
|
|
101
|
-
})
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
function timeout(ms) {
|
|
105
|
-
return new Promise((resolve) => setTimeout(resolve, ms))
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
async function wait() {
|
|
109
|
-
console.log('...')
|
|
110
|
-
try {
|
|
111
|
-
const res = await fetch('http://127.0.0.1:22973/infos/node', { method: 'Get' })
|
|
112
|
-
if (res.status != 200) {
|
|
113
|
-
await timeout(1000)
|
|
114
|
-
await wait()
|
|
115
|
-
} else {
|
|
116
|
-
console.log('Devnet is ready')
|
|
117
|
-
await timeout(1000)
|
|
118
|
-
new Promise((resolve) => {
|
|
119
|
-
resolve()
|
|
120
|
-
})
|
|
121
|
-
}
|
|
122
|
-
} catch (err) {
|
|
123
|
-
await timeout(1000)
|
|
124
|
-
await wait()
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
async function main() {
|
|
129
|
-
const tag = process.argv[2]
|
|
130
|
-
console.log(`Full node version: ${tag}`)
|
|
131
|
-
const devDir = path.resolve(process.cwd() + path.sep + 'dev')
|
|
132
|
-
const jarFile = `${devDir}${path.sep}alephium-${tag}.jar`
|
|
133
|
-
|
|
134
|
-
console.log(`Dev folder: ${devDir}`)
|
|
135
|
-
await downloadFullNode(tag, devDir, jarFile)
|
|
136
|
-
launchDevnet(devDir, jarFile)
|
|
137
|
-
await wait()
|
|
138
|
-
await prepareWallet()
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
main()
|
package/scripts/stop-devnet.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2018 - 2022 The Alephium Authors
|
|
3
|
-
This file is part of the alephium project.
|
|
4
|
-
|
|
5
|
-
The library is free software: you can redistribute it and/or modify
|
|
6
|
-
it under the terms of the GNU Lesser General Public License as published by
|
|
7
|
-
the Free Software Foundation, either version 3 of the License, or
|
|
8
|
-
(at your option) any later version.
|
|
9
|
-
|
|
10
|
-
The library is distributed in the hope that it will be useful,
|
|
11
|
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
-
GNU Lesser General Public License for more details.
|
|
14
|
-
|
|
15
|
-
You should have received a copy of the GNU Lesser General Public License
|
|
16
|
-
along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
const fs = require('fs')
|
|
20
|
-
const process = require('process')
|
|
21
|
-
const path = require('path')
|
|
22
|
-
|
|
23
|
-
const pidFile = process.cwd() + path.sep + 'dev' + path.sep + 'alephium.pid'
|
|
24
|
-
try {
|
|
25
|
-
const pid = parseInt(fs.readFileSync(pidFile).toString())
|
|
26
|
-
if (pid) {
|
|
27
|
-
console.log(`Stopping the running devnet: ${pid}`)
|
|
28
|
-
process.kill(pid)
|
|
29
|
-
}
|
|
30
|
-
} catch (e) {
|
|
31
|
-
console.log(`Error in stopping the running devnet: ${e}`)
|
|
32
|
-
}
|