@alephium/web3 0.2.0-test.1 → 0.2.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/.eslintignore +2 -2
- package/README.md +2 -135
- package/dist/alephium-web3.min.js +1 -1
- package/dist/alephium-web3.min.js.LICENSE.txt +0 -17
- package/dist/alephium-web3.min.js.map +1 -1
- package/dist/src/api/api-alephium.d.ts +115 -17
- package/dist/src/api/api-alephium.js +145 -80
- package/dist/src/api/api-explorer.d.ts +178 -51
- package/dist/src/api/api-explorer.js +172 -37
- package/dist/src/api/index.d.ts +40 -5
- package/dist/src/api/index.js +115 -7
- package/dist/src/api/types.d.ts +23 -0
- package/dist/src/api/types.js +235 -0
- package/dist/src/api/utils.d.ts +6 -0
- package/dist/{scripts/rename-gitignore.js → src/api/utils.js} +11 -6
- package/dist/src/contract/contract.d.ts +68 -55
- package/dist/src/contract/contract.js +235 -384
- package/dist/src/contract/events.d.ts +4 -4
- package/dist/src/contract/events.js +2 -1
- package/dist/src/contract/index.js +5 -1
- package/dist/src/contract/ralph.d.ts +5 -4
- package/dist/src/contract/ralph.js +27 -1
- package/dist/src/global.d.ts +6 -2
- package/dist/src/global.js +19 -3
- package/dist/src/index.d.ts +2 -1
- package/dist/src/index.js +23 -2
- package/dist/src/signer/index.d.ts +0 -1
- package/dist/src/signer/index.js +5 -2
- package/dist/src/signer/signer.d.ts +59 -60
- package/dist/src/signer/signer.js +99 -70
- package/dist/src/transaction/index.d.ts +0 -1
- package/dist/src/transaction/index.js +5 -2
- package/dist/src/transaction/status.d.ts +2 -1
- package/dist/src/transaction/status.js +2 -1
- package/dist/src/utils/bs58.d.ts +1 -0
- package/dist/src/utils/bs58.js +13 -1
- package/dist/src/utils/index.d.ts +0 -1
- package/dist/src/utils/index.js +5 -2
- package/dist/src/utils/subscription.d.ts +0 -2
- package/dist/src/utils/subscription.js +0 -2
- package/dist/src/utils/utils.d.ts +4 -9
- package/dist/src/utils/utils.js +20 -24
- package/jest-config.json +11 -0
- package/package.json +11 -45
- package/src/api/api-alephium.ts +162 -25
- package/src/api/api-explorer.ts +247 -54
- package/src/api/index.ts +140 -6
- package/src/api/types.ts +229 -0
- package/{scripts/rename-gitignore.js → src/api/utils.ts} +7 -6
- package/src/contract/contract.ts +398 -429
- package/src/contract/events.ts +6 -5
- package/src/contract/ralph.ts +29 -4
- package/src/global.ts +23 -3
- package/src/index.ts +7 -1
- package/src/signer/index.ts +0 -1
- package/src/signer/signer.ts +165 -135
- package/src/transaction/index.ts +0 -1
- package/src/transaction/status.ts +5 -2
- package/src/utils/bs58.ts +11 -0
- package/src/utils/index.ts +0 -1
- package/src/utils/subscription.ts +0 -4
- package/src/utils/utils.ts +11 -19
- package/webpack.config.js +3 -0
- package/.eslintrc.json +0 -21
- package/LICENSE +0 -165
- package/contracts/add/add.ral +0 -13
- package/contracts/greeter/greeter.ral +0 -7
- package/contracts/greeter/greeter_interface.ral +0 -4
- package/contracts/greeter_main.ral +0 -7
- package/contracts/main.ral +0 -4
- package/contracts/sub/sub.ral +0 -10
- package/contracts/test/metadata.ral +0 -18
- package/contracts/test/warnings.ral +0 -8
- package/dev/user.conf +0 -29
- package/dist/scripts/create-project.d.ts +0 -2
- package/dist/scripts/create-project.js +0 -125
- package/dist/scripts/rename-gitignore.d.ts +0 -1
- package/dist/scripts/start-devnet.d.ts +0 -1
- package/dist/scripts/start-devnet.js +0 -131
- package/dist/scripts/stop-devnet.d.ts +0 -1
- package/dist/scripts/stop-devnet.js +0 -32
- package/dist/src/signer/node-wallet.d.ts +0 -11
- package/dist/src/signer/node-wallet.js +0 -57
- package/dist/src/test/index.d.ts +0 -6
- package/dist/src/test/index.js +0 -41
- package/dist/src/test/privatekey-wallet.d.ts +0 -11
- 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 -9
- package/scripts/create-project.ts +0 -137
- package/scripts/start-devnet.js +0 -141
- package/scripts/stop-devnet.js +0 -32
- package/src/contract/ralph.test.ts +0 -178
- package/src/fixtures/address.json +0 -36
- package/src/fixtures/balance.json +0 -9
- package/src/fixtures/self-clique.json +0 -19
- package/src/fixtures/transaction.json +0 -13
- package/src/fixtures/transactions.json +0 -179
- package/src/signer/fixtures/genesis.json +0 -26
- package/src/signer/fixtures/wallets.json +0 -26
- package/src/signer/node-wallet.ts +0 -65
- package/src/test/index.ts +0 -31
- package/src/test/privatekey-wallet.ts +0 -57
- package/src/transaction/sign-verify.test.ts +0 -50
- package/src/transaction/sign-verify.ts +0 -39
- package/src/utils/address.test.ts +0 -47
- package/src/utils/djb2.test.ts +0 -35
- package/src/utils/password-crypto.test.ts +0 -27
- package/src/utils/password-crypto.ts +0 -77
- package/src/utils/utils.test.ts +0 -161
- package/templates/base/README.md +0 -34
- package/templates/base/package.json +0 -35
- package/templates/base/src/greeter.ts +0 -42
- package/templates/base/tsconfig.json +0 -19
- package/templates/react/README.md +0 -34
- package/templates/react/config-overrides.js +0 -18
- package/templates/react/package.json +0 -66
- package/templates/react/src/App.tsx +0 -42
- package/templates/react/src/artifacts/greeter.ral.json +0 -26
- package/templates/react/src/artifacts/greeter_main.ral.json +0 -22
- package/templates/shared/.eslintrc.json +0 -12
- package/templates/shared/scripts/header.js +0 -0
- package/test/contract.test.ts +0 -213
- package/test/events.test.ts +0 -141
- package/test/transaction.test.ts +0 -73
|
@@ -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];
|
|
@@ -39,12 +43,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
39
43
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
44
|
};
|
|
41
45
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
exports.verifySignedMessage = exports.verifyHexString = exports.
|
|
46
|
+
exports.fromApiDestination = exports.toApiDestinations = exports.toApiDestination = exports.verifySignedMessage = exports.verifyHexString = exports.SignerProviderWithMultipleAccounts = exports.SignerProviderSimple = void 0;
|
|
43
47
|
const elliptic_1 = require("elliptic");
|
|
48
|
+
const api_1 = require("../api");
|
|
44
49
|
const utils = __importStar(require("../utils"));
|
|
45
50
|
const utils_1 = require("../utils");
|
|
46
51
|
const blakejs_1 = __importDefault(require("blakejs"));
|
|
47
|
-
const global_1 = require("../global");
|
|
48
52
|
const ec = new elliptic_1.ec('secp256k1');
|
|
49
53
|
(0, utils_1.assertType)();
|
|
50
54
|
(0, utils_1.assertType)();
|
|
@@ -53,109 +57,108 @@ const ec = new elliptic_1.ec('secp256k1');
|
|
|
53
57
|
(0, utils_1.assertType)();
|
|
54
58
|
(0, utils_1.assertType)();
|
|
55
59
|
(0, utils_1.assertType)();
|
|
60
|
+
utils_1.assertType;
|
|
56
61
|
(0, utils_1.assertType)();
|
|
57
|
-
|
|
58
|
-
(
|
|
59
|
-
(
|
|
60
|
-
(
|
|
61
|
-
class SignerWithNodeProvider {
|
|
62
|
-
constructor(alwaysSubmitTx) {
|
|
63
|
-
this.provider = (0, global_1.getCurrentNodeProvider)();
|
|
64
|
-
this.alwaysSubmitTx = alwaysSubmitTx;
|
|
65
|
-
}
|
|
66
|
-
async getAccount(signerAddress) {
|
|
67
|
-
const accounts = await this.getAccounts();
|
|
68
|
-
const account = accounts.find((a) => a.address === signerAddress);
|
|
69
|
-
if (typeof account === 'undefined') {
|
|
70
|
-
throw new Error('Unmatched signerAddress');
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
return account;
|
|
62
|
+
class SignerProviderSimple {
|
|
63
|
+
getNodeProvider() {
|
|
64
|
+
if (this.nodeProvider === undefined) {
|
|
65
|
+
throw Error('The signer does not contain a node provider');
|
|
74
66
|
}
|
|
67
|
+
return this.nodeProvider;
|
|
68
|
+
}
|
|
69
|
+
async submitTransaction(params) {
|
|
70
|
+
const data = { unsignedTx: params.unsignedTx, signature: params.signature };
|
|
71
|
+
return this.getNodeProvider().transactions.postTransactionsSubmit(data);
|
|
75
72
|
}
|
|
76
|
-
async
|
|
77
|
-
|
|
73
|
+
async signAndSubmitTransferTx(params) {
|
|
74
|
+
const signResult = await this.signTransferTx(params);
|
|
75
|
+
await this.submitTransaction(signResult);
|
|
76
|
+
return signResult;
|
|
78
77
|
}
|
|
79
|
-
async
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
return this.provider.transactions.postTransactionsSubmit(params);
|
|
78
|
+
async signAndSubmitDeployContractTx(params) {
|
|
79
|
+
const signResult = await this.signDeployContractTx(params);
|
|
80
|
+
await this.submitTransaction(signResult);
|
|
81
|
+
return signResult;
|
|
84
82
|
}
|
|
85
|
-
|
|
86
|
-
|
|
83
|
+
async signAndSubmitExecuteScriptTx(params) {
|
|
84
|
+
const signResult = await this.signExecuteScriptTx(params);
|
|
85
|
+
await this.submitTransaction(signResult);
|
|
86
|
+
return signResult;
|
|
87
|
+
}
|
|
88
|
+
async signAndSubmitUnsignedTx(params) {
|
|
89
|
+
const signResult = await this.signUnsignedTx(params);
|
|
90
|
+
await this.submitTransaction(signResult);
|
|
91
|
+
return signResult;
|
|
87
92
|
}
|
|
88
93
|
async usePublicKey(params) {
|
|
89
94
|
const { signerAddress, ...restParams } = params;
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
throw new Error('Unknown signer address');
|
|
95
|
+
const selectedAccount = await this.getSelectedAccount();
|
|
96
|
+
if (signerAddress !== selectedAccount.address) {
|
|
97
|
+
throw new Error('The signer address is not the selected address');
|
|
94
98
|
}
|
|
95
99
|
else {
|
|
96
|
-
return { fromPublicKey:
|
|
100
|
+
return { fromPublicKey: selectedAccount.publicKey, ...restParams };
|
|
97
101
|
}
|
|
98
102
|
}
|
|
99
103
|
async signTransferTx(params) {
|
|
100
104
|
const response = await this.buildTransferTx(params);
|
|
101
|
-
|
|
105
|
+
const signature = await this.signRaw(params.signerAddress, response.txId);
|
|
106
|
+
return { ...response, signature, gasPrice: (0, api_1.fromApiNumber256)(response.gasPrice) };
|
|
102
107
|
}
|
|
103
108
|
async buildTransferTx(params) {
|
|
104
|
-
|
|
109
|
+
const data = {
|
|
110
|
+
...(await this.usePublicKey(params)),
|
|
111
|
+
destinations: toApiDestinations(params.destinations),
|
|
112
|
+
gasPrice: (0, api_1.toApiNumber256Optional)(params.gasPrice)
|
|
113
|
+
};
|
|
114
|
+
return this.getNodeProvider().transactions.postTransactionsBuild(data);
|
|
105
115
|
}
|
|
106
116
|
async signDeployContractTx(params) {
|
|
107
117
|
const response = await this.buildContractCreationTx(params);
|
|
108
|
-
const
|
|
118
|
+
const signature = await this.signRaw(params.signerAddress, response.txId);
|
|
109
119
|
const contractId = utils.binToHex(utils.contractIdFromAddress(response.contractAddress));
|
|
110
|
-
return { ...
|
|
120
|
+
return { ...response, contractId, signature, gasPrice: (0, api_1.fromApiNumber256)(response.gasPrice) };
|
|
111
121
|
}
|
|
112
122
|
async buildContractCreationTx(params) {
|
|
113
|
-
|
|
123
|
+
const data = {
|
|
124
|
+
...(await this.usePublicKey(params)),
|
|
125
|
+
initialAttoAlphAmount: (0, api_1.toApiNumber256Optional)(params.initialAttoAlphAmount),
|
|
126
|
+
initialTokenAmounts: (0, api_1.toApiTokens)(params.initialTokenAmounts),
|
|
127
|
+
issueTokenAmount: (0, api_1.toApiNumber256Optional)(params.issueTokenAmount),
|
|
128
|
+
gasPrice: (0, api_1.toApiNumber256Optional)(params.gasPrice)
|
|
129
|
+
};
|
|
130
|
+
return this.getNodeProvider().contracts.postContractsUnsignedTxDeployContract(data);
|
|
114
131
|
}
|
|
115
132
|
async signExecuteScriptTx(params) {
|
|
116
133
|
const response = await this.buildScriptTx(params);
|
|
117
|
-
|
|
134
|
+
const signature = await this.signRaw(params.signerAddress, response.txId);
|
|
135
|
+
return { ...response, signature, gasPrice: (0, api_1.fromApiNumber256)(response.gasPrice) };
|
|
118
136
|
}
|
|
119
137
|
async buildScriptTx(params) {
|
|
120
|
-
|
|
138
|
+
const data = {
|
|
139
|
+
...(await this.usePublicKey(params)),
|
|
140
|
+
attoAlphAmount: (0, api_1.toApiNumber256Optional)(params.attoAlphAmount),
|
|
141
|
+
tokens: (0, api_1.toApiTokens)(params.tokens),
|
|
142
|
+
gasPrice: (0, api_1.toApiNumber256Optional)(params.gasPrice)
|
|
143
|
+
};
|
|
144
|
+
return this.getNodeProvider().contracts.postContractsUnsignedTxExecuteScript(data);
|
|
121
145
|
}
|
|
122
146
|
// in general, wallet should show the decoded information to user for confirmation
|
|
123
147
|
// please overwrite this function for real wallet
|
|
124
148
|
async signUnsignedTx(params) {
|
|
125
149
|
const data = { unsignedTx: params.unsignedTx };
|
|
126
|
-
const decoded = await this.
|
|
127
|
-
|
|
150
|
+
const decoded = await this.getNodeProvider().transactions.postTransactionsDecodeUnsignedTx(data);
|
|
151
|
+
const signature = await this.signRaw(params.signerAddress, decoded.unsignedTx.txId);
|
|
152
|
+
return {
|
|
128
153
|
fromGroup: decoded.fromGroup,
|
|
129
154
|
toGroup: decoded.toGroup,
|
|
130
|
-
signerAddress: params.signerAddress,
|
|
131
155
|
unsignedTx: params.unsignedTx,
|
|
132
|
-
txId: decoded.unsignedTx.txId
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
async handleSign(response, submitTx) {
|
|
137
|
-
// sign the tx
|
|
138
|
-
const signature = await this.signRaw(response.signerAddress, response.txId);
|
|
139
|
-
// submit the tx if required
|
|
140
|
-
if (submitTx) {
|
|
141
|
-
await this.provider.transactions.postTransactionsSubmit({
|
|
142
|
-
unsignedTx: response.unsignedTx,
|
|
143
|
-
signature: signature
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
// return the signature back to the provider
|
|
147
|
-
return {
|
|
148
|
-
fromGroup: response.fromGroup,
|
|
149
|
-
toGroup: response.toGroup,
|
|
150
|
-
unsignedTx: response.unsignedTx,
|
|
151
|
-
txId: response.txId,
|
|
152
|
-
signature: signature
|
|
156
|
+
txId: decoded.unsignedTx.txId,
|
|
157
|
+
signature,
|
|
158
|
+
gasAmount: decoded.unsignedTx.gasAmount,
|
|
159
|
+
gasPrice: (0, api_1.fromApiNumber256)(decoded.unsignedTx.gasPrice)
|
|
153
160
|
};
|
|
154
161
|
}
|
|
155
|
-
async signHexString(params) {
|
|
156
|
-
const signature = await this.signRaw(params.signerAddress, params.hexString);
|
|
157
|
-
return { signature: signature };
|
|
158
|
-
}
|
|
159
162
|
async signMessage(params) {
|
|
160
163
|
const extendedMessage = extendMessage(params.message);
|
|
161
164
|
const messageHash = blakejs_1.default.blake2b(extendedMessage, undefined, 32);
|
|
@@ -163,7 +166,20 @@ class SignerWithNodeProvider {
|
|
|
163
166
|
return { signature: signature };
|
|
164
167
|
}
|
|
165
168
|
}
|
|
166
|
-
exports.
|
|
169
|
+
exports.SignerProviderSimple = SignerProviderSimple;
|
|
170
|
+
class SignerProviderWithMultipleAccounts extends SignerProviderSimple {
|
|
171
|
+
async getAccount(signerAddress) {
|
|
172
|
+
const accounts = await this.getAccounts();
|
|
173
|
+
const account = accounts.find((a) => a.address === signerAddress);
|
|
174
|
+
if (typeof account === 'undefined') {
|
|
175
|
+
throw new Error('Unmatched signerAddress');
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
return account;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
exports.SignerProviderWithMultipleAccounts = SignerProviderWithMultipleAccounts;
|
|
167
183
|
function verifyHexString(hexString, publicKey, signature) {
|
|
168
184
|
try {
|
|
169
185
|
const key = ec.keyFromPublic(publicKey, 'hex');
|
|
@@ -183,3 +199,16 @@ function verifySignedMessage(message, publicKey, signature) {
|
|
|
183
199
|
return verifyHexString(utils.binToHex(messageHash), publicKey, signature);
|
|
184
200
|
}
|
|
185
201
|
exports.verifySignedMessage = verifySignedMessage;
|
|
202
|
+
utils_1.assertType;
|
|
203
|
+
function toApiDestination(data) {
|
|
204
|
+
return { ...data, attoAlphAmount: (0, api_1.toApiNumber256)(data.attoAlphAmount), tokens: (0, api_1.toApiTokens)(data.tokens) };
|
|
205
|
+
}
|
|
206
|
+
exports.toApiDestination = toApiDestination;
|
|
207
|
+
function toApiDestinations(data) {
|
|
208
|
+
return data.map(toApiDestination);
|
|
209
|
+
}
|
|
210
|
+
exports.toApiDestinations = toApiDestinations;
|
|
211
|
+
function fromApiDestination(data) {
|
|
212
|
+
return { ...data, attoAlphAmount: (0, api_1.fromApiNumber256)(data.attoAlphAmount), tokens: (0, api_1.fromApiTokens)(data.tokens) };
|
|
213
|
+
}
|
|
214
|
+
exports.fromApiDestination = fromApiDestination;
|
|
@@ -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);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { node } from '../api';
|
|
2
2
|
import { Subscription, SubscribeOptions } from '../utils';
|
|
3
|
+
export declare type TxStatus = node.TxStatus;
|
|
3
4
|
export declare class TxStatusSubscription extends Subscription<TxStatus> {
|
|
4
5
|
readonly txId: string;
|
|
5
6
|
readonly fromGroup?: number;
|
|
@@ -18,6 +18,7 @@ along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
18
18
|
*/
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
20
|
exports.subscribeToTxStatus = exports.TxStatusSubscription = void 0;
|
|
21
|
+
const __1 = require("..");
|
|
21
22
|
const utils_1 = require("../utils");
|
|
22
23
|
class TxStatusSubscription extends utils_1.Subscription {
|
|
23
24
|
constructor(options, txId, fromGroup, toGroup) {
|
|
@@ -29,7 +30,7 @@ class TxStatusSubscription extends utils_1.Subscription {
|
|
|
29
30
|
}
|
|
30
31
|
async polling() {
|
|
31
32
|
try {
|
|
32
|
-
const txStatus = await
|
|
33
|
+
const txStatus = await __1.web3.getCurrentNodeProvider().transactions.getTransactionsStatus({
|
|
33
34
|
txId: this.txId,
|
|
34
35
|
fromGroup: this.fromGroup,
|
|
35
36
|
toGroup: this.toGroup
|
package/dist/src/utils/bs58.d.ts
CHANGED
package/dist/src/utils/bs58.js
CHANGED
|
@@ -20,9 +20,21 @@ 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.bs58 = void 0;
|
|
23
|
+
exports.isBase58 = exports.bs58 = void 0;
|
|
24
24
|
/** This source is under MIT License and come originally from https://github.com/cryptocoinjs/bs58 **/
|
|
25
25
|
const base_x_1 = __importDefault(require("base-x"));
|
|
26
26
|
const ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
|
|
27
27
|
exports.bs58 = (0, base_x_1.default)(ALPHABET);
|
|
28
|
+
function isBase58(s) {
|
|
29
|
+
if (s === '' || s.trim() === '') {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
try {
|
|
33
|
+
return exports.bs58.encode(exports.bs58.decode(s)) === s;
|
|
34
|
+
}
|
|
35
|
+
catch (err) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.isBase58 = isBase58;
|
|
28
40
|
exports.default = exports.bs58;
|
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);
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import EventEmitter from 'eventemitter3';
|
|
2
|
-
import { NodeProvider } from '../api';
|
|
3
2
|
declare type MessageCallback<Message> = (message: Message) => Promise<void>;
|
|
4
3
|
declare type ErrorCallback<Message> = (error: any, subscription: Subscription<Message>) => Promise<void>;
|
|
5
4
|
export interface SubscribeOptions<Message> {
|
|
@@ -8,7 +7,6 @@ export interface SubscribeOptions<Message> {
|
|
|
8
7
|
errorCallback: ErrorCallback<Message>;
|
|
9
8
|
}
|
|
10
9
|
export declare abstract class Subscription<Message> {
|
|
11
|
-
provider: NodeProvider;
|
|
12
10
|
pollingInterval: number;
|
|
13
11
|
protected messageCallback: MessageCallback<Message>;
|
|
14
12
|
protected errorCallback: ErrorCallback<Message>;
|
|
@@ -22,10 +22,8 @@ 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");
|
|
26
25
|
class Subscription {
|
|
27
26
|
constructor(options) {
|
|
28
|
-
this.provider = (0, global_1.getCurrentNodeProvider)();
|
|
29
27
|
this.pollingInterval = options.pollingInterval;
|
|
30
28
|
this.messageCallback = options.messageCallback;
|
|
31
29
|
this.errorCallback = options.errorCallback;
|
|
@@ -1,19 +1,14 @@
|
|
|
1
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
2
|
export declare function signatureEncode(signature: EC.Signature): string;
|
|
10
|
-
export declare
|
|
3
|
+
export declare function signatureDecode(ec: EC, signature: string): SignatureInput;
|
|
4
|
+
export declare function xorByte(intValue: number): number;
|
|
11
5
|
export declare function isHexString(input: string): boolean;
|
|
12
|
-
export declare
|
|
6
|
+
export declare function groupOfAddress(address: string): number;
|
|
13
7
|
export declare function contractIdFromAddress(address: string): Uint8Array;
|
|
14
8
|
export declare function tokenIdFromAddress(address: string): Uint8Array;
|
|
15
9
|
export declare function hexToBinUnsafe(hex: string): Uint8Array;
|
|
16
10
|
export declare function binToHex(bin: Uint8Array): string;
|
|
11
|
+
export declare function groupOfPrivateKey(privateKey: string): number;
|
|
17
12
|
export declare function publicKeyFromPrivateKey(privateKey: string): string;
|
|
18
13
|
export declare function addressFromPublicKey(publicKey: string): string;
|
|
19
14
|
export declare function addressFromContractId(contractId: string): string;
|
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.groupOfPrivateKey = exports.binToHex = exports.hexToBinUnsafe = exports.tokenIdFromAddress = exports.contractIdFromAddress = exports.groupOfAddress = exports.isHexString = exports.xorByte = exports.signatureDecode = exports.signatureEncode = 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"));
|
|
@@ -29,15 +29,6 @@ const buffer_1 = require("buffer/");
|
|
|
29
29
|
const constants_1 = require("../constants");
|
|
30
30
|
const djb2_1 = __importDefault(require("./djb2"));
|
|
31
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
32
|
function signatureEncode(signature) {
|
|
42
33
|
let sNormalized = signature.s;
|
|
43
34
|
if (ec.n && signature.s.cmp(ec.nh) === 1) {
|
|
@@ -49,7 +40,7 @@ function signatureEncode(signature) {
|
|
|
49
40
|
}
|
|
50
41
|
exports.signatureEncode = signatureEncode;
|
|
51
42
|
// the signature should be in hex string format for 64 bytes
|
|
52
|
-
|
|
43
|
+
function signatureDecode(ec, signature) {
|
|
53
44
|
if (signature.length !== 128) {
|
|
54
45
|
throw new Error('Invalid signature length');
|
|
55
46
|
}
|
|
@@ -62,15 +53,16 @@ const signatureDecode = (ec, signature) => {
|
|
|
62
53
|
else {
|
|
63
54
|
throw new Error('The signature is not normalized');
|
|
64
55
|
}
|
|
65
|
-
}
|
|
56
|
+
}
|
|
66
57
|
exports.signatureDecode = signatureDecode;
|
|
67
|
-
|
|
58
|
+
function xorByte(intValue) {
|
|
68
59
|
const byte0 = (intValue >> 24) & 0xff;
|
|
69
60
|
const byte1 = (intValue >> 16) & 0xff;
|
|
70
61
|
const byte2 = (intValue >> 8) & 0xff;
|
|
71
62
|
const byte3 = intValue & 0xff;
|
|
72
63
|
return (byte0 ^ byte1 ^ byte2 ^ byte3) & 0xff;
|
|
73
|
-
}
|
|
64
|
+
}
|
|
65
|
+
exports.xorByte = xorByte;
|
|
74
66
|
function isHexString(input) {
|
|
75
67
|
return input.length % 2 === 0 && /[0-9a-f]*$/.test(input);
|
|
76
68
|
}
|
|
@@ -82,7 +74,7 @@ var AddressType;
|
|
|
82
74
|
AddressType[AddressType["P2SH"] = 2] = "P2SH";
|
|
83
75
|
AddressType[AddressType["P2C"] = 3] = "P2C";
|
|
84
76
|
})(AddressType || (AddressType = {}));
|
|
85
|
-
|
|
77
|
+
function groupOfAddress(address) {
|
|
86
78
|
const decoded = bs58_1.default.decode(address);
|
|
87
79
|
if (decoded.length == 0)
|
|
88
80
|
throw new Error('Address string is empty');
|
|
@@ -100,32 +92,32 @@ const groupOfAddress = (address) => {
|
|
|
100
92
|
else {
|
|
101
93
|
throw new Error(`Invalid asset address type: ${addressType}`);
|
|
102
94
|
}
|
|
103
|
-
}
|
|
95
|
+
}
|
|
104
96
|
exports.groupOfAddress = groupOfAddress;
|
|
105
|
-
|
|
97
|
+
function groupOfAddressBytes(bytes) {
|
|
106
98
|
const hint = (0, djb2_1.default)(bytes) | 1;
|
|
107
99
|
const hash = xorByte(hint);
|
|
108
100
|
const group = hash % constants_1.TOTAL_NUMBER_OF_GROUPS;
|
|
109
101
|
return group;
|
|
110
|
-
}
|
|
102
|
+
}
|
|
111
103
|
// Pay to public key hash address
|
|
112
|
-
|
|
104
|
+
function groupOfP2pkhAddress(address) {
|
|
113
105
|
if (address.length != 32) {
|
|
114
106
|
throw new Error(`Invalid p2pkh address length: ${address.length}`);
|
|
115
107
|
}
|
|
116
108
|
return groupOfAddressBytes(address);
|
|
117
|
-
}
|
|
109
|
+
}
|
|
118
110
|
// Pay to multiple public key hash address
|
|
119
|
-
|
|
111
|
+
function groupOfP2mpkhAddress(address) {
|
|
120
112
|
if ((address.length - 2) % 32 != 0) {
|
|
121
113
|
throw new Error(`Invalid p2mpkh address length: ${address.length}`);
|
|
122
114
|
}
|
|
123
115
|
return groupOfAddressBytes(address.slice(1, 33));
|
|
124
|
-
}
|
|
116
|
+
}
|
|
125
117
|
// Pay to script hash address
|
|
126
|
-
|
|
118
|
+
function groupOfP2shAddress(address) {
|
|
127
119
|
return groupOfAddressBytes(address);
|
|
128
|
-
}
|
|
120
|
+
}
|
|
129
121
|
function contractIdFromAddress(address) {
|
|
130
122
|
return idFromAddress(address);
|
|
131
123
|
}
|
|
@@ -155,6 +147,10 @@ function binToHex(bin) {
|
|
|
155
147
|
return buffer_1.Buffer.from(bin).toString('hex');
|
|
156
148
|
}
|
|
157
149
|
exports.binToHex = binToHex;
|
|
150
|
+
function groupOfPrivateKey(privateKey) {
|
|
151
|
+
return groupOfAddress(addressFromPublicKey(publicKeyFromPrivateKey(privateKey)));
|
|
152
|
+
}
|
|
153
|
+
exports.groupOfPrivateKey = groupOfPrivateKey;
|
|
158
154
|
function publicKeyFromPrivateKey(privateKey) {
|
|
159
155
|
const key = ec.keyFromPrivate(privateKey);
|
|
160
156
|
return key.getPublic(true, 'hex');
|
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
|
|
3
|
+
"version": "0.2.0",
|
|
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,52 +27,28 @@
|
|
|
27
27
|
},
|
|
28
28
|
"author": "Alephium dev <dev@alephium.org>",
|
|
29
29
|
"config": {
|
|
30
|
-
"alephium_version": "1.5.0
|
|
31
|
-
"explorer_backend_version": "1.
|
|
30
|
+
"alephium_version": "1.5.0",
|
|
31
|
+
"explorer_backend_version": "1.9.0"
|
|
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
|
-
"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",
|
|
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
|
-
"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"
|
|
37
|
+
"update-schema:alephium": "npx swagger-typescript-api --disable-throw-on-error -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 --disable-throw-on-error -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
|
+
"check-versions": "node scripts/check-versions.js ${npm_package_config_alephium_version} ${npm_package_config_explorer_backend_version}"
|
|
56
40
|
},
|
|
57
41
|
"type": "commonjs",
|
|
58
|
-
"bin": {
|
|
59
|
-
"alephium": "dist/scripts/create-project.js"
|
|
60
|
-
},
|
|
61
42
|
"dependencies": {
|
|
62
43
|
"base-x": "4.0.0",
|
|
63
44
|
"blakejs": "1.2.1",
|
|
64
45
|
"buffer": "^6.0.3",
|
|
65
|
-
"commander": "^9.1.0",
|
|
66
46
|
"cross-fetch": "^3.1.5",
|
|
67
|
-
"crypto-js": "4.1.1",
|
|
68
47
|
"elliptic": "6.5.4",
|
|
69
|
-
"eventemitter3": "^4.0.7"
|
|
70
|
-
"find-up": "^2.1.0",
|
|
71
|
-
"fs-extra": "^10.0.1"
|
|
48
|
+
"eventemitter3": "^4.0.7"
|
|
72
49
|
},
|
|
73
50
|
"devDependencies": {
|
|
74
|
-
"@
|
|
75
|
-
"@types/elliptic": "^6.4.13",
|
|
51
|
+
"@babel/eslint-parser": "^7.18.9",
|
|
76
52
|
"@types/find-up": "^2.1.0",
|
|
77
53
|
"@types/fs-extra": "^9.0.13",
|
|
78
54
|
"@types/jest": "^27.5.1",
|
|
@@ -81,7 +57,6 @@
|
|
|
81
57
|
"@types/rewire": "^2.5.28",
|
|
82
58
|
"@typescript-eslint/eslint-plugin": "^4.30.0",
|
|
83
59
|
"@typescript-eslint/parser": "^4.30.0",
|
|
84
|
-
"babel-eslint": "^10.1.0",
|
|
85
60
|
"clean-webpack-plugin": "4.0.0",
|
|
86
61
|
"crypto-browserify": "^3.12.0",
|
|
87
62
|
"eslint": "^7.32.0",
|
|
@@ -105,21 +80,12 @@
|
|
|
105
80
|
"ts-jest": "^28.0.2",
|
|
106
81
|
"ts-node": "^10.7.0",
|
|
107
82
|
"tslib": "^2.3.1",
|
|
108
|
-
"typescript": "^4.4
|
|
83
|
+
"typescript": "^4.7.4",
|
|
109
84
|
"webpack": "^5.72.0",
|
|
110
85
|
"webpack-cli": "^4.9.2"
|
|
111
86
|
},
|
|
112
87
|
"engines": {
|
|
113
|
-
"node": ">=
|
|
88
|
+
"node": ">=16.0.0",
|
|
114
89
|
"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"
|
|
124
90
|
}
|
|
125
91
|
}
|