@alephium/web3 0.2.0-rc.3 → 0.2.0-rc.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintignore +2 -2
- package/README.md +2 -135
- package/dist/alephium-web3.min.js +1 -1
- package/dist/alephium-web3.min.js.LICENSE.txt +0 -17
- package/dist/alephium-web3.min.js.map +1 -1
- package/dist/src/api/api-alephium.d.ts +117 -17
- package/dist/src/api/api-alephium.js +145 -79
- package/dist/src/api/api-explorer.d.ts +163 -48
- package/dist/src/api/api-explorer.js +157 -34
- package/dist/src/api/index.d.ts +3 -2
- package/dist/src/api/index.js +22 -3
- package/dist/src/api/types.d.ts +23 -0
- package/dist/src/api/types.js +240 -0
- package/dist/src/api/utils.d.ts +6 -0
- package/dist/{scripts/rename-gitignore.js → src/api/utils.js} +11 -6
- package/dist/src/contract/contract.d.ts +107 -68
- package/dist/src/contract/contract.js +395 -451
- package/dist/src/contract/events.d.ts +4 -4
- package/dist/src/contract/events.js +2 -1
- package/dist/src/contract/index.js +5 -1
- package/dist/src/contract/ralph.d.ts +5 -4
- package/dist/src/contract/ralph.js +27 -1
- package/dist/src/global.d.ts +4 -0
- package/dist/{scripts/stop-devnet.js → src/global.js} +17 -11
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.js +23 -1
- package/dist/src/signer/index.d.ts +0 -1
- package/dist/src/signer/index.js +5 -2
- package/dist/src/signer/signer.d.ts +25 -13
- package/dist/src/signer/signer.js +51 -16
- package/dist/src/transaction/index.d.ts +0 -1
- package/dist/src/transaction/index.js +5 -2
- package/dist/src/transaction/status.d.ts +2 -1
- package/dist/src/transaction/status.js +2 -1
- package/dist/src/utils/bs58.d.ts +1 -0
- package/dist/src/utils/bs58.js +13 -1
- package/dist/src/utils/index.d.ts +0 -1
- package/dist/src/utils/index.js +5 -2
- package/dist/src/utils/subscription.d.ts +0 -3
- package/dist/src/utils/subscription.js +0 -1
- package/dist/src/utils/utils.d.ts +4 -9
- package/dist/src/utils/utils.js +20 -24
- package/jest-config.json +11 -0
- package/package.json +11 -47
- package/src/api/api-alephium.ts +169 -25
- package/src/api/api-explorer.ts +234 -51
- package/src/api/index.ts +14 -3
- package/src/api/types.ts +233 -0
- package/{scripts/rename-gitignore.js → src/api/utils.ts} +7 -6
- package/src/contract/contract.ts +579 -545
- package/src/contract/events.ts +6 -5
- package/src/contract/ralph.ts +29 -4
- package/src/{transaction/sign-verify.ts → global.ts} +14 -15
- package/src/index.ts +7 -0
- package/src/signer/index.ts +0 -1
- package/src/signer/signer.ts +79 -27
- 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 +1 -3
- package/src/utils/utils.ts +11 -19
- package/.eslintrc.json +0 -21
- package/LICENSE +0 -165
- package/contracts/add/add.ral +0 -16
- package/contracts/greeter/greeter.ral +0 -7
- package/contracts/greeter/greeter_interface.ral +0 -3
- package/contracts/greeter_main.ral +0 -9
- package/contracts/main.ral +0 -6
- package/contracts/sub/sub.ral +0 -9
- package/contracts/test/metadata.ral +0 -17
- package/contracts/test/warnings.ral +0 -5
- package/dev/user.conf +0 -29
- package/dist/scripts/create-project.d.ts +0 -2
- package/dist/scripts/create-project.js +0 -125
- package/dist/scripts/rename-gitignore.d.ts +0 -1
- package/dist/scripts/start-devnet.d.ts +0 -1
- package/dist/scripts/start-devnet.js +0 -131
- package/dist/scripts/stop-devnet.d.ts +0 -1
- package/dist/src/signer/node-wallet.d.ts +0 -13
- package/dist/src/signer/node-wallet.js +0 -60
- package/dist/src/test/index.d.ts +0 -7
- package/dist/src/test/index.js +0 -41
- package/dist/src/test/privatekey-wallet.d.ts +0 -12
- package/dist/src/test/privatekey-wallet.js +0 -68
- package/dist/src/transaction/sign-verify.d.ts +0 -2
- package/dist/src/transaction/sign-verify.js +0 -58
- package/dist/src/utils/password-crypto.d.ts +0 -2
- package/dist/src/utils/password-crypto.js +0 -69
- package/gitignore +0 -10
- package/scripts/create-project.ts +0 -137
- package/scripts/start-devnet.js +0 -141
- package/scripts/stop-devnet.js +0 -32
- package/src/contract/ralph.test.ts +0 -178
- package/src/fixtures/address.json +0 -36
- package/src/fixtures/balance.json +0 -9
- package/src/fixtures/self-clique.json +0 -19
- package/src/fixtures/transaction.json +0 -13
- package/src/fixtures/transactions.json +0 -179
- package/src/signer/fixtures/genesis.json +0 -26
- package/src/signer/fixtures/wallets.json +0 -26
- package/src/signer/node-wallet.ts +0 -74
- package/src/test/index.ts +0 -32
- package/src/test/privatekey-wallet.ts +0 -58
- package/src/transaction/sign-verify.test.ts +0 -50
- package/src/utils/address.test.ts +0 -47
- package/src/utils/djb2.test.ts +0 -35
- package/src/utils/password-crypto.test.ts +0 -27
- package/src/utils/password-crypto.ts +0 -77
- package/src/utils/utils.test.ts +0 -161
- package/templates/base/README.md +0 -34
- package/templates/base/package.json +0 -35
- package/templates/base/src/greeter.ts +0 -41
- package/templates/base/tsconfig.json +0 -19
- package/templates/react/README.md +0 -34
- package/templates/react/config-overrides.js +0 -18
- package/templates/react/package.json +0 -66
- package/templates/react/src/App.tsx +0 -42
- package/templates/react/src/artifacts/greeter.ral.json +0 -26
- package/templates/react/src/artifacts/greeter_main.ral.json +0 -22
- package/templates/shared/.eslintrc.json +0 -12
- package/templates/shared/scripts/header.js +0 -0
- package/test/contract.test.ts +0 -197
- package/test/events.test.ts +0 -138
- package/test/transaction.test.ts +0 -72
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { node } from '../api';
|
|
2
2
|
import { Subscription, SubscribeOptions } from '../utils';
|
|
3
|
-
export declare class EventSubscription extends Subscription<ContractEvent> {
|
|
3
|
+
export declare class EventSubscription extends Subscription<node.ContractEvent> {
|
|
4
4
|
readonly contractAddress: string;
|
|
5
5
|
private fromCount;
|
|
6
|
-
constructor(options: SubscribeOptions<ContractEvent>, contractAddress: string, fromCount?: number);
|
|
6
|
+
constructor(options: SubscribeOptions<node.ContractEvent>, contractAddress: string, fromCount?: number);
|
|
7
7
|
startPolling(): void;
|
|
8
8
|
currentEventCount(): number;
|
|
9
9
|
polling(): Promise<void>;
|
|
10
10
|
}
|
|
11
|
-
export declare function subscribeToEvents(options: SubscribeOptions<ContractEvent>, contractAddress: string, fromCount?: number): EventSubscription;
|
|
11
|
+
export declare function subscribeToEvents(options: SubscribeOptions<node.ContractEvent>, contractAddress: string, fromCount?: number): EventSubscription;
|
|
@@ -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.subscribeToEvents = exports.EventSubscription = void 0;
|
|
21
|
+
const __1 = require("..");
|
|
21
22
|
const utils_1 = require("../utils");
|
|
22
23
|
class EventSubscription extends utils_1.Subscription {
|
|
23
24
|
constructor(options, contractAddress, fromCount) {
|
|
@@ -37,7 +38,7 @@ class EventSubscription extends utils_1.Subscription {
|
|
|
37
38
|
}
|
|
38
39
|
async polling() {
|
|
39
40
|
try {
|
|
40
|
-
const events = await
|
|
41
|
+
const events = await __1.web3.getCurrentNodeProvider().events.getEventsContractContractaddress(this.contractAddress, {
|
|
41
42
|
start: this.fromCount
|
|
42
43
|
});
|
|
43
44
|
if (this.cancelled) {
|
|
@@ -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];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Fields,
|
|
1
|
+
import { Val } from '../api';
|
|
2
|
+
import { Fields, FieldsSig } from './contract';
|
|
3
3
|
export declare function encodeBool(bool: boolean): Uint8Array;
|
|
4
4
|
export declare function encodeI256(i256: bigint): Uint8Array;
|
|
5
5
|
export declare function encodeU256(u256: bigint): Uint8Array;
|
|
@@ -7,6 +7,7 @@ export declare function encodeByteVec(bytes: string): Uint8Array;
|
|
|
7
7
|
export declare function encodeAddress(address: string): Uint8Array;
|
|
8
8
|
export declare function encodeScriptFieldAsString(tpe: string, value: Val): string;
|
|
9
9
|
export declare function encodeScriptField(tpe: string, value: Val): Uint8Array;
|
|
10
|
-
export declare function buildScriptByteCode(bytecodeTemplate: string, fields: Fields, fieldsSig:
|
|
11
|
-
export declare function buildContractByteCode(bytecode: string, fields: Fields, fieldsSig:
|
|
10
|
+
export declare function buildScriptByteCode(bytecodeTemplate: string, fields: Fields, fieldsSig: FieldsSig): string;
|
|
11
|
+
export declare function buildContractByteCode(bytecode: string, fields: Fields, fieldsSig: FieldsSig): string;
|
|
12
12
|
export declare function encodeContractField(tpe: string, value: Val): Uint8Array[];
|
|
13
|
+
export declare function buildDebugBytecode(bytecode: string, bytecodePatch: string): string;
|
|
@@ -18,7 +18,7 @@ along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
18
18
|
*/
|
|
19
19
|
var _a;
|
|
20
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
-
exports.encodeContractField = exports.buildContractByteCode = exports.buildScriptByteCode = exports.encodeScriptField = exports.encodeScriptFieldAsString = exports.encodeAddress = exports.encodeByteVec = exports.encodeU256 = exports.encodeI256 = exports.encodeBool = void 0;
|
|
21
|
+
exports.buildDebugBytecode = exports.encodeContractField = exports.buildContractByteCode = exports.buildScriptByteCode = exports.encodeScriptField = exports.encodeScriptFieldAsString = exports.encodeAddress = exports.encodeByteVec = exports.encodeU256 = exports.encodeI256 = exports.encodeBool = void 0;
|
|
22
22
|
const buffer_1 = require("buffer/");
|
|
23
23
|
const utils_1 = require("../utils");
|
|
24
24
|
const bigIntZero = BigInt(0);
|
|
@@ -343,6 +343,32 @@ exports.encodeContractField = encodeContractField;
|
|
|
343
343
|
function invalidVal(tpe, value) {
|
|
344
344
|
return Error(`Invalid API value ${value} for type ${tpe}`);
|
|
345
345
|
}
|
|
346
|
+
function buildDebugBytecode(bytecode, bytecodePatch) {
|
|
347
|
+
if (bytecodePatch === '') {
|
|
348
|
+
return bytecode;
|
|
349
|
+
}
|
|
350
|
+
const pattern = /[=+-][0-9a-f]*/g;
|
|
351
|
+
let result = '';
|
|
352
|
+
let index = 0;
|
|
353
|
+
for (const parts of bytecodePatch.matchAll(pattern)) {
|
|
354
|
+
const part = parts[0];
|
|
355
|
+
const diffType = part[0];
|
|
356
|
+
if (diffType === '=') {
|
|
357
|
+
const length = parseInt(part.substring(1));
|
|
358
|
+
result = result + bytecode.slice(index, index + length);
|
|
359
|
+
index = index + length;
|
|
360
|
+
}
|
|
361
|
+
else if (diffType === '+') {
|
|
362
|
+
result = result + part.substring(1);
|
|
363
|
+
}
|
|
364
|
+
else {
|
|
365
|
+
const length = parseInt(part.substring(1));
|
|
366
|
+
index = index + length;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
return result;
|
|
370
|
+
}
|
|
371
|
+
exports.buildDebugBytecode = buildDebugBytecode;
|
|
346
372
|
// export function buildContractByteCode(
|
|
347
373
|
// compiled: node.TemplateContractByteCode,
|
|
348
374
|
// templateVariables: TemplateVariables
|
|
@@ -16,17 +16,23 @@ GNU Lesser General Public License for more details.
|
|
|
16
16
|
You should have received a copy of the GNU Lesser General Public License
|
|
17
17
|
along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
18
18
|
*/
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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;
|
|
28
29
|
}
|
|
29
30
|
}
|
|
30
|
-
|
|
31
|
-
|
|
31
|
+
exports.setCurrentNodeProvider = setCurrentNodeProvider;
|
|
32
|
+
function getCurrentNodeProvider() {
|
|
33
|
+
if (typeof _currentNodeProvider === 'undefined') {
|
|
34
|
+
throw Error('No node provider is set.');
|
|
35
|
+
}
|
|
36
|
+
return _currentNodeProvider;
|
|
32
37
|
}
|
|
38
|
+
exports.getCurrentNodeProvider = getCurrentNodeProvider;
|
package/dist/src/index.d.ts
CHANGED
package/dist/src/index.js
CHANGED
|
@@ -18,18 +18,40 @@ 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;
|
|
47
|
+
BigInt.prototype['toJSON'] = function () {
|
|
48
|
+
return this.toString();
|
|
49
|
+
};
|
|
30
50
|
__exportStar(require("./api"), exports);
|
|
31
51
|
__exportStar(require("./contract"), exports);
|
|
32
52
|
__exportStar(require("./signer"), exports);
|
|
33
53
|
__exportStar(require("./utils"), exports);
|
|
34
54
|
__exportStar(require("./transaction"), exports);
|
|
35
55
|
__exportStar(require("./constants"), exports);
|
|
56
|
+
exports.web3 = __importStar(require("./global"));
|
|
57
|
+
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);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Number256, Token } from '../api';
|
|
2
2
|
import { node } from '../api';
|
|
3
|
-
|
|
3
|
+
export declare type OutputRef = node.OutputRef;
|
|
4
4
|
export interface SignResult {
|
|
5
5
|
fromGroup: number;
|
|
6
6
|
toGroup: number;
|
|
@@ -23,10 +23,10 @@ export declare type GetAccountsParams = undefined;
|
|
|
23
23
|
export declare type GetAccountsResult = Account[];
|
|
24
24
|
export interface SignTransferTxParams {
|
|
25
25
|
signerAddress: string;
|
|
26
|
-
destinations:
|
|
27
|
-
utxos?:
|
|
26
|
+
destinations: Destination[];
|
|
27
|
+
utxos?: OutputRef[];
|
|
28
28
|
gasAmount?: number;
|
|
29
|
-
gasPrice?:
|
|
29
|
+
gasPrice?: Number256;
|
|
30
30
|
submitTx?: boolean;
|
|
31
31
|
}
|
|
32
32
|
export interface SignTransferTxResult {
|
|
@@ -39,11 +39,11 @@ export interface SignTransferTxResult {
|
|
|
39
39
|
export interface SignDeployContractTxParams {
|
|
40
40
|
signerAddress: string;
|
|
41
41
|
bytecode: string;
|
|
42
|
-
initialAttoAlphAmount?:
|
|
42
|
+
initialAttoAlphAmount?: Number256;
|
|
43
43
|
initialTokenAmounts?: Token[];
|
|
44
|
-
issueTokenAmount?:
|
|
44
|
+
issueTokenAmount?: Number256;
|
|
45
45
|
gasAmount?: number;
|
|
46
|
-
gasPrice?:
|
|
46
|
+
gasPrice?: Number256;
|
|
47
47
|
submitTx?: boolean;
|
|
48
48
|
}
|
|
49
49
|
export interface SignDeployContractTxResult {
|
|
@@ -59,7 +59,7 @@ export interface SignExecuteScriptTxParams {
|
|
|
59
59
|
signerAddress: string;
|
|
60
60
|
bytecode: string;
|
|
61
61
|
attoAlphAmount?: string;
|
|
62
|
-
tokens?:
|
|
62
|
+
tokens?: Token[];
|
|
63
63
|
gasAmount?: number;
|
|
64
64
|
gasPrice?: string;
|
|
65
65
|
submitTx?: boolean;
|
|
@@ -107,13 +107,15 @@ export interface SignerProvider {
|
|
|
107
107
|
signMessage(params: SignMessageParams): Promise<SignMessageResult>;
|
|
108
108
|
}
|
|
109
109
|
export declare abstract class SignerWithNodeProvider implements SignerProvider {
|
|
110
|
-
readonly provider: NodeProvider;
|
|
111
110
|
alwaysSubmitTx: boolean;
|
|
112
111
|
abstract getAccounts(): Promise<Account[]>;
|
|
113
112
|
getAccount(signerAddress: string): Promise<Account>;
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
113
|
+
abstract setActiveAccount(addressIndex: number): Promise<void>;
|
|
114
|
+
abstract setActiveAccount(address: string): Promise<void>;
|
|
115
|
+
abstract setActiveAccount(input: unknown): Promise<void>;
|
|
116
|
+
abstract getActiveAccount(): Promise<Account>;
|
|
117
|
+
constructor(alwaysSubmitTx: boolean);
|
|
118
|
+
submitTransaction(unsignedTx: string, signerAddress?: string): Promise<SubmissionResult>;
|
|
117
119
|
private shouldSubmitTx;
|
|
118
120
|
private usePublicKey;
|
|
119
121
|
signTransferTx(params: SignTransferTxParams): Promise<SignTransferTxResult>;
|
|
@@ -141,3 +143,13 @@ export interface SubmissionResult {
|
|
|
141
143
|
}
|
|
142
144
|
export declare function verifyHexString(hexString: string, publicKey: string, signature: string): boolean;
|
|
143
145
|
export declare function verifySignedMessage(message: string, publicKey: string, signature: string): boolean;
|
|
146
|
+
export interface Destination {
|
|
147
|
+
address: string;
|
|
148
|
+
attoAlphAmount: Number256;
|
|
149
|
+
tokens?: Token[];
|
|
150
|
+
lockTime?: number;
|
|
151
|
+
message?: string;
|
|
152
|
+
}
|
|
153
|
+
export declare function toApiDestination(data: Destination): node.Destination;
|
|
154
|
+
export declare function toApiDestinations(data: Destination[]): node.Destination[];
|
|
155
|
+
export declare function fromApiDestination(data: node.Destination): Destination;
|
|
@@ -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,11 +43,13 @@ 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.SignerWithNodeProvider = void 0;
|
|
46
|
+
exports.fromApiDestination = exports.toApiDestinations = exports.toApiDestination = exports.verifySignedMessage = exports.verifyHexString = exports.SignerWithNodeProvider = 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"));
|
|
52
|
+
const __1 = require("..");
|
|
47
53
|
const ec = new elliptic_1.ec('secp256k1');
|
|
48
54
|
(0, utils_1.assertType)();
|
|
49
55
|
(0, utils_1.assertType)();
|
|
@@ -58,8 +64,7 @@ const ec = new elliptic_1.ec('secp256k1');
|
|
|
58
64
|
(0, utils_1.assertType)();
|
|
59
65
|
(0, utils_1.assertType)();
|
|
60
66
|
class SignerWithNodeProvider {
|
|
61
|
-
constructor(
|
|
62
|
-
this.provider = provider;
|
|
67
|
+
constructor(alwaysSubmitTx) {
|
|
63
68
|
this.alwaysSubmitTx = alwaysSubmitTx;
|
|
64
69
|
}
|
|
65
70
|
async getAccount(signerAddress) {
|
|
@@ -72,14 +77,15 @@ class SignerWithNodeProvider {
|
|
|
72
77
|
return account;
|
|
73
78
|
}
|
|
74
79
|
}
|
|
75
|
-
async
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
const
|
|
80
|
-
const
|
|
80
|
+
async submitTransaction(unsignedTx, signerAddress) {
|
|
81
|
+
const decoded = await __1.web3
|
|
82
|
+
.getCurrentNodeProvider()
|
|
83
|
+
.transactions.postTransactionsDecodeUnsignedTx({ unsignedTx: unsignedTx });
|
|
84
|
+
const txId = decoded.unsignedTx.txId;
|
|
85
|
+
const address = typeof signerAddress !== 'undefined' ? signerAddress : (await this.getActiveAccount()).address;
|
|
86
|
+
const signature = await this.signRaw(address, txId);
|
|
81
87
|
const params = { unsignedTx: unsignedTx, signature: signature };
|
|
82
|
-
return
|
|
88
|
+
return __1.web3.getCurrentNodeProvider().transactions.postTransactionsSubmit(params);
|
|
83
89
|
}
|
|
84
90
|
shouldSubmitTx(params) {
|
|
85
91
|
return this.alwaysSubmitTx || (params.submitTx ? params.submitTx : true);
|
|
@@ -100,7 +106,12 @@ class SignerWithNodeProvider {
|
|
|
100
106
|
return this.handleSign({ signerAddress: params.signerAddress, ...response }, this.shouldSubmitTx(params));
|
|
101
107
|
}
|
|
102
108
|
async buildTransferTx(params) {
|
|
103
|
-
|
|
109
|
+
const data = {
|
|
110
|
+
...(await this.usePublicKey(params)),
|
|
111
|
+
destinations: toApiDestinations(params.destinations),
|
|
112
|
+
gasPrice: (0, api_1.toApiNumber256Optional)(params.gasPrice)
|
|
113
|
+
};
|
|
114
|
+
return __1.web3.getCurrentNodeProvider().transactions.postTransactionsBuild(data);
|
|
104
115
|
}
|
|
105
116
|
async signDeployContractTx(params) {
|
|
106
117
|
const response = await this.buildContractCreationTx(params);
|
|
@@ -109,20 +120,31 @@ class SignerWithNodeProvider {
|
|
|
109
120
|
return { ...result, contractId: contractId, contractAddress: response.contractAddress };
|
|
110
121
|
}
|
|
111
122
|
async buildContractCreationTx(params) {
|
|
112
|
-
|
|
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 __1.web3.getCurrentNodeProvider().contracts.postContractsUnsignedTxDeployContract(data);
|
|
113
131
|
}
|
|
114
132
|
async signExecuteScriptTx(params) {
|
|
115
133
|
const response = await this.buildScriptTx(params);
|
|
116
134
|
return this.handleSign({ signerAddress: params.signerAddress, ...response }, this.shouldSubmitTx(params));
|
|
117
135
|
}
|
|
118
136
|
async buildScriptTx(params) {
|
|
119
|
-
|
|
137
|
+
const data = {
|
|
138
|
+
...(await this.usePublicKey(params)),
|
|
139
|
+
tokens: (0, api_1.toApiTokens)(params.tokens)
|
|
140
|
+
};
|
|
141
|
+
return __1.web3.getCurrentNodeProvider().contracts.postContractsUnsignedTxExecuteScript(data);
|
|
120
142
|
}
|
|
121
143
|
// in general, wallet should show the decoded information to user for confirmation
|
|
122
144
|
// please overwrite this function for real wallet
|
|
123
145
|
async signUnsignedTx(params) {
|
|
124
146
|
const data = { unsignedTx: params.unsignedTx };
|
|
125
|
-
const decoded = await
|
|
147
|
+
const decoded = await __1.web3.getCurrentNodeProvider().transactions.postTransactionsDecodeUnsignedTx(data);
|
|
126
148
|
return this.handleSign({
|
|
127
149
|
fromGroup: decoded.fromGroup,
|
|
128
150
|
toGroup: decoded.toGroup,
|
|
@@ -137,7 +159,7 @@ class SignerWithNodeProvider {
|
|
|
137
159
|
const signature = await this.signRaw(response.signerAddress, response.txId);
|
|
138
160
|
// submit the tx if required
|
|
139
161
|
if (submitTx) {
|
|
140
|
-
await
|
|
162
|
+
await __1.web3.getCurrentNodeProvider().transactions.postTransactionsSubmit({
|
|
141
163
|
unsignedTx: response.unsignedTx,
|
|
142
164
|
signature: signature
|
|
143
165
|
});
|
|
@@ -182,3 +204,16 @@ function verifySignedMessage(message, publicKey, signature) {
|
|
|
182
204
|
return verifyHexString(utils.binToHex(messageHash), publicKey, signature);
|
|
183
205
|
}
|
|
184
206
|
exports.verifySignedMessage = verifySignedMessage;
|
|
207
|
+
utils_1.assertType;
|
|
208
|
+
function toApiDestination(data) {
|
|
209
|
+
return { ...data, attoAlphAmount: (0, api_1.toApiNumber256)(data.attoAlphAmount), tokens: (0, api_1.toApiTokens)(data.tokens) };
|
|
210
|
+
}
|
|
211
|
+
exports.toApiDestination = toApiDestination;
|
|
212
|
+
function toApiDestinations(data) {
|
|
213
|
+
return data.map(toApiDestination);
|
|
214
|
+
}
|
|
215
|
+
exports.toApiDestinations = toApiDestinations;
|
|
216
|
+
function fromApiDestination(data) {
|
|
217
|
+
return { ...data, attoAlphAmount: (0, api_1.fromApiNumber256)(data.attoAlphAmount), tokens: (0, api_1.fromApiTokens)(data.tokens) };
|
|
218
|
+
}
|
|
219
|
+
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,15 +1,12 @@
|
|
|
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> {
|
|
6
|
-
provider: NodeProvider;
|
|
7
5
|
pollingInterval: number;
|
|
8
6
|
messageCallback: MessageCallback<Message>;
|
|
9
7
|
errorCallback: ErrorCallback<Message>;
|
|
10
8
|
}
|
|
11
9
|
export declare abstract class Subscription<Message> {
|
|
12
|
-
provider: NodeProvider;
|
|
13
10
|
pollingInterval: number;
|
|
14
11
|
protected messageCallback: MessageCallback<Message>;
|
|
15
12
|
protected errorCallback: ErrorCallback<Message>;
|
|
@@ -24,7 +24,6 @@ exports.Subscription = void 0;
|
|
|
24
24
|
const eventemitter3_1 = __importDefault(require("eventemitter3"));
|
|
25
25
|
class Subscription {
|
|
26
26
|
constructor(options) {
|
|
27
|
-
this.provider = options.provider;
|
|
28
27
|
this.pollingInterval = options.pollingInterval;
|
|
29
28
|
this.messageCallback = options.messageCallback;
|
|
30
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;
|