@alephium/web3 0.0.3 → 0.1.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.editorconfig +13 -0
- package/.eslintignore +2 -0
- package/.eslintrc.json +21 -0
- package/README.md +2 -2
- package/contracts/add.ral +7 -3
- package/contracts/greeter.ral +3 -1
- package/contracts/greeter_interface.ral +3 -0
- package/contracts/greeter_main.ral +9 -0
- package/contracts/main.ral +3 -5
- package/dev/user.conf +8 -4
- package/dist/alephium-web3.min.js +1 -1
- package/dist/alephium-web3.min.js.map +1 -1
- package/dist/scripts/check-versions.d.ts +1 -0
- package/dist/scripts/check-versions.js +39 -0
- package/dist/{cli → scripts}/create-project.d.ts +0 -0
- package/dist/scripts/create-project.js +124 -0
- package/dist/scripts/header.d.ts +0 -0
- package/dist/scripts/header.js +18 -0
- package/dist/scripts/rename-gitignore.d.ts +1 -0
- package/dist/scripts/rename-gitignore.js +24 -0
- package/dist/scripts/start-devnet.d.ts +1 -0
- package/dist/scripts/start-devnet.js +131 -0
- package/dist/scripts/stop-devnet.d.ts +1 -0
- package/dist/scripts/stop-devnet.js +32 -0
- package/dist/{api → src/api}/api-alephium.d.ts +287 -168
- package/dist/{api → src/api}/api-alephium.js +497 -115
- package/dist/{api → src/api}/api-explorer.d.ts +117 -19
- package/dist/{api → src/api}/api-explorer.js +206 -46
- package/dist/src/api/index.d.ts +10 -0
- package/dist/src/api/index.js +55 -0
- package/dist/{lib → src}/constants.d.ts +0 -0
- package/dist/{lib → src}/constants.js +0 -0
- package/dist/src/contract/contract.d.ts +182 -0
- package/dist/src/contract/contract.js +760 -0
- package/dist/src/contract/events.d.ts +29 -0
- package/dist/src/contract/events.js +77 -0
- package/dist/src/contract/index.d.ts +3 -0
- package/dist/src/contract/index.js +32 -0
- package/dist/src/contract/ralph.d.ts +12 -0
- package/dist/src/contract/ralph.js +362 -0
- package/dist/src/index.d.ts +5 -0
- package/dist/src/index.js +34 -0
- package/dist/src/signer/index.d.ts +2 -0
- package/dist/src/signer/index.js +31 -0
- package/dist/src/signer/node-wallet.d.ts +13 -0
- package/dist/src/signer/node-wallet.js +60 -0
- package/dist/src/signer/signer.d.ts +143 -0
- package/dist/src/signer/signer.js +184 -0
- package/dist/src/test/index.d.ts +7 -0
- package/dist/src/test/index.js +41 -0
- package/dist/src/test/privatekey-wallet.d.ts +12 -0
- package/dist/src/test/privatekey-wallet.js +68 -0
- package/dist/{lib → src/utils}/address.d.ts +0 -0
- package/dist/{lib → src/utils}/address.js +1 -1
- package/dist/{lib → src/utils}/bs58.d.ts +2 -2
- package/dist/{lib → src/utils}/bs58.js +3 -1
- package/dist/{lib → src/utils}/djb2.d.ts +0 -0
- package/dist/{lib → src/utils}/djb2.js +1 -1
- package/dist/src/utils/index.d.ts +6 -0
- package/dist/src/utils/index.js +35 -0
- package/dist/{lib → src/utils}/password-crypto.d.ts +0 -0
- package/dist/{lib → src/utils}/password-crypto.js +8 -7
- package/dist/src/utils/transaction.d.ts +2 -0
- package/dist/src/utils/transaction.js +58 -0
- package/dist/src/utils/utils.d.ts +30 -0
- package/dist/{lib → src/utils}/utils.js +83 -19
- package/gitignore +5 -4
- package/package.json +56 -40
- package/scripts/create-project.ts +136 -0
- package/scripts/header.js +17 -0
- package/scripts/start-devnet.js +3 -3
- package/src/api/api-alephium.ts +2323 -0
- package/src/api/api-explorer.ts +808 -0
- package/src/api/index.ts +35 -0
- package/src/constants.ts +20 -0
- package/src/contract/contract.ts +1014 -0
- package/src/contract/events.ts +102 -0
- package/src/contract/index.ts +21 -0
- package/src/contract/ralph.test.ts +178 -0
- package/src/contract/ralph.ts +362 -0
- package/src/fixtures/address.json +36 -0
- package/src/fixtures/balance.json +9 -0
- package/src/fixtures/self-clique.json +19 -0
- package/src/fixtures/transaction.json +13 -0
- package/src/fixtures/transactions.json +179 -0
- package/src/index.ts +24 -0
- package/src/signer/fixtures/genesis.json +26 -0
- package/src/signer/fixtures/wallets.json +26 -0
- package/src/signer/index.ts +20 -0
- package/src/signer/node-wallet.ts +74 -0
- package/src/signer/signer.ts +313 -0
- package/src/test/index.ts +32 -0
- package/src/test/privatekey-wallet.ts +58 -0
- package/src/utils/address.test.ts +47 -0
- package/src/utils/address.ts +39 -0
- package/src/utils/bs58.ts +26 -0
- package/src/utils/djb2.test.ts +35 -0
- package/src/utils/djb2.ts +25 -0
- package/src/utils/index.ts +24 -0
- package/src/utils/password-crypto.test.ts +27 -0
- package/src/utils/password-crypto.ts +77 -0
- package/src/utils/transaction.test.ts +50 -0
- package/src/utils/transaction.ts +39 -0
- package/src/utils/utils.test.ts +160 -0
- package/src/utils/utils.ts +209 -0
- package/templates/{README.md → base/README.md} +4 -4
- package/templates/base/package.json +35 -0
- package/templates/base/src/greeter.ts +41 -0
- package/templates/base/tsconfig.json +19 -0
- package/templates/react/README.md +34 -0
- package/templates/react/config-overrides.js +18 -0
- package/templates/react/package.json +66 -0
- package/templates/react/src/App.tsx +42 -0
- package/templates/react/src/artifacts/greeter.ral.json +26 -0
- package/templates/react/src/artifacts/greeter_main.ral.json +22 -0
- package/templates/shared/.eslintrc.json +12 -0
- package/templates/shared/scripts/header.js +0 -0
- package/test/contract.test.ts +161 -0
- package/test/events.test.ts +139 -0
- package/webpack.config.js +1 -1
- package/contracts/greeter-main.ral +0 -8
- package/dist/cli/create-project.js +0 -87
- package/dist/lib/clique.d.ts +0 -23
- package/dist/lib/clique.js +0 -149
- package/dist/lib/contract.d.ts +0 -152
- package/dist/lib/contract.js +0 -711
- package/dist/lib/explorer.d.ts +0 -8
- package/dist/lib/explorer.js +0 -46
- package/dist/lib/index.d.ts +0 -12
- package/dist/lib/index.js +0 -60
- package/dist/lib/node.d.ts +0 -10
- package/dist/lib/node.js +0 -64
- package/dist/lib/numbers.d.ts +0 -7
- package/dist/lib/numbers.js +0 -128
- package/dist/lib/signer.d.ts +0 -17
- package/dist/lib/signer.js +0 -70
- package/dist/lib/storage-browser.d.ts +0 -9
- package/dist/lib/storage-browser.js +0 -52
- package/dist/lib/storage-node.d.ts +0 -9
- package/dist/lib/storage-node.js +0 -65
- package/dist/lib/utils.d.ts +0 -11
- package/dist/lib/wallet.d.ts +0 -30
- package/dist/lib/wallet.js +0 -142
- package/templates/package.json +0 -29
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ec as EC, SignatureInput } from 'elliptic';
|
|
2
|
+
import * as node from '../api/api-alephium';
|
|
3
|
+
import * as explorer from '../api/api-explorer';
|
|
4
|
+
export declare function convertHttpResponse<T>(response: node.HttpResponse<T, {
|
|
5
|
+
detail: string;
|
|
6
|
+
}> | explorer.HttpResponse<T, {
|
|
7
|
+
detail: string;
|
|
8
|
+
}>): T;
|
|
9
|
+
export declare function signatureEncode(signature: EC.Signature): string;
|
|
10
|
+
export declare const signatureDecode: (ec: EC, signature: string) => SignatureInput;
|
|
11
|
+
export declare function isHexString(input: string): boolean;
|
|
12
|
+
export declare const groupOfAddress: (address: string) => number;
|
|
13
|
+
export declare function contractIdFromAddress(address: string): Uint8Array;
|
|
14
|
+
export declare function tokenIdFromAddress(address: string): Uint8Array;
|
|
15
|
+
export declare function hexToBinUnsafe(hex: string): Uint8Array;
|
|
16
|
+
export declare function binToHex(bin: Uint8Array): string;
|
|
17
|
+
export declare function publicKeyFromPrivateKey(privateKey: string): string;
|
|
18
|
+
export declare function addressFromPublicKey(publicKey: string): string;
|
|
19
|
+
export declare function addressFromContractId(contractId: string): string;
|
|
20
|
+
export declare function contractIdFromTx(txId: string, outputIndex: number): string;
|
|
21
|
+
export declare function subContractId(parentContractId: string, pathInHex: string): string;
|
|
22
|
+
export declare function stringToHex(str: string): string;
|
|
23
|
+
declare type _Eq<X, Y> = (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2 ? true : false;
|
|
24
|
+
export declare type Eq<X, Y> = _Eq<{
|
|
25
|
+
[P in keyof X]: X[P];
|
|
26
|
+
}, {
|
|
27
|
+
[P in keyof Y]: Y[P];
|
|
28
|
+
}>;
|
|
29
|
+
export declare function assertType<T extends true>(): void;
|
|
30
|
+
export {};
|
|
@@ -20,25 +20,33 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
20
20
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
21
21
|
};
|
|
22
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
-
exports.tokenIdFromAddress = exports.groupOfAddress = exports.
|
|
23
|
+
exports.assertType = exports.stringToHex = exports.subContractId = exports.contractIdFromTx = exports.addressFromContractId = exports.addressFromPublicKey = exports.publicKeyFromPrivateKey = exports.binToHex = exports.hexToBinUnsafe = exports.tokenIdFromAddress = exports.contractIdFromAddress = exports.groupOfAddress = exports.isHexString = exports.signatureDecode = exports.signatureEncode = exports.convertHttpResponse = void 0;
|
|
24
|
+
const elliptic_1 = require("elliptic");
|
|
24
25
|
const bn_js_1 = __importDefault(require("bn.js"));
|
|
26
|
+
const blakejs_1 = __importDefault(require("blakejs"));
|
|
25
27
|
const bs58_1 = __importDefault(require("./bs58"));
|
|
26
|
-
const
|
|
27
|
-
const
|
|
28
|
-
const constants_1 = require("./constants");
|
|
28
|
+
const buffer_1 = require("buffer/");
|
|
29
|
+
const constants_1 = require("../constants");
|
|
29
30
|
const djb2_1 = __importDefault(require("./djb2"));
|
|
30
|
-
const
|
|
31
|
+
const ec = new elliptic_1.ec('secp256k1');
|
|
32
|
+
function convertHttpResponse(response) {
|
|
33
|
+
if (response.error) {
|
|
34
|
+
throw new Error(response.error.detail);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
return response.data;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.convertHttpResponse = convertHttpResponse;
|
|
41
|
+
function signatureEncode(signature) {
|
|
31
42
|
let sNormalized = signature.s;
|
|
32
43
|
if (ec.n && signature.s.cmp(ec.nh) === 1) {
|
|
33
44
|
sNormalized = ec.n.sub(signature.s);
|
|
34
45
|
}
|
|
35
|
-
const r = signature.r.
|
|
36
|
-
const s = sNormalized.
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
xs.set(new Uint8Array(s), r.byteLength);
|
|
40
|
-
return Buffer.from(xs).toString('hex');
|
|
41
|
-
};
|
|
46
|
+
const r = signature.r.toString('hex', 66).slice(2);
|
|
47
|
+
const s = sNormalized.toString('hex', 66).slice(2);
|
|
48
|
+
return r + s;
|
|
49
|
+
}
|
|
42
50
|
exports.signatureEncode = signatureEncode;
|
|
43
51
|
// the signature should be in hex string format for 64 bytes
|
|
44
52
|
const signatureDecode = (ec, signature) => {
|
|
@@ -56,11 +64,6 @@ const signatureDecode = (ec, signature) => {
|
|
|
56
64
|
}
|
|
57
65
|
};
|
|
58
66
|
exports.signatureDecode = signatureDecode;
|
|
59
|
-
const getStorage = () => {
|
|
60
|
-
const isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';
|
|
61
|
-
return isBrowser ? new storage_browser_1.default() : new storage_node_1.default();
|
|
62
|
-
};
|
|
63
|
-
exports.getStorage = getStorage;
|
|
64
67
|
const xorByte = (intValue) => {
|
|
65
68
|
const byte0 = (intValue >> 24) & 0xff;
|
|
66
69
|
const byte1 = (intValue >> 16) & 0xff;
|
|
@@ -68,6 +71,10 @@ const xorByte = (intValue) => {
|
|
|
68
71
|
const byte3 = intValue & 0xff;
|
|
69
72
|
return (byte0 ^ byte1 ^ byte2 ^ byte3) & 0xff;
|
|
70
73
|
};
|
|
74
|
+
function isHexString(input) {
|
|
75
|
+
return input.length % 2 === 0 && /[0-9a-f]*$/.test(input);
|
|
76
|
+
}
|
|
77
|
+
exports.isHexString = isHexString;
|
|
71
78
|
var AddressType;
|
|
72
79
|
(function (AddressType) {
|
|
73
80
|
AddressType[AddressType["P2PKH"] = 0] = "P2PKH";
|
|
@@ -119,17 +126,74 @@ const groupOfP2mpkhAddress = (address) => {
|
|
|
119
126
|
const groupOfP2shAddress = (address) => {
|
|
120
127
|
return groupOfAddressBytes(address);
|
|
121
128
|
};
|
|
129
|
+
function contractIdFromAddress(address) {
|
|
130
|
+
return idFromAddress(address);
|
|
131
|
+
}
|
|
132
|
+
exports.contractIdFromAddress = contractIdFromAddress;
|
|
122
133
|
function tokenIdFromAddress(address) {
|
|
134
|
+
return idFromAddress(address);
|
|
135
|
+
}
|
|
136
|
+
exports.tokenIdFromAddress = tokenIdFromAddress;
|
|
137
|
+
function idFromAddress(address) {
|
|
123
138
|
const decoded = bs58_1.default.decode(address);
|
|
124
139
|
if (decoded.length == 0)
|
|
125
140
|
throw new Error('Address string is empty');
|
|
126
141
|
const addressType = decoded[0];
|
|
127
142
|
const addressBody = decoded.slice(1);
|
|
128
143
|
if (addressType == AddressType.P2C) {
|
|
129
|
-
return
|
|
144
|
+
return addressBody;
|
|
130
145
|
}
|
|
131
146
|
else {
|
|
132
147
|
throw new Error(`Invalid contract address type: ${addressType}`);
|
|
133
148
|
}
|
|
134
149
|
}
|
|
135
|
-
|
|
150
|
+
function hexToBinUnsafe(hex) {
|
|
151
|
+
return buffer_1.Buffer.from(hex, 'hex');
|
|
152
|
+
}
|
|
153
|
+
exports.hexToBinUnsafe = hexToBinUnsafe;
|
|
154
|
+
function binToHex(bin) {
|
|
155
|
+
return buffer_1.Buffer.from(bin).toString('hex');
|
|
156
|
+
}
|
|
157
|
+
exports.binToHex = binToHex;
|
|
158
|
+
function publicKeyFromPrivateKey(privateKey) {
|
|
159
|
+
const key = ec.keyFromPrivate(privateKey);
|
|
160
|
+
return key.getPublic(true, 'hex');
|
|
161
|
+
}
|
|
162
|
+
exports.publicKeyFromPrivateKey = publicKeyFromPrivateKey;
|
|
163
|
+
function addressFromPublicKey(publicKey) {
|
|
164
|
+
const addressType = buffer_1.Buffer.from([AddressType.P2PKH]);
|
|
165
|
+
const hash = buffer_1.Buffer.from(blakejs_1.default.blake2b(buffer_1.Buffer.from(publicKey, 'hex'), undefined, 32));
|
|
166
|
+
const bytes = buffer_1.Buffer.concat([addressType, hash]);
|
|
167
|
+
return bs58_1.default.encode(bytes);
|
|
168
|
+
}
|
|
169
|
+
exports.addressFromPublicKey = addressFromPublicKey;
|
|
170
|
+
function addressFromContractId(contractId) {
|
|
171
|
+
const addressType = buffer_1.Buffer.from([AddressType.P2C]);
|
|
172
|
+
const hash = buffer_1.Buffer.from(hexToBinUnsafe(contractId));
|
|
173
|
+
const bytes = buffer_1.Buffer.concat([addressType, hash]);
|
|
174
|
+
return bs58_1.default.encode(bytes);
|
|
175
|
+
}
|
|
176
|
+
exports.addressFromContractId = addressFromContractId;
|
|
177
|
+
function contractIdFromTx(txId, outputIndex) {
|
|
178
|
+
const txIdBin = hexToBinUnsafe(txId);
|
|
179
|
+
const data = buffer_1.Buffer.concat([txIdBin, buffer_1.Buffer.from([outputIndex])]);
|
|
180
|
+
const hash = blakejs_1.default.blake2b(data, undefined, 32);
|
|
181
|
+
return binToHex(hash);
|
|
182
|
+
}
|
|
183
|
+
exports.contractIdFromTx = contractIdFromTx;
|
|
184
|
+
function subContractId(parentContractId, pathInHex) {
|
|
185
|
+
const data = buffer_1.Buffer.concat([hexToBinUnsafe(pathInHex), hexToBinUnsafe(parentContractId)]);
|
|
186
|
+
return binToHex(blakejs_1.default.blake2b(blakejs_1.default.blake2b(data, undefined, 32), undefined, 32));
|
|
187
|
+
}
|
|
188
|
+
exports.subContractId = subContractId;
|
|
189
|
+
function stringToHex(str) {
|
|
190
|
+
let hex = '';
|
|
191
|
+
for (let i = 0; i < str.length; i++) {
|
|
192
|
+
hex += '' + str.charCodeAt(i).toString(16);
|
|
193
|
+
}
|
|
194
|
+
return hex;
|
|
195
|
+
}
|
|
196
|
+
exports.stringToHex = stringToHex;
|
|
197
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function, @typescript-eslint/no-unused-vars
|
|
198
|
+
function assertType() { }
|
|
199
|
+
exports.assertType = assertType;
|
package/gitignore
CHANGED
package/package.json
CHANGED
|
@@ -1,27 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alephium/web3",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.1.0-rc.0",
|
|
4
4
|
"description": "A JS/TS library to interact with the Alephium platform",
|
|
5
5
|
"license": "GPL",
|
|
6
|
-
"main": "dist/
|
|
6
|
+
"main": "dist/src/index.js",
|
|
7
7
|
"browser": "dist/alephium-web3.min.js",
|
|
8
|
-
"types": "dist/
|
|
8
|
+
"types": "dist/src/index.d.ts",
|
|
9
9
|
"exports": {
|
|
10
|
-
".": "./dist/
|
|
11
|
-
"./
|
|
12
|
-
"./api/explorer": "./dist/api/api-explorer.js"
|
|
10
|
+
".": "./dist/src/index.js",
|
|
11
|
+
"./test": "./dist/src/test/index.js"
|
|
13
12
|
},
|
|
14
13
|
"typesVersions": {
|
|
15
14
|
"*": {
|
|
16
|
-
"
|
|
17
|
-
"dist/
|
|
18
|
-
],
|
|
19
|
-
"api/explorer": [
|
|
20
|
-
"dist/api/api-explorer"
|
|
15
|
+
"test": [
|
|
16
|
+
"dist/src/test/"
|
|
21
17
|
]
|
|
22
18
|
}
|
|
23
19
|
},
|
|
24
|
-
"type": "commonjs",
|
|
25
20
|
"repository": {
|
|
26
21
|
"type": "git",
|
|
27
22
|
"url": "git@github.com:alephium/alephium-web3.git"
|
|
@@ -32,42 +27,47 @@
|
|
|
32
27
|
},
|
|
33
28
|
"author": "Alephium dev <dev@alephium.org>",
|
|
34
29
|
"config": {
|
|
35
|
-
"alephium_version": "1.
|
|
36
|
-
"explorer_backend_version": "1.
|
|
30
|
+
"alephium_version": "1.4.0-rc2",
|
|
31
|
+
"explorer_backend_version": "1.7.0-leman1"
|
|
37
32
|
},
|
|
38
33
|
"scripts": {
|
|
39
|
-
"build": "rm -rf dist && npx tsc --build . && webpack",
|
|
34
|
+
"build": "rm -rf dist/* && npx tsc --build . && webpack",
|
|
35
|
+
"bundle": "webpack",
|
|
40
36
|
"update-schemas": "npm run update-schema:alephium && npm run update-schema:explorer",
|
|
41
|
-
"update-schema:alephium": "npx swagger-typescript-api -t ./
|
|
42
|
-
"update-schema:explorer": "npx swagger-typescript-api -t ./
|
|
37
|
+
"update-schema:alephium": "npx swagger-typescript-api -t ./configs -o ./src/api -n api-alephium.ts -p https://raw.githubusercontent.com/alephium/alephium/v${npm_package_config_alephium_version}/api/src/main/resources/openapi.json",
|
|
38
|
+
"update-schema:explorer": "npx swagger-typescript-api -t ./configs -o ./src/api -n api-explorer.ts -p https://raw.githubusercontent.com/alephium/explorer-backend/v${npm_package_config_explorer_backend_version}/app/src/main/resources/explorer-backend-openapi.json",
|
|
43
39
|
"check-versions": "node scripts/check-versions.js ${npm_package_config_alephium_version} ${npm_package_config_explorer_backend_version}",
|
|
44
40
|
"dev": "tsnd --respawn lib/index.ts",
|
|
45
|
-
"lint": "eslint . --ext
|
|
46
|
-
"lint:fix": "eslint . --fix --ext
|
|
47
|
-
"
|
|
48
|
-
"test": "
|
|
49
|
-
"test:
|
|
41
|
+
"lint": "eslint . --ext ts",
|
|
42
|
+
"lint:fix": "eslint . --fix --ext ts",
|
|
43
|
+
"test": "jest -i --config ./configs/jest.config.ts",
|
|
44
|
+
"test:client": "jest -i --config ./configs/jest-client.config.ts",
|
|
45
|
+
"test:unit": "jest -i --config ./configs/jest-unit.config.ts",
|
|
46
|
+
"test:watch": "npm run test -- --watch --coverage=false",
|
|
47
|
+
"test:watch:unit": "npm run test:unit -- --watch --coverage=false",
|
|
48
|
+
"test:watch:client": "npm run test:client -- --watch --coverage=false",
|
|
50
49
|
"prepublishOnly": "npm run build",
|
|
51
50
|
"prepack": "node scripts/rename-gitignore.js .gitignore gitignore",
|
|
52
51
|
"postpack": "node scripts/rename-gitignore.js gitignore .gitignore",
|
|
53
|
-
"
|
|
54
|
-
"devnet
|
|
55
|
-
"devnet
|
|
56
|
-
"devnet
|
|
52
|
+
"prettier": "prettier --write \"**/*.{js,jsx,ts,tsx,json,md}\"",
|
|
53
|
+
"start-devnet": "node scripts/start-devnet.js ${npm_package_config_alephium_version}",
|
|
54
|
+
"restart-devnet": "npm run start-devnet",
|
|
55
|
+
"stop-devnet": "node scripts/stop-devnet.js"
|
|
57
56
|
},
|
|
57
|
+
"type": "commonjs",
|
|
58
58
|
"bin": {
|
|
59
|
-
"alephium": "dist/
|
|
59
|
+
"alephium": "dist/scripts/create-project.js"
|
|
60
60
|
},
|
|
61
61
|
"dependencies": {
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
"
|
|
67
|
-
"chalk": "^4.1.2",
|
|
62
|
+
"@scure/bip32": "1.0.1",
|
|
63
|
+
"base-x": "4.0.0",
|
|
64
|
+
"bip39": "3.0.4",
|
|
65
|
+
"blakejs": "1.2.1",
|
|
66
|
+
"commander": "^9.1.0",
|
|
68
67
|
"cross-fetch": "^3.1.5",
|
|
69
|
-
"crypto-js": "
|
|
70
|
-
"elliptic": "
|
|
68
|
+
"crypto-js": "4.1.1",
|
|
69
|
+
"elliptic": "6.5.4",
|
|
70
|
+
"eventemitter3": "^4.0.7",
|
|
71
71
|
"find-up": "^2.1.0",
|
|
72
72
|
"fs-extra": "^10.0.1"
|
|
73
73
|
},
|
|
@@ -76,7 +76,7 @@
|
|
|
76
76
|
"@types/elliptic": "^6.4.13",
|
|
77
77
|
"@types/find-up": "^2.1.0",
|
|
78
78
|
"@types/fs-extra": "^9.0.13",
|
|
79
|
-
"@types/jest": "^27.
|
|
79
|
+
"@types/jest": "^27.5.1",
|
|
80
80
|
"@types/mock-fs": "^4.13.1",
|
|
81
81
|
"@types/node": "^16.7.8",
|
|
82
82
|
"@types/rewire": "^2.5.28",
|
|
@@ -84,23 +84,30 @@
|
|
|
84
84
|
"@typescript-eslint/parser": "^4.30.0",
|
|
85
85
|
"babel-eslint": "^10.1.0",
|
|
86
86
|
"buffer": "^6.0.3",
|
|
87
|
+
"clean-webpack-plugin": "4.0.0",
|
|
87
88
|
"crypto-browserify": "^3.12.0",
|
|
88
89
|
"eslint": "^7.32.0",
|
|
89
|
-
"eslint-config-prettier": "^8.
|
|
90
|
+
"eslint-config-prettier": "^8.5.0",
|
|
90
91
|
"eslint-plugin-header": "^3.1.1",
|
|
91
92
|
"eslint-plugin-prettier": "^4.0.0",
|
|
92
|
-
"
|
|
93
|
+
"eslint-plugin-react": "^7.29.4",
|
|
94
|
+
"eslint-plugin-security": "1.4.0",
|
|
95
|
+
"html-webpack-plugin": "5.5.0",
|
|
96
|
+
"jest": "^28.1.0",
|
|
93
97
|
"jest-localstorage-mock": "^2.4.18",
|
|
94
98
|
"jest-websocket-mock": "^2.2.1",
|
|
95
99
|
"mock-fs": "^5.1.2",
|
|
96
100
|
"mock-socket": "^9.0.8",
|
|
97
101
|
"prettier": "^2.3.2",
|
|
102
|
+
"process": "^0.11.10",
|
|
103
|
+
"react-app-rewired": "^2.2.1",
|
|
98
104
|
"rewire": "^6.0.0",
|
|
99
105
|
"shelljs": "^0.8.5",
|
|
100
106
|
"stream-browserify": "^3.0.0",
|
|
101
107
|
"swagger-typescript-api": "^9.2.0",
|
|
102
|
-
"
|
|
103
|
-
"ts-
|
|
108
|
+
"terser-webpack-plugin": "^5.3.1",
|
|
109
|
+
"ts-jest": "^28.0.2",
|
|
110
|
+
"ts-node": "^10.7.0",
|
|
104
111
|
"tslib": "^2.3.1",
|
|
105
112
|
"typescript": "^4.4.2",
|
|
106
113
|
"webpack": "^5.72.0",
|
|
@@ -109,5 +116,14 @@
|
|
|
109
116
|
"engines": {
|
|
110
117
|
"node": ">=14.0.0",
|
|
111
118
|
"npm": ">=7.0.0"
|
|
119
|
+
},
|
|
120
|
+
"prettier": {
|
|
121
|
+
"printWidth": 120,
|
|
122
|
+
"tabWidth": 2,
|
|
123
|
+
"useTabs": false,
|
|
124
|
+
"semi": false,
|
|
125
|
+
"singleQuote": true,
|
|
126
|
+
"bracketSameLine": false,
|
|
127
|
+
"trailingComma": "none"
|
|
112
128
|
}
|
|
113
129
|
}
|
|
@@ -0,0 +1,136 @@
|
|
|
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.ral', 'greeter_interface.ral', 'greeter_main.ral'])
|
|
91
|
+
fsExtra.copySync(path.join(packageRoot, 'templates/base'), projectRoot)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function prepareReact(packageRoot: string, projectRoot: string, projectName: string) {
|
|
95
|
+
console.log('Creating the React app')
|
|
96
|
+
execSync(`npx create-react-app ${projectName} --template typescript`)
|
|
97
|
+
|
|
98
|
+
prepareShared(packageRoot, projectRoot)
|
|
99
|
+
fsExtra.copySync(path.join(packageRoot, 'templates/react'), projectRoot)
|
|
100
|
+
|
|
101
|
+
console.log('Initialize the project')
|
|
102
|
+
execSync(
|
|
103
|
+
'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',
|
|
104
|
+
{ cwd: projectRoot }
|
|
105
|
+
)
|
|
106
|
+
execSync('npm install && npm run prettier', { cwd: projectRoot })
|
|
107
|
+
console.log()
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const program = new commander.Command('Create sample project')
|
|
111
|
+
.arguments('<project-directory>')
|
|
112
|
+
.option('-t, --template <path-to-template>', 'specify a template for the project: either base or react')
|
|
113
|
+
.parse(process.argv)
|
|
114
|
+
|
|
115
|
+
const projectName = program.processedArgs[0]
|
|
116
|
+
const projectType = program.opts()['template']
|
|
117
|
+
|
|
118
|
+
const packageRoot = getPackageRoot()
|
|
119
|
+
const projectParent = process.cwd()
|
|
120
|
+
const projectRoot = extractProjectRoot()
|
|
121
|
+
|
|
122
|
+
switch (extractProjectType(projectType)) {
|
|
123
|
+
case 'base':
|
|
124
|
+
prepareBase(packageRoot, projectRoot)
|
|
125
|
+
break
|
|
126
|
+
case 'react':
|
|
127
|
+
prepareReact(packageRoot, projectRoot, projectName)
|
|
128
|
+
break
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
console.log('✅ Done.')
|
|
132
|
+
console.log()
|
|
133
|
+
console.log('✨ Project is initialized!')
|
|
134
|
+
console.log()
|
|
135
|
+
console.log(`Next step: checkout the readme under <${projectName}>`)
|
|
136
|
+
console.log()
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
*/
|
package/scripts/start-devnet.js
CHANGED
|
@@ -71,10 +71,10 @@ function launchDevnet(devDir, jarFile) {
|
|
|
71
71
|
fs.writeFileSync(devDir + path.sep + 'alephium.pid', p.pid.toString(), { falg: 'w' })
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
const testWallet = 'alephium-
|
|
74
|
+
const testWallet = 'alephium-web3-test-only-wallet'
|
|
75
75
|
const password = 'alph'
|
|
76
76
|
const mnemonic =
|
|
77
|
-
'vault
|
|
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
78
|
|
|
79
79
|
async function prepareWallet() {
|
|
80
80
|
const wallets = await fetch('http://127.0.0.1:22973/wallets', { method: 'Get' }).then((res) => res.json())
|
|
@@ -95,7 +95,7 @@ async function createWallet() {
|
|
|
95
95
|
|
|
96
96
|
async function unlockWallet() {
|
|
97
97
|
console.log('Unlock the test wallet')
|
|
98
|
-
await fetch('http://127.0.0.1:22973/wallets/alephium-
|
|
98
|
+
await fetch('http://127.0.0.1:22973/wallets/alephium-web3-test-only-wallet/unlock', {
|
|
99
99
|
method: 'POST',
|
|
100
100
|
body: '{ "password": "alph" }'
|
|
101
101
|
})
|