@alephium/web3 0.2.0-rc.1 → 0.2.0-rc.10
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/contracts/greeter/greeter.ral +2 -2
- package/contracts/greeter/greeter_interface.ral +1 -0
- package/contracts/greeter_main.ral +0 -2
- 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/scripts/create-project.js +3 -2
- package/dist/src/api/api-alephium.d.ts +44 -11
- package/dist/src/api/api-alephium.js +16 -0
- package/dist/src/api/api-explorer.d.ts +16 -16
- package/dist/src/api/index.d.ts +2 -2
- package/dist/src/api/index.js +18 -3
- package/dist/src/contract/contract.d.ts +101 -52
- package/dist/src/contract/contract.js +353 -219
- package/dist/src/contract/index.js +5 -1
- package/dist/src/global.d.ts +4 -0
- package/dist/src/global.js +38 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.js +20 -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 +1 -1
- package/dist/src/signer/signer.js +8 -3
- package/dist/src/transaction/index.d.ts +0 -1
- package/dist/src/transaction/index.js +5 -2
- 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 -1
- package/dist/src/utils/subscription.js +2 -1
- package/dist/src/utils/utils.d.ts +5 -4
- package/dist/src/utils/utils.js +17 -16
- package/jest-config.json +11 -0
- package/package.json +6 -34
- package/scripts/create-project.ts +3 -2
- package/src/api/api-alephium.ts +53 -5
- package/src/api/index.ts +13 -3
- package/src/contract/contract.ts +505 -318
- package/src/contract/events.ts +2 -2
- package/src/{transaction/sign-verify.ts → global.ts} +14 -15
- package/src/index.ts +3 -0
- package/src/signer/index.ts +0 -1
- package/src/signer/signer.ts +3 -2
- package/src/transaction/index.ts +0 -1
- package/src/transaction/status.ts +1 -1
- package/src/utils/index.ts +0 -1
- package/src/utils/subscription.ts +3 -3
- package/src/utils/utils.ts +10 -10
- package/templates/base/package.json +2 -2
- package/templates/base/src/greeter.ts +8 -7
- package/templates/react/package.json +2 -2
- package/templates/react/src/App.tsx +2 -2
- package/.eslintrc.json +0 -21
- package/LICENSE +0 -165
- package/contracts/add/add.ral +0 -16
- package/contracts/main.ral +0 -6
- package/contracts/sub/sub.ral +0 -9
- 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/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/test/contract.test.ts +0 -178
- package/test/events.test.ts +0 -138
- package/test/transaction.test.ts +0 -72
|
@@ -18,7 +18,11 @@ 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
|
-
Object.
|
|
21
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
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);
|
|
22
26
|
}) : (function(o, m, k, k2) {
|
|
23
27
|
if (k2 === undefined) k2 = k;
|
|
24
28
|
o[k2] = m[k];
|
|
@@ -0,0 +1,38 @@
|
|
|
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.getCurrentNodeProvider = exports.setCurrentNodeProvider = void 0;
|
|
21
|
+
const api_1 = require("./api");
|
|
22
|
+
let _currentNodeProvider = undefined;
|
|
23
|
+
function setCurrentNodeProvider(provider, apiKey) {
|
|
24
|
+
if (typeof provider == 'string') {
|
|
25
|
+
_currentNodeProvider = new api_1.NodeProvider(provider, apiKey);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
_currentNodeProvider = provider;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.setCurrentNodeProvider = setCurrentNodeProvider;
|
|
32
|
+
function getCurrentNodeProvider() {
|
|
33
|
+
if (typeof _currentNodeProvider === 'undefined') {
|
|
34
|
+
throw Error('No node provider is set.');
|
|
35
|
+
}
|
|
36
|
+
return _currentNodeProvider;
|
|
37
|
+
}
|
|
38
|
+
exports.getCurrentNodeProvider = getCurrentNodeProvider;
|
package/dist/src/index.d.ts
CHANGED
package/dist/src/index.js
CHANGED
|
@@ -18,18 +18,37 @@ 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
|
-
Object.
|
|
21
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
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);
|
|
22
26
|
}) : (function(o, m, k, k2) {
|
|
23
27
|
if (k2 === undefined) k2 = k;
|
|
24
28
|
o[k2] = m[k];
|
|
25
29
|
}));
|
|
30
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
31
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
32
|
+
}) : function(o, v) {
|
|
33
|
+
o["default"] = v;
|
|
34
|
+
});
|
|
26
35
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
27
36
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
28
37
|
};
|
|
38
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
39
|
+
if (mod && mod.__esModule) return mod;
|
|
40
|
+
var result = {};
|
|
41
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
42
|
+
__setModuleDefault(result, mod);
|
|
43
|
+
return result;
|
|
44
|
+
};
|
|
29
45
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
46
|
+
exports.utils = exports.web3 = void 0;
|
|
30
47
|
__exportStar(require("./api"), exports);
|
|
31
48
|
__exportStar(require("./contract"), exports);
|
|
32
49
|
__exportStar(require("./signer"), exports);
|
|
33
50
|
__exportStar(require("./utils"), exports);
|
|
34
51
|
__exportStar(require("./transaction"), exports);
|
|
35
52
|
__exportStar(require("./constants"), exports);
|
|
53
|
+
exports.web3 = __importStar(require("./global"));
|
|
54
|
+
exports.utils = __importStar(require("./utils"));
|
package/dist/src/signer/index.js
CHANGED
|
@@ -18,7 +18,11 @@ 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
|
-
Object.
|
|
21
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
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);
|
|
22
26
|
}) : (function(o, m, k, k2) {
|
|
23
27
|
if (k2 === undefined) k2 = k;
|
|
24
28
|
o[k2] = m[k];
|
|
@@ -28,4 +32,3 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
28
32
|
};
|
|
29
33
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
34
|
__exportStar(require("./signer"), exports);
|
|
31
|
-
__exportStar(require("./node-wallet"), exports);
|
|
@@ -111,7 +111,7 @@ export declare abstract class SignerWithNodeProvider implements SignerProvider {
|
|
|
111
111
|
alwaysSubmitTx: boolean;
|
|
112
112
|
abstract getAccounts(): Promise<Account[]>;
|
|
113
113
|
getAccount(signerAddress: string): Promise<Account>;
|
|
114
|
-
constructor(
|
|
114
|
+
constructor(alwaysSubmitTx: boolean);
|
|
115
115
|
private defaultSignerAddress;
|
|
116
116
|
submitTransaction(unsignedTx: string, txHash: string, signerAddress?: string): Promise<SubmissionResult>;
|
|
117
117
|
private shouldSubmitTx;
|
|
@@ -18,7 +18,11 @@ 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
|
-
Object.
|
|
21
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
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);
|
|
22
26
|
}) : (function(o, m, k, k2) {
|
|
23
27
|
if (k2 === undefined) k2 = k;
|
|
24
28
|
o[k2] = m[k];
|
|
@@ -44,6 +48,7 @@ const elliptic_1 = require("elliptic");
|
|
|
44
48
|
const utils = __importStar(require("../utils"));
|
|
45
49
|
const utils_1 = require("../utils");
|
|
46
50
|
const blakejs_1 = __importDefault(require("blakejs"));
|
|
51
|
+
const global_1 = require("../global");
|
|
47
52
|
const ec = new elliptic_1.ec('secp256k1');
|
|
48
53
|
(0, utils_1.assertType)();
|
|
49
54
|
(0, utils_1.assertType)();
|
|
@@ -58,8 +63,8 @@ const ec = new elliptic_1.ec('secp256k1');
|
|
|
58
63
|
(0, utils_1.assertType)();
|
|
59
64
|
(0, utils_1.assertType)();
|
|
60
65
|
class SignerWithNodeProvider {
|
|
61
|
-
constructor(
|
|
62
|
-
this.provider =
|
|
66
|
+
constructor(alwaysSubmitTx) {
|
|
67
|
+
this.provider = (0, global_1.getCurrentNodeProvider)();
|
|
63
68
|
this.alwaysSubmitTx = alwaysSubmitTx;
|
|
64
69
|
}
|
|
65
70
|
async getAccount(signerAddress) {
|
|
@@ -18,7 +18,11 @@ 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
|
-
Object.
|
|
21
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
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);
|
|
22
26
|
}) : (function(o, m, k, k2) {
|
|
23
27
|
if (k2 === undefined) k2 = k;
|
|
24
28
|
o[k2] = m[k];
|
|
@@ -27,5 +31,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
27
31
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
28
32
|
};
|
|
29
33
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
-
__exportStar(require("./sign-verify"), exports);
|
|
31
34
|
__exportStar(require("./status"), exports);
|
package/dist/src/utils/index.js
CHANGED
|
@@ -18,7 +18,11 @@ 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
|
-
Object.
|
|
21
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
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);
|
|
22
26
|
}) : (function(o, m, k, k2) {
|
|
23
27
|
if (k2 === undefined) k2 = k;
|
|
24
28
|
o[k2] = m[k];
|
|
@@ -30,6 +34,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
30
34
|
__exportStar(require("./address"), exports);
|
|
31
35
|
__exportStar(require("./bs58"), exports);
|
|
32
36
|
__exportStar(require("./djb2"), exports);
|
|
33
|
-
__exportStar(require("./password-crypto"), exports);
|
|
34
37
|
__exportStar(require("./utils"), exports);
|
|
35
38
|
__exportStar(require("./subscription"), exports);
|
|
@@ -3,7 +3,6 @@ import { NodeProvider } from '../api';
|
|
|
3
3
|
declare type MessageCallback<Message> = (message: Message) => Promise<void>;
|
|
4
4
|
declare type ErrorCallback<Message> = (error: any, subscription: Subscription<Message>) => Promise<void>;
|
|
5
5
|
export interface SubscribeOptions<Message> {
|
|
6
|
-
provider: NodeProvider;
|
|
7
6
|
pollingInterval: number;
|
|
8
7
|
messageCallback: MessageCallback<Message>;
|
|
9
8
|
errorCallback: ErrorCallback<Message>;
|
|
@@ -22,9 +22,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
22
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
23
|
exports.Subscription = void 0;
|
|
24
24
|
const eventemitter3_1 = __importDefault(require("eventemitter3"));
|
|
25
|
+
const global_1 = require("../global");
|
|
25
26
|
class Subscription {
|
|
26
27
|
constructor(options) {
|
|
27
|
-
this.provider =
|
|
28
|
+
this.provider = (0, global_1.getCurrentNodeProvider)();
|
|
28
29
|
this.pollingInterval = options.pollingInterval;
|
|
29
30
|
this.messageCallback = options.messageCallback;
|
|
30
31
|
this.errorCallback = options.errorCallback;
|
|
@@ -7,9 +7,10 @@ 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
|
|
10
|
+
export declare function signatureDecode(ec: EC, signature: string): SignatureInput;
|
|
11
|
+
export declare function xorByte(intValue: number): number;
|
|
11
12
|
export declare function isHexString(input: string): boolean;
|
|
12
|
-
export declare
|
|
13
|
+
export declare function groupOfAddress(address: string): number;
|
|
13
14
|
export declare function contractIdFromAddress(address: string): Uint8Array;
|
|
14
15
|
export declare function tokenIdFromAddress(address: string): Uint8Array;
|
|
15
16
|
export declare function hexToBinUnsafe(hex: string): Uint8Array;
|
|
@@ -20,8 +21,8 @@ export declare function addressFromContractId(contractId: string): string;
|
|
|
20
21
|
export declare function contractIdFromTx(txId: string, outputIndex: number): string;
|
|
21
22
|
export declare function subContractId(parentContractId: string, pathInHex: string): string;
|
|
22
23
|
export declare function stringToHex(str: string): string;
|
|
23
|
-
export declare function hexToString(str:
|
|
24
|
-
export declare function timeout(ms: number): Promise<
|
|
24
|
+
export declare function hexToString(str: string): string;
|
|
25
|
+
export declare function timeout(ms: number): Promise<void>;
|
|
25
26
|
declare type _Eq<X, Y> = (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2 ? true : false;
|
|
26
27
|
export declare type Eq<X, Y> = _Eq<{
|
|
27
28
|
[P in keyof X]: X[P];
|
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.signatureDecode = exports.signatureEncode = exports.convertHttpResponse = void 0;
|
|
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.xorByte = 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
|
+
function signatureDecode(ec, signature) {
|
|
53
53
|
if (signature.length !== 128) {
|
|
54
54
|
throw new Error('Invalid signature length');
|
|
55
55
|
}
|
|
@@ -62,15 +62,16 @@ const 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
|
+
function 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
|
-
}
|
|
73
|
+
}
|
|
74
|
+
exports.xorByte = xorByte;
|
|
74
75
|
function isHexString(input) {
|
|
75
76
|
return input.length % 2 === 0 && /[0-9a-f]*$/.test(input);
|
|
76
77
|
}
|
|
@@ -82,7 +83,7 @@ var AddressType;
|
|
|
82
83
|
AddressType[AddressType["P2SH"] = 2] = "P2SH";
|
|
83
84
|
AddressType[AddressType["P2C"] = 3] = "P2C";
|
|
84
85
|
})(AddressType || (AddressType = {}));
|
|
85
|
-
|
|
86
|
+
function groupOfAddress(address) {
|
|
86
87
|
const decoded = bs58_1.default.decode(address);
|
|
87
88
|
if (decoded.length == 0)
|
|
88
89
|
throw new Error('Address string is empty');
|
|
@@ -100,32 +101,32 @@ const groupOfAddress = (address) => {
|
|
|
100
101
|
else {
|
|
101
102
|
throw new Error(`Invalid asset address type: ${addressType}`);
|
|
102
103
|
}
|
|
103
|
-
}
|
|
104
|
+
}
|
|
104
105
|
exports.groupOfAddress = groupOfAddress;
|
|
105
|
-
|
|
106
|
+
function groupOfAddressBytes(bytes) {
|
|
106
107
|
const hint = (0, djb2_1.default)(bytes) | 1;
|
|
107
108
|
const hash = xorByte(hint);
|
|
108
109
|
const group = hash % constants_1.TOTAL_NUMBER_OF_GROUPS;
|
|
109
110
|
return group;
|
|
110
|
-
}
|
|
111
|
+
}
|
|
111
112
|
// Pay to public key hash address
|
|
112
|
-
|
|
113
|
+
function groupOfP2pkhAddress(address) {
|
|
113
114
|
if (address.length != 32) {
|
|
114
115
|
throw new Error(`Invalid p2pkh address length: ${address.length}`);
|
|
115
116
|
}
|
|
116
117
|
return groupOfAddressBytes(address);
|
|
117
|
-
}
|
|
118
|
+
}
|
|
118
119
|
// Pay to multiple public key hash address
|
|
119
|
-
|
|
120
|
+
function groupOfP2mpkhAddress(address) {
|
|
120
121
|
if ((address.length - 2) % 32 != 0) {
|
|
121
122
|
throw new Error(`Invalid p2mpkh address length: ${address.length}`);
|
|
122
123
|
}
|
|
123
124
|
return groupOfAddressBytes(address.slice(1, 33));
|
|
124
|
-
}
|
|
125
|
+
}
|
|
125
126
|
// Pay to script hash address
|
|
126
|
-
|
|
127
|
+
function groupOfP2shAddress(address) {
|
|
127
128
|
return groupOfAddressBytes(address);
|
|
128
|
-
}
|
|
129
|
+
}
|
|
129
130
|
function contractIdFromAddress(address) {
|
|
130
131
|
return idFromAddress(address);
|
|
131
132
|
}
|
|
@@ -195,7 +196,7 @@ function stringToHex(str) {
|
|
|
195
196
|
}
|
|
196
197
|
exports.stringToHex = stringToHex;
|
|
197
198
|
function hexToString(str) {
|
|
198
|
-
return buffer_1.Buffer.from(str
|
|
199
|
+
return buffer_1.Buffer.from(str, 'hex').toString();
|
|
199
200
|
}
|
|
200
201
|
exports.hexToString = hexToString;
|
|
201
202
|
function timeout(ms) {
|
package/jest-config.json
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"testPathIgnorePatterns": [".*/node_modules/"],
|
|
3
|
+
"transform": {
|
|
4
|
+
"^.+\\.(t|j)sx?$": "ts-jest"
|
|
5
|
+
},
|
|
6
|
+
"testMatch": ["**/*.test.ts"],
|
|
7
|
+
"moduleFileExtensions": ["ts", "tsx", "js", "jsx", "json", "node"],
|
|
8
|
+
"collectCoverage": true,
|
|
9
|
+
"coverageDirectory": "./coverage/",
|
|
10
|
+
"collectCoverageFrom": ["src/**/*.ts"]
|
|
11
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alephium/web3",
|
|
3
|
-
"version": "0.2.0-rc.
|
|
3
|
+
"version": "0.2.0-rc.10",
|
|
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,29 +27,16 @@
|
|
|
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-rc7",
|
|
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
|
+
"test": "jest -i --config ./jest-config.json",
|
|
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}\"",
|
|
53
40
|
"start-devnet": "node scripts/start-devnet.js ${npm_package_config_alephium_version}",
|
|
54
41
|
"restart-devnet": "npm run start-devnet",
|
|
55
42
|
"stop-devnet": "node scripts/stop-devnet.js"
|
|
@@ -64,15 +51,12 @@
|
|
|
64
51
|
"buffer": "^6.0.3",
|
|
65
52
|
"commander": "^9.1.0",
|
|
66
53
|
"cross-fetch": "^3.1.5",
|
|
67
|
-
"crypto-js": "4.1.1",
|
|
68
|
-
"elliptic": "6.5.4",
|
|
69
54
|
"eventemitter3": "^4.0.7",
|
|
70
55
|
"find-up": "^2.1.0",
|
|
71
56
|
"fs-extra": "^10.0.1"
|
|
72
57
|
},
|
|
73
58
|
"devDependencies": {
|
|
74
|
-
"@
|
|
75
|
-
"@types/elliptic": "^6.4.13",
|
|
59
|
+
"@babel/eslint-parser": "^7.18.9",
|
|
76
60
|
"@types/find-up": "^2.1.0",
|
|
77
61
|
"@types/fs-extra": "^9.0.13",
|
|
78
62
|
"@types/jest": "^27.5.1",
|
|
@@ -81,14 +65,12 @@
|
|
|
81
65
|
"@types/rewire": "^2.5.28",
|
|
82
66
|
"@typescript-eslint/eslint-plugin": "^4.30.0",
|
|
83
67
|
"@typescript-eslint/parser": "^4.30.0",
|
|
84
|
-
"babel-eslint": "^10.1.0",
|
|
85
68
|
"clean-webpack-plugin": "4.0.0",
|
|
86
69
|
"crypto-browserify": "^3.12.0",
|
|
87
70
|
"eslint": "^7.32.0",
|
|
88
71
|
"eslint-config-prettier": "^8.5.0",
|
|
89
72
|
"eslint-plugin-header": "^3.1.1",
|
|
90
73
|
"eslint-plugin-prettier": "^4.0.0",
|
|
91
|
-
"eslint-plugin-react": "^7.29.4",
|
|
92
74
|
"eslint-plugin-security": "1.4.0",
|
|
93
75
|
"html-webpack-plugin": "5.5.0",
|
|
94
76
|
"jest": "^28.1.0",
|
|
@@ -98,7 +80,6 @@
|
|
|
98
80
|
"mock-socket": "^9.0.8",
|
|
99
81
|
"prettier": "^2.3.2",
|
|
100
82
|
"process": "^0.11.10",
|
|
101
|
-
"react-app-rewired": "^2.2.1",
|
|
102
83
|
"rewire": "^6.0.0",
|
|
103
84
|
"shelljs": "^0.8.5",
|
|
104
85
|
"stream-browserify": "^3.0.0",
|
|
@@ -107,21 +88,12 @@
|
|
|
107
88
|
"ts-jest": "^28.0.2",
|
|
108
89
|
"ts-node": "^10.7.0",
|
|
109
90
|
"tslib": "^2.3.1",
|
|
110
|
-
"typescript": "
|
|
91
|
+
"typescript": "4.7.4",
|
|
111
92
|
"webpack": "^5.72.0",
|
|
112
93
|
"webpack-cli": "^4.9.2"
|
|
113
94
|
},
|
|
114
95
|
"engines": {
|
|
115
|
-
"node": ">=
|
|
96
|
+
"node": ">=16.0.0",
|
|
116
97
|
"npm": ">=7.0.0"
|
|
117
|
-
},
|
|
118
|
-
"prettier": {
|
|
119
|
-
"printWidth": 120,
|
|
120
|
-
"tabWidth": 2,
|
|
121
|
-
"useTabs": false,
|
|
122
|
-
"semi": false,
|
|
123
|
-
"singleQuote": true,
|
|
124
|
-
"bracketSameLine": false,
|
|
125
|
-
"trailingComma": "none"
|
|
126
98
|
}
|
|
127
99
|
}
|
|
@@ -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'])
|
|
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'))) {
|
|
@@ -87,7 +87,8 @@ function prepareShared(packageRoot: string, projectRoot: string) {
|
|
|
87
87
|
|
|
88
88
|
function prepareBase(packageRoot: string, projectRoot: string) {
|
|
89
89
|
prepareShared(packageRoot, projectRoot)
|
|
90
|
-
copy('contracts', ['
|
|
90
|
+
copy('contracts', ['greeter_main.ral'])
|
|
91
|
+
copy('contracts/greeter', ['greeter.ral', 'greeter_interface.ral'])
|
|
91
92
|
fsExtra.copySync(path.join(packageRoot, 'templates/base'), projectRoot)
|
|
92
93
|
}
|
|
93
94
|
|
package/src/api/api-alephium.ts
CHANGED
|
@@ -422,6 +422,7 @@ export interface ChangeActiveAddress {
|
|
|
422
422
|
}
|
|
423
423
|
|
|
424
424
|
export interface CompileContractResult {
|
|
425
|
+
name: string
|
|
425
426
|
bytecode: string
|
|
426
427
|
|
|
427
428
|
/** @format 32-byte-hash */
|
|
@@ -429,12 +430,29 @@ export interface CompileContractResult {
|
|
|
429
430
|
fields: FieldsSig
|
|
430
431
|
functions: FunctionSig[]
|
|
431
432
|
events: EventSig[]
|
|
433
|
+
warnings: string[]
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
export interface CompileProjectResult {
|
|
437
|
+
contracts: CompileContractResult[]
|
|
438
|
+
scripts: CompileScriptResult[]
|
|
432
439
|
}
|
|
433
440
|
|
|
434
441
|
export interface CompileScriptResult {
|
|
442
|
+
name: string
|
|
435
443
|
bytecodeTemplate: string
|
|
436
444
|
fields: FieldsSig
|
|
437
445
|
functions: FunctionSig[]
|
|
446
|
+
warnings: string[]
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
export interface CompilerOptions {
|
|
450
|
+
ignoreUnusedConstantsWarnings?: boolean
|
|
451
|
+
ignoreUnusedVariablesWarnings?: boolean
|
|
452
|
+
ignoreUnusedFieldsWarnings?: boolean
|
|
453
|
+
ignoreUnusedPrivateFunctionsWarnings?: boolean
|
|
454
|
+
ignoreReadonlyCheckWarnings?: boolean
|
|
455
|
+
ignoreExternalCallCheckWarnings?: boolean
|
|
438
456
|
}
|
|
439
457
|
|
|
440
458
|
export interface Confirmed {
|
|
@@ -457,6 +475,7 @@ export interface Confirmed {
|
|
|
457
475
|
|
|
458
476
|
export interface Contract {
|
|
459
477
|
code: string
|
|
478
|
+
compilerOptions?: CompilerOptions
|
|
460
479
|
}
|
|
461
480
|
|
|
462
481
|
export interface ContractEvent {
|
|
@@ -561,7 +580,6 @@ export type DiscoveryAction = Reachable | Unreachable
|
|
|
561
580
|
|
|
562
581
|
export interface EventSig {
|
|
563
582
|
name: string
|
|
564
|
-
signature: string
|
|
565
583
|
fieldNames: string[]
|
|
566
584
|
fieldTypes: string[]
|
|
567
585
|
}
|
|
@@ -571,9 +589,9 @@ export interface FetchResponse {
|
|
|
571
589
|
}
|
|
572
590
|
|
|
573
591
|
export interface FieldsSig {
|
|
574
|
-
signature: string
|
|
575
592
|
names: string[]
|
|
576
593
|
types: string[]
|
|
594
|
+
isMutable: boolean[]
|
|
577
595
|
}
|
|
578
596
|
|
|
579
597
|
export interface FixedAssetOutput {
|
|
@@ -599,9 +617,12 @@ export interface FixedAssetOutput {
|
|
|
599
617
|
|
|
600
618
|
export interface FunctionSig {
|
|
601
619
|
name: string
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
620
|
+
usePreapprovedAssets: boolean
|
|
621
|
+
useAssetsInContract: boolean
|
|
622
|
+
isPublic: boolean
|
|
623
|
+
paramNames: string[]
|
|
624
|
+
paramTypes: string[]
|
|
625
|
+
paramIsMutable: boolean[]
|
|
605
626
|
returnTypes: string[]
|
|
606
627
|
}
|
|
607
628
|
|
|
@@ -703,6 +724,11 @@ export interface Penalty {
|
|
|
703
724
|
type: string
|
|
704
725
|
}
|
|
705
726
|
|
|
727
|
+
export interface Project {
|
|
728
|
+
code: string
|
|
729
|
+
compilerOptions?: CompilerOptions
|
|
730
|
+
}
|
|
731
|
+
|
|
706
732
|
export interface Reachable {
|
|
707
733
|
peers: string[]
|
|
708
734
|
type: string
|
|
@@ -729,6 +755,7 @@ export interface RevealMnemonicResult {
|
|
|
729
755
|
|
|
730
756
|
export interface Script {
|
|
731
757
|
code: string
|
|
758
|
+
compilerOptions?: CompilerOptions
|
|
732
759
|
}
|
|
733
760
|
|
|
734
761
|
export interface SelfClique {
|
|
@@ -2160,6 +2187,27 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
|
|
|
2160
2187
|
...params
|
|
2161
2188
|
}).then(convertHttpResponse),
|
|
2162
2189
|
|
|
2190
|
+
/**
|
|
2191
|
+
* No description
|
|
2192
|
+
*
|
|
2193
|
+
* @tags Contracts
|
|
2194
|
+
* @name PostContractsCompileProject
|
|
2195
|
+
* @summary Compile a project
|
|
2196
|
+
* @request POST:/contracts/compile-project
|
|
2197
|
+
*/
|
|
2198
|
+
postContractsCompileProject: (data: Project, params: RequestParams = {}) =>
|
|
2199
|
+
this.request<
|
|
2200
|
+
CompileProjectResult,
|
|
2201
|
+
BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable
|
|
2202
|
+
>({
|
|
2203
|
+
path: `/contracts/compile-project`,
|
|
2204
|
+
method: 'POST',
|
|
2205
|
+
body: data,
|
|
2206
|
+
type: ContentType.Json,
|
|
2207
|
+
format: 'json',
|
|
2208
|
+
...params
|
|
2209
|
+
}).then(convertHttpResponse),
|
|
2210
|
+
|
|
2163
2211
|
/**
|
|
2164
2212
|
* No description
|
|
2165
2213
|
*
|
package/src/api/index.ts
CHANGED
|
@@ -19,9 +19,19 @@ along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
19
19
|
import { Api as NodeApi } from './api-alephium'
|
|
20
20
|
import { Api as ExplorerApi } from './api-explorer'
|
|
21
21
|
|
|
22
|
-
export class NodeProvider extends NodeApi<
|
|
23
|
-
constructor(baseUrl: string) {
|
|
24
|
-
|
|
22
|
+
export class NodeProvider extends NodeApi<string> {
|
|
23
|
+
constructor(baseUrl: string, apiKey?: string) {
|
|
24
|
+
// eslint-disable-next-line security/detect-possible-timing-attacks
|
|
25
|
+
if (apiKey === undefined) {
|
|
26
|
+
super({ baseUrl: baseUrl })
|
|
27
|
+
} else {
|
|
28
|
+
super({
|
|
29
|
+
baseUrl: baseUrl,
|
|
30
|
+
baseApiParams: { secure: true },
|
|
31
|
+
securityWorker: (accessToken) => (accessToken !== null ? { headers: { 'X-API-KEY': `${accessToken}` } } : {})
|
|
32
|
+
})
|
|
33
|
+
this.setSecurityData(apiKey)
|
|
34
|
+
}
|
|
25
35
|
}
|
|
26
36
|
}
|
|
27
37
|
|