@alephium/web3 0.2.0-rc.8 → 0.2.0-test.1
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/.eslintrc.json +21 -0
- package/LICENSE +165 -0
- package/README.md +135 -2
- package/contracts/add/add.ral +13 -0
- package/contracts/greeter_main.ral +1 -1
- package/contracts/main.ral +4 -0
- package/contracts/sub/sub.ral +10 -0
- package/contracts/test/metadata.ral +18 -0
- package/contracts/test/warnings.ral +8 -0
- package/dist/alephium-web3.min.js +1 -1
- package/dist/alephium-web3.min.js.LICENSE.txt +17 -0
- package/dist/alephium-web3.min.js.map +1 -1
- package/dist/scripts/create-project.js +1 -1
- package/dist/src/api/api-alephium.d.ts +6 -19
- package/dist/src/api/api-explorer.d.ts +16 -16
- package/dist/src/api/index.js +1 -5
- package/dist/src/contract/contract.d.ts +16 -31
- package/dist/src/contract/contract.js +96 -123
- package/dist/src/contract/index.js +1 -5
- package/dist/src/index.d.ts +0 -1
- package/dist/src/index.js +1 -19
- package/dist/src/signer/index.d.ts +1 -0
- package/dist/src/signer/index.js +2 -5
- package/dist/src/signer/node-wallet.d.ts +11 -0
- package/dist/src/signer/node-wallet.js +57 -0
- package/dist/src/signer/signer.js +1 -5
- package/dist/src/test/index.d.ts +6 -0
- package/dist/src/test/index.js +41 -0
- package/dist/src/test/privatekey-wallet.d.ts +11 -0
- package/dist/src/test/privatekey-wallet.js +68 -0
- package/dist/src/transaction/index.d.ts +1 -0
- package/dist/src/transaction/index.js +2 -5
- package/dist/src/transaction/sign-verify.d.ts +2 -0
- package/dist/src/transaction/sign-verify.js +58 -0
- package/dist/src/utils/index.d.ts +1 -0
- package/dist/src/utils/index.js +2 -5
- package/dist/src/utils/password-crypto.d.ts +2 -0
- package/dist/src/utils/password-crypto.js +69 -0
- package/dist/src/utils/utils.d.ts +2 -3
- package/dist/src/utils/utils.js +15 -16
- package/gitignore +9 -0
- package/package.json +32 -6
- package/scripts/create-project.ts +1 -1
- package/src/api/api-alephium.ts +0 -14
- package/src/contract/contract.ts +102 -176
- package/src/contract/ralph.test.ts +178 -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 +0 -2
- package/src/signer/fixtures/genesis.json +26 -0
- package/src/signer/fixtures/wallets.json +26 -0
- package/src/signer/index.ts +1 -0
- package/src/signer/node-wallet.ts +65 -0
- package/src/test/index.ts +31 -0
- package/src/test/privatekey-wallet.ts +57 -0
- package/src/transaction/index.ts +1 -0
- package/src/transaction/sign-verify.test.ts +50 -0
- package/src/transaction/sign-verify.ts +39 -0
- package/src/utils/address.test.ts +47 -0
- package/src/utils/djb2.test.ts +35 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/password-crypto.test.ts +27 -0
- package/src/utils/password-crypto.ts +77 -0
- package/src/utils/utils.test.ts +161 -0
- package/src/utils/utils.ts +7 -7
- package/templates/base/package.json +1 -1
- package/templates/react/package.json +1 -1
- package/test/contract.test.ts +213 -0
- package/test/events.test.ts +141 -0
- package/test/transaction.test.ts +73 -0
- package/jest-config.json +0 -11
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Account, SignerWithNodeProvider } from '../signer';
|
|
2
|
+
export declare class PrivateKeyWallet extends SignerWithNodeProvider {
|
|
3
|
+
readonly privateKey: string;
|
|
4
|
+
readonly publicKey: string;
|
|
5
|
+
readonly address: string;
|
|
6
|
+
readonly group: number;
|
|
7
|
+
constructor(privateKey: string, alwaysSubmitTx?: boolean);
|
|
8
|
+
static Random(alwaysSubmitTx?: boolean): PrivateKeyWallet;
|
|
9
|
+
getAccounts(): Promise<Account[]>;
|
|
10
|
+
signRaw(signerAddress: string, hexString: string): Promise<string>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
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(privateKey, alwaysSubmitTx = true) {
|
|
46
|
+
super(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(alwaysSubmitTx = true) {
|
|
53
|
+
const keyPair = ec.genKeyPair();
|
|
54
|
+
return new PrivateKeyWallet(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;
|
|
@@ -18,11 +18,7 @@ along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
18
18
|
*/
|
|
19
19
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
20
20
|
if (k2 === undefined) k2 = k;
|
|
21
|
-
|
|
22
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
23
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
24
|
-
}
|
|
25
|
-
Object.defineProperty(o, k2, desc);
|
|
21
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
26
22
|
}) : (function(o, m, k, k2) {
|
|
27
23
|
if (k2 === undefined) k2 = k;
|
|
28
24
|
o[k2] = m[k];
|
|
@@ -31,4 +27,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
31
27
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
32
28
|
};
|
|
33
29
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
+
__exportStar(require("./sign-verify"), exports);
|
|
34
31
|
__exportStar(require("./status"), exports);
|
|
@@ -0,0 +1,58 @@
|
|
|
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;
|
package/dist/src/utils/index.js
CHANGED
|
@@ -18,11 +18,7 @@ along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
18
18
|
*/
|
|
19
19
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
20
20
|
if (k2 === undefined) k2 = k;
|
|
21
|
-
|
|
22
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
23
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
24
|
-
}
|
|
25
|
-
Object.defineProperty(o, k2, desc);
|
|
21
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
26
22
|
}) : (function(o, m, k, k2) {
|
|
27
23
|
if (k2 === undefined) k2 = k;
|
|
28
24
|
o[k2] = m[k];
|
|
@@ -34,5 +30,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
34
30
|
__exportStar(require("./address"), exports);
|
|
35
31
|
__exportStar(require("./bs58"), exports);
|
|
36
32
|
__exportStar(require("./djb2"), exports);
|
|
33
|
+
__exportStar(require("./password-crypto"), exports);
|
|
37
34
|
__exportStar(require("./utils"), exports);
|
|
38
35
|
__exportStar(require("./subscription"), exports);
|
|
@@ -0,0 +1,69 @@
|
|
|
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
|
+
};
|
|
@@ -7,10 +7,9 @@ export declare function convertHttpResponse<T>(response: node.HttpResponse<T, {
|
|
|
7
7
|
detail: string;
|
|
8
8
|
}>): T;
|
|
9
9
|
export declare function signatureEncode(signature: EC.Signature): string;
|
|
10
|
-
export declare
|
|
11
|
-
export declare function xorByte(intValue: number): number;
|
|
10
|
+
export declare const signatureDecode: (ec: EC, signature: string) => SignatureInput;
|
|
12
11
|
export declare function isHexString(input: string): boolean;
|
|
13
|
-
export declare
|
|
12
|
+
export declare const groupOfAddress: (address: string) => number;
|
|
14
13
|
export declare function contractIdFromAddress(address: string): Uint8Array;
|
|
15
14
|
export declare function tokenIdFromAddress(address: string): Uint8Array;
|
|
16
15
|
export declare function hexToBinUnsafe(hex: string): Uint8Array;
|
package/dist/src/utils/utils.js
CHANGED
|
@@ -20,7 +20,7 @@ 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.assertType = exports.timeout = exports.hexToString = 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.
|
|
23
|
+
exports.assertType = exports.timeout = exports.hexToString = 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
24
|
const elliptic_1 = require("elliptic");
|
|
25
25
|
const bn_js_1 = __importDefault(require("bn.js"));
|
|
26
26
|
const blakejs_1 = __importDefault(require("blakejs"));
|
|
@@ -49,7 +49,7 @@ function signatureEncode(signature) {
|
|
|
49
49
|
}
|
|
50
50
|
exports.signatureEncode = signatureEncode;
|
|
51
51
|
// the signature should be in hex string format for 64 bytes
|
|
52
|
-
|
|
52
|
+
const signatureDecode = (ec, signature) => {
|
|
53
53
|
if (signature.length !== 128) {
|
|
54
54
|
throw new Error('Invalid signature length');
|
|
55
55
|
}
|
|
@@ -62,16 +62,15 @@ function signatureDecode(ec, signature) {
|
|
|
62
62
|
else {
|
|
63
63
|
throw new Error('The signature is not normalized');
|
|
64
64
|
}
|
|
65
|
-
}
|
|
65
|
+
};
|
|
66
66
|
exports.signatureDecode = signatureDecode;
|
|
67
|
-
|
|
67
|
+
const xorByte = (intValue) => {
|
|
68
68
|
const byte0 = (intValue >> 24) & 0xff;
|
|
69
69
|
const byte1 = (intValue >> 16) & 0xff;
|
|
70
70
|
const byte2 = (intValue >> 8) & 0xff;
|
|
71
71
|
const byte3 = intValue & 0xff;
|
|
72
72
|
return (byte0 ^ byte1 ^ byte2 ^ byte3) & 0xff;
|
|
73
|
-
}
|
|
74
|
-
exports.xorByte = xorByte;
|
|
73
|
+
};
|
|
75
74
|
function isHexString(input) {
|
|
76
75
|
return input.length % 2 === 0 && /[0-9a-f]*$/.test(input);
|
|
77
76
|
}
|
|
@@ -83,7 +82,7 @@ var AddressType;
|
|
|
83
82
|
AddressType[AddressType["P2SH"] = 2] = "P2SH";
|
|
84
83
|
AddressType[AddressType["P2C"] = 3] = "P2C";
|
|
85
84
|
})(AddressType || (AddressType = {}));
|
|
86
|
-
|
|
85
|
+
const groupOfAddress = (address) => {
|
|
87
86
|
const decoded = bs58_1.default.decode(address);
|
|
88
87
|
if (decoded.length == 0)
|
|
89
88
|
throw new Error('Address string is empty');
|
|
@@ -101,32 +100,32 @@ function groupOfAddress(address) {
|
|
|
101
100
|
else {
|
|
102
101
|
throw new Error(`Invalid asset address type: ${addressType}`);
|
|
103
102
|
}
|
|
104
|
-
}
|
|
103
|
+
};
|
|
105
104
|
exports.groupOfAddress = groupOfAddress;
|
|
106
|
-
|
|
105
|
+
const groupOfAddressBytes = (bytes) => {
|
|
107
106
|
const hint = (0, djb2_1.default)(bytes) | 1;
|
|
108
107
|
const hash = xorByte(hint);
|
|
109
108
|
const group = hash % constants_1.TOTAL_NUMBER_OF_GROUPS;
|
|
110
109
|
return group;
|
|
111
|
-
}
|
|
110
|
+
};
|
|
112
111
|
// Pay to public key hash address
|
|
113
|
-
|
|
112
|
+
const groupOfP2pkhAddress = (address) => {
|
|
114
113
|
if (address.length != 32) {
|
|
115
114
|
throw new Error(`Invalid p2pkh address length: ${address.length}`);
|
|
116
115
|
}
|
|
117
116
|
return groupOfAddressBytes(address);
|
|
118
|
-
}
|
|
117
|
+
};
|
|
119
118
|
// Pay to multiple public key hash address
|
|
120
|
-
|
|
119
|
+
const groupOfP2mpkhAddress = (address) => {
|
|
121
120
|
if ((address.length - 2) % 32 != 0) {
|
|
122
121
|
throw new Error(`Invalid p2mpkh address length: ${address.length}`);
|
|
123
122
|
}
|
|
124
123
|
return groupOfAddressBytes(address.slice(1, 33));
|
|
125
|
-
}
|
|
124
|
+
};
|
|
126
125
|
// Pay to script hash address
|
|
127
|
-
|
|
126
|
+
const groupOfP2shAddress = (address) => {
|
|
128
127
|
return groupOfAddressBytes(address);
|
|
129
|
-
}
|
|
128
|
+
};
|
|
130
129
|
function contractIdFromAddress(address) {
|
|
131
130
|
return idFromAddress(address);
|
|
132
131
|
}
|
package/gitignore
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alephium/web3",
|
|
3
|
-
"version": "0.2.0-
|
|
3
|
+
"version": "0.2.0-test.1",
|
|
4
4
|
"description": "A JS/TS library to interact with the Alephium platform",
|
|
5
5
|
"license": "GPL",
|
|
6
6
|
"main": "dist/src/index.js",
|
|
@@ -27,16 +27,29 @@
|
|
|
27
27
|
},
|
|
28
28
|
"author": "Alephium dev <dev@alephium.org>",
|
|
29
29
|
"config": {
|
|
30
|
-
"alephium_version": "1.5.0-
|
|
30
|
+
"alephium_version": "1.5.0-rc6",
|
|
31
31
|
"explorer_backend_version": "1.7.1"
|
|
32
32
|
},
|
|
33
33
|
"scripts": {
|
|
34
34
|
"build": "rm -rf dist/* && npx tsc --build . && webpack",
|
|
35
|
-
"
|
|
35
|
+
"bundle": "webpack",
|
|
36
36
|
"update-schemas": "npm run update-schema:alephium && npm run update-schema:explorer",
|
|
37
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
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",
|
|
39
39
|
"check-versions": "node scripts/check-versions.js ${npm_package_config_alephium_version} ${npm_package_config_explorer_backend_version}",
|
|
40
|
+
"dev": "tsnd --respawn lib/index.ts",
|
|
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",
|
|
49
|
+
"prepublishOnly": "npm run build",
|
|
50
|
+
"prepack": "node scripts/rename-gitignore.js .gitignore gitignore",
|
|
51
|
+
"postpack": "node scripts/rename-gitignore.js gitignore .gitignore",
|
|
52
|
+
"prettier": "prettier --write \"**/*.{js,jsx,ts,tsx,json,md}\"",
|
|
40
53
|
"start-devnet": "node scripts/start-devnet.js ${npm_package_config_alephium_version}",
|
|
41
54
|
"restart-devnet": "npm run start-devnet",
|
|
42
55
|
"stop-devnet": "node scripts/stop-devnet.js"
|
|
@@ -51,12 +64,15 @@
|
|
|
51
64
|
"buffer": "^6.0.3",
|
|
52
65
|
"commander": "^9.1.0",
|
|
53
66
|
"cross-fetch": "^3.1.5",
|
|
67
|
+
"crypto-js": "4.1.1",
|
|
68
|
+
"elliptic": "6.5.4",
|
|
54
69
|
"eventemitter3": "^4.0.7",
|
|
55
70
|
"find-up": "^2.1.0",
|
|
56
71
|
"fs-extra": "^10.0.1"
|
|
57
72
|
},
|
|
58
73
|
"devDependencies": {
|
|
59
|
-
"@
|
|
74
|
+
"@types/crypto-js": "^4.1.1",
|
|
75
|
+
"@types/elliptic": "^6.4.13",
|
|
60
76
|
"@types/find-up": "^2.1.0",
|
|
61
77
|
"@types/fs-extra": "^9.0.13",
|
|
62
78
|
"@types/jest": "^27.5.1",
|
|
@@ -65,6 +81,7 @@
|
|
|
65
81
|
"@types/rewire": "^2.5.28",
|
|
66
82
|
"@typescript-eslint/eslint-plugin": "^4.30.0",
|
|
67
83
|
"@typescript-eslint/parser": "^4.30.0",
|
|
84
|
+
"babel-eslint": "^10.1.0",
|
|
68
85
|
"clean-webpack-plugin": "4.0.0",
|
|
69
86
|
"crypto-browserify": "^3.12.0",
|
|
70
87
|
"eslint": "^7.32.0",
|
|
@@ -88,12 +105,21 @@
|
|
|
88
105
|
"ts-jest": "^28.0.2",
|
|
89
106
|
"ts-node": "^10.7.0",
|
|
90
107
|
"tslib": "^2.3.1",
|
|
91
|
-
"typescript": "4.
|
|
108
|
+
"typescript": "^4.4.2",
|
|
92
109
|
"webpack": "^5.72.0",
|
|
93
110
|
"webpack-cli": "^4.9.2"
|
|
94
111
|
},
|
|
95
112
|
"engines": {
|
|
96
|
-
"node": ">=
|
|
113
|
+
"node": ">=14.0.0",
|
|
97
114
|
"npm": ">=7.0.0"
|
|
115
|
+
},
|
|
116
|
+
"prettier": {
|
|
117
|
+
"printWidth": 120,
|
|
118
|
+
"tabWidth": 2,
|
|
119
|
+
"useTabs": false,
|
|
120
|
+
"semi": false,
|
|
121
|
+
"singleQuote": true,
|
|
122
|
+
"bracketSameLine": false,
|
|
123
|
+
"trailingComma": "none"
|
|
98
124
|
}
|
|
99
125
|
}
|
|
@@ -73,7 +73,7 @@ function prepareShared(packageRoot: string, projectRoot: string) {
|
|
|
73
73
|
console.log('...')
|
|
74
74
|
|
|
75
75
|
fsExtra.copySync(path.join(packageRoot, 'templates/shared'), projectRoot)
|
|
76
|
-
copy('', ['.editorconfig', '.eslintignore', '.gitattributes'])
|
|
76
|
+
copy('', ['.editorconfig', '.eslintignore', '.gitattributes', 'LICENSE'])
|
|
77
77
|
copy('dev', ['user.conf'])
|
|
78
78
|
copy('scripts', ['start-devnet.js', 'stop-devnet.js'])
|
|
79
79
|
if (fsExtra.existsSync(path.join(packageRoot, 'gitignore'))) {
|
package/src/api/api-alephium.ts
CHANGED
|
@@ -422,7 +422,6 @@ export interface ChangeActiveAddress {
|
|
|
422
422
|
}
|
|
423
423
|
|
|
424
424
|
export interface CompileContractResult {
|
|
425
|
-
name: string
|
|
426
425
|
bytecode: string
|
|
427
426
|
|
|
428
427
|
/** @format 32-byte-hash */
|
|
@@ -439,22 +438,12 @@ export interface CompileProjectResult {
|
|
|
439
438
|
}
|
|
440
439
|
|
|
441
440
|
export interface CompileScriptResult {
|
|
442
|
-
name: string
|
|
443
441
|
bytecodeTemplate: string
|
|
444
442
|
fields: FieldsSig
|
|
445
443
|
functions: FunctionSig[]
|
|
446
444
|
warnings: string[]
|
|
447
445
|
}
|
|
448
446
|
|
|
449
|
-
export interface CompilerOptions {
|
|
450
|
-
ignoreUnusedConstantsWarnings?: boolean
|
|
451
|
-
ignoreUnusedVariablesWarnings?: boolean
|
|
452
|
-
ignoreUnusedFieldsWarnings?: boolean
|
|
453
|
-
ignoreUnusedPrivateFunctionsWarnings?: boolean
|
|
454
|
-
ignoreReadonlyCheckWarnings?: boolean
|
|
455
|
-
ignoreExternalCallCheckWarnings?: boolean
|
|
456
|
-
}
|
|
457
|
-
|
|
458
447
|
export interface Confirmed {
|
|
459
448
|
/** @format block-hash */
|
|
460
449
|
blockHash: string
|
|
@@ -475,7 +464,6 @@ export interface Confirmed {
|
|
|
475
464
|
|
|
476
465
|
export interface Contract {
|
|
477
466
|
code: string
|
|
478
|
-
compilerOptions?: CompilerOptions
|
|
479
467
|
}
|
|
480
468
|
|
|
481
469
|
export interface ContractEvent {
|
|
@@ -726,7 +714,6 @@ export interface Penalty {
|
|
|
726
714
|
|
|
727
715
|
export interface Project {
|
|
728
716
|
code: string
|
|
729
|
-
compilerOptions?: CompilerOptions
|
|
730
717
|
}
|
|
731
718
|
|
|
732
719
|
export interface Reachable {
|
|
@@ -755,7 +742,6 @@ export interface RevealMnemonicResult {
|
|
|
755
742
|
|
|
756
743
|
export interface Script {
|
|
757
744
|
code: string
|
|
758
|
-
compilerOptions?: CompilerOptions
|
|
759
745
|
}
|
|
760
746
|
|
|
761
747
|
export interface SelfClique {
|