@alephium/web3 0.5.0-rc.9 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/alephium-web3.min.js +1 -1
- package/dist/alephium-web3.min.js.map +1 -1
- package/dist/src/api/api-alephium.d.ts +56 -6
- package/dist/src/api/api-alephium.js +5 -3
- package/dist/src/api/api-explorer.d.ts +222 -52
- package/dist/src/api/api-explorer.js +17 -15
- package/dist/src/api/explorer-provider.d.ts +18 -0
- package/dist/src/api/explorer-provider.js +65 -0
- package/dist/src/api/index.d.ts +2 -42
- package/dist/src/api/index.js +6 -117
- package/dist/src/api/node-provider.d.ts +21 -0
- package/dist/src/api/node-provider.js +68 -0
- package/dist/src/api/types.d.ts +9 -1
- package/dist/src/api/types.js +17 -1
- package/dist/src/contract/contract.d.ts +6 -3
- package/dist/src/contract/contract.js +31 -28
- package/dist/src/signer/signer.d.ts +4 -8
- package/dist/src/signer/signer.js +26 -8
- package/dist/src/signer/types.d.ts +5 -17
- package/dist/src/utils/index.d.ts +1 -0
- package/dist/src/utils/index.js +1 -0
- package/dist/src/utils/number.d.ts +18 -0
- package/dist/src/utils/number.fixture.d.ts +12 -0
- package/dist/src/utils/number.fixture.js +189 -0
- package/dist/src/utils/number.js +148 -0
- package/package.json +6 -5
- package/src/api/api-alephium.ts +177 -180
- package/src/api/api-explorer.ts +327 -126
- package/src/api/explorer-provider.ts +78 -0
- package/src/api/index.ts +2 -148
- package/src/api/node-provider.ts +84 -0
- package/src/api/types.ts +24 -1
- package/src/contract/contract.ts +31 -29
- package/src/signer/signer.ts +33 -26
- package/src/signer/types.ts +15 -11
- package/src/utils/index.ts +1 -0
- package/src/utils/number.fixture.ts +187 -0
- package/src/utils/number.ts +162 -0
package/dist/src/api/index.d.ts
CHANGED
|
@@ -1,45 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
path: string;
|
|
4
|
-
method: string;
|
|
5
|
-
params: any[];
|
|
6
|
-
}
|
|
7
|
-
export declare type ApiRequestHandler = (args: ApiRequestArguments) => Promise<any>;
|
|
8
|
-
export declare class NodeProvider {
|
|
9
|
-
readonly wallets: NodeApi<string>['wallets'];
|
|
10
|
-
readonly infos: NodeApi<string>['infos'];
|
|
11
|
-
readonly blockflow: NodeApi<string>['blockflow'];
|
|
12
|
-
readonly addresses: NodeApi<string>['addresses'];
|
|
13
|
-
readonly transactions: NodeApi<string>['transactions'];
|
|
14
|
-
readonly mempool: NodeApi<string>['mempool'];
|
|
15
|
-
readonly contracts: NodeApi<string>['contracts'];
|
|
16
|
-
readonly multisig: NodeApi<string>['multisig'];
|
|
17
|
-
readonly utils: NodeApi<string>['utils'];
|
|
18
|
-
readonly miners: NodeApi<string>['miners'];
|
|
19
|
-
readonly events: NodeApi<string>['events'];
|
|
20
|
-
constructor(baseUrl: string, apiKey?: string);
|
|
21
|
-
constructor(provider: NodeProvider);
|
|
22
|
-
constructor(handler: ApiRequestHandler);
|
|
23
|
-
request: (args: ApiRequestArguments) => Promise<any>;
|
|
24
|
-
static Proxy(nodeProvider: NodeProvider): NodeProvider;
|
|
25
|
-
static Remote(handler: ApiRequestHandler): NodeProvider;
|
|
26
|
-
}
|
|
27
|
-
export declare class ExplorerProvider {
|
|
28
|
-
readonly blocks: any;
|
|
29
|
-
readonly transactions: any;
|
|
30
|
-
readonly addresses: any;
|
|
31
|
-
readonly infos: any;
|
|
32
|
-
readonly unconfirmedTransactions: any;
|
|
33
|
-
readonly tokens: any;
|
|
34
|
-
readonly charts: any;
|
|
35
|
-
readonly utils: any;
|
|
36
|
-
constructor(baseUrl: string, apiKey?: string);
|
|
37
|
-
constructor(provider: ExplorerProvider);
|
|
38
|
-
constructor(handler: ApiRequestHandler);
|
|
39
|
-
request: (args: ApiRequestArguments) => Promise<any>;
|
|
40
|
-
static Proxy(explorerProvider: ExplorerProvider): ExplorerProvider;
|
|
41
|
-
static Remote(handler: ApiRequestHandler): ExplorerProvider;
|
|
42
|
-
}
|
|
1
|
+
export * from './node-provider';
|
|
2
|
+
export * from './explorer-provider';
|
|
43
3
|
export * as node from './api-alephium';
|
|
44
4
|
export * as explorer from './api-explorer';
|
|
45
5
|
export * from './types';
|
package/dist/src/api/index.js
CHANGED
|
@@ -32,6 +32,9 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
32
32
|
}) : function(o, v) {
|
|
33
33
|
o["default"] = v;
|
|
34
34
|
});
|
|
35
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
36
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
37
|
+
};
|
|
35
38
|
var __importStar = (this && this.__importStar) || function (mod) {
|
|
36
39
|
if (mod && mod.__esModule) return mod;
|
|
37
40
|
var result = {};
|
|
@@ -39,124 +42,10 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
39
42
|
__setModuleDefault(result, mod);
|
|
40
43
|
return result;
|
|
41
44
|
};
|
|
42
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
43
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
44
|
-
};
|
|
45
45
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
46
|
-
exports.explorer = exports.node =
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
function forwardRequests(api, handler) {
|
|
50
|
-
// Update class properties to forward requests
|
|
51
|
-
for (const [path, pathObject] of Object.entries(api)) {
|
|
52
|
-
for (const method of Object.keys(pathObject)) {
|
|
53
|
-
pathObject[`${method}`] = async (...params) => {
|
|
54
|
-
return handler({ path, method, params });
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
async function request(provider, args) {
|
|
60
|
-
const call = provider[`${args.path}`][`${args.method}`];
|
|
61
|
-
return call(...args.params);
|
|
62
|
-
}
|
|
63
|
-
function initializeNodeApi(baseUrl, apiKey) {
|
|
64
|
-
const nodeApi = new api_alephium_1.Api({
|
|
65
|
-
baseUrl: baseUrl,
|
|
66
|
-
baseApiParams: { secure: true },
|
|
67
|
-
securityWorker: (accessToken) => (accessToken !== null ? { headers: { 'X-API-KEY': `${accessToken}` } } : {})
|
|
68
|
-
});
|
|
69
|
-
nodeApi.setSecurityData(apiKey ?? null);
|
|
70
|
-
return nodeApi;
|
|
71
|
-
}
|
|
72
|
-
class NodeProvider {
|
|
73
|
-
constructor(param0, apiKey) {
|
|
74
|
-
this.request = (args) => {
|
|
75
|
-
return request(this, args);
|
|
76
|
-
};
|
|
77
|
-
let nodeApi;
|
|
78
|
-
if (typeof param0 === 'string') {
|
|
79
|
-
nodeApi = initializeNodeApi(param0, apiKey);
|
|
80
|
-
}
|
|
81
|
-
else if (typeof param0 === 'function') {
|
|
82
|
-
nodeApi = new NodeProvider('https://1.2.3.4:0');
|
|
83
|
-
forwardRequests(nodeApi, param0);
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
nodeApi = param0;
|
|
87
|
-
}
|
|
88
|
-
this.wallets = { ...nodeApi.wallets };
|
|
89
|
-
this.infos = { ...nodeApi.infos };
|
|
90
|
-
this.blockflow = { ...nodeApi.blockflow };
|
|
91
|
-
this.addresses = { ...nodeApi.addresses };
|
|
92
|
-
this.transactions = { ...nodeApi.transactions };
|
|
93
|
-
this.mempool = { ...nodeApi.mempool };
|
|
94
|
-
this.contracts = { ...nodeApi.contracts };
|
|
95
|
-
this.multisig = { ...nodeApi.multisig };
|
|
96
|
-
this.utils = { ...nodeApi.utils };
|
|
97
|
-
this.miners = { ...nodeApi.miners };
|
|
98
|
-
this.events = { ...nodeApi.events };
|
|
99
|
-
}
|
|
100
|
-
// This can prevent the proxied node provider from being modified
|
|
101
|
-
static Proxy(nodeProvider) {
|
|
102
|
-
return new NodeProvider(nodeProvider);
|
|
103
|
-
}
|
|
104
|
-
static Remote(handler) {
|
|
105
|
-
return new NodeProvider(handler);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
exports.NodeProvider = NodeProvider;
|
|
109
|
-
function initializeExplorerApi(baseUrl, apiKey) {
|
|
110
|
-
const explorerApi = new api_explorer_1.Api({
|
|
111
|
-
baseUrl: baseUrl,
|
|
112
|
-
baseApiParams: { secure: true },
|
|
113
|
-
securityWorker: (accessToken) => (accessToken !== null ? { headers: { 'X-API-KEY': `${accessToken}` } } : {})
|
|
114
|
-
});
|
|
115
|
-
explorerApi.setSecurityData(apiKey ?? null);
|
|
116
|
-
return explorerApi;
|
|
117
|
-
}
|
|
118
|
-
class ExplorerProvider {
|
|
119
|
-
constructor(param0, apiKey) {
|
|
120
|
-
this.blocks = api_explorer_1.Api['blocks'];
|
|
121
|
-
this.transactions = api_explorer_1.Api['transactions'];
|
|
122
|
-
this.addresses = api_explorer_1.Api['addresses'];
|
|
123
|
-
this.infos = api_explorer_1.Api['infos'];
|
|
124
|
-
this.unconfirmedTransactions = api_explorer_1.Api['unconfirmedTransactions'];
|
|
125
|
-
this.tokens = api_explorer_1.Api['tokens'];
|
|
126
|
-
this.charts = api_explorer_1.Api['charts'];
|
|
127
|
-
this.utils = api_explorer_1.Api['utils'];
|
|
128
|
-
this.request = (args) => {
|
|
129
|
-
return request(this, args);
|
|
130
|
-
};
|
|
131
|
-
let explorerApi;
|
|
132
|
-
if (typeof param0 === 'string') {
|
|
133
|
-
explorerApi = initializeExplorerApi(param0, apiKey);
|
|
134
|
-
}
|
|
135
|
-
else if (typeof param0 === 'function') {
|
|
136
|
-
explorerApi = new ExplorerProvider('https://1.2.3.4:0');
|
|
137
|
-
forwardRequests(explorerApi, param0);
|
|
138
|
-
}
|
|
139
|
-
else {
|
|
140
|
-
explorerApi = param0;
|
|
141
|
-
}
|
|
142
|
-
this.blocks = { ...explorerApi.blocks };
|
|
143
|
-
this.transactions = { ...explorerApi.transactions };
|
|
144
|
-
this.addresses = { ...explorerApi.addresses };
|
|
145
|
-
this.infos = { ...explorerApi.infos };
|
|
146
|
-
this.unconfirmedTransactions = { ...explorerApi.unconfirmedTransactions };
|
|
147
|
-
this.tokens = { ...explorerApi.tokens };
|
|
148
|
-
this.charts = { ...explorerApi.charts };
|
|
149
|
-
this.utils = { ...explorerApi.utils };
|
|
150
|
-
}
|
|
151
|
-
// This can prevent the proxied explorer provider from being modified
|
|
152
|
-
static Proxy(explorerProvider) {
|
|
153
|
-
return new ExplorerProvider(explorerProvider);
|
|
154
|
-
}
|
|
155
|
-
static Remote(handler) {
|
|
156
|
-
return new ExplorerProvider(handler);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
exports.ExplorerProvider = ExplorerProvider;
|
|
46
|
+
exports.explorer = exports.node = void 0;
|
|
47
|
+
__exportStar(require("./node-provider"), exports);
|
|
48
|
+
__exportStar(require("./explorer-provider"), exports);
|
|
160
49
|
exports.node = __importStar(require("./api-alephium"));
|
|
161
50
|
exports.explorer = __importStar(require("./api-explorer"));
|
|
162
51
|
__exportStar(require("./types"), exports);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ApiRequestArguments, ApiRequestHandler } from './types';
|
|
2
|
+
import { Api as NodeApi } from './api-alephium';
|
|
3
|
+
export declare class NodeProvider {
|
|
4
|
+
readonly wallets: NodeApi<string>['wallets'];
|
|
5
|
+
readonly infos: NodeApi<string>['infos'];
|
|
6
|
+
readonly blockflow: NodeApi<string>['blockflow'];
|
|
7
|
+
readonly addresses: NodeApi<string>['addresses'];
|
|
8
|
+
readonly transactions: NodeApi<string>['transactions'];
|
|
9
|
+
readonly mempool: NodeApi<string>['mempool'];
|
|
10
|
+
readonly contracts: NodeApi<string>['contracts'];
|
|
11
|
+
readonly multisig: NodeApi<string>['multisig'];
|
|
12
|
+
readonly utils: NodeApi<string>['utils'];
|
|
13
|
+
readonly miners: NodeApi<string>['miners'];
|
|
14
|
+
readonly events: NodeApi<string>['events'];
|
|
15
|
+
constructor(baseUrl: string, apiKey?: string);
|
|
16
|
+
constructor(provider: NodeProvider);
|
|
17
|
+
constructor(handler: ApiRequestHandler);
|
|
18
|
+
request: (args: ApiRequestArguments) => Promise<any>;
|
|
19
|
+
static Proxy(nodeProvider: NodeProvider): NodeProvider;
|
|
20
|
+
static Remote(handler: ApiRequestHandler): NodeProvider;
|
|
21
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
Copyright 2018 - 2022 The Alephium Authors
|
|
4
|
+
This file is part of the alephium project.
|
|
5
|
+
|
|
6
|
+
The library is free software: you can redistribute it and/or modify
|
|
7
|
+
it under the terms of the GNU Lesser General Public License as published by
|
|
8
|
+
the Free Software Foundation, either version 3 of the License, or
|
|
9
|
+
(at your option) any later version.
|
|
10
|
+
|
|
11
|
+
The library is distributed in the hope that it will be useful,
|
|
12
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14
|
+
GNU Lesser General Public License for more details.
|
|
15
|
+
|
|
16
|
+
You should have received a copy of the GNU Lesser General Public License
|
|
17
|
+
along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
18
|
+
*/
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.NodeProvider = void 0;
|
|
21
|
+
const types_1 = require("./types");
|
|
22
|
+
const api_alephium_1 = require("./api-alephium");
|
|
23
|
+
function initializeNodeApi(baseUrl, apiKey) {
|
|
24
|
+
const nodeApi = new api_alephium_1.Api({
|
|
25
|
+
baseUrl: baseUrl,
|
|
26
|
+
baseApiParams: { secure: true },
|
|
27
|
+
securityWorker: (accessToken) => (accessToken !== null ? { headers: { 'X-API-KEY': `${accessToken}` } } : {})
|
|
28
|
+
});
|
|
29
|
+
nodeApi.setSecurityData(apiKey ?? null);
|
|
30
|
+
return nodeApi;
|
|
31
|
+
}
|
|
32
|
+
class NodeProvider {
|
|
33
|
+
constructor(param0, apiKey) {
|
|
34
|
+
this.request = (args) => {
|
|
35
|
+
return (0, types_1.request)(this, args);
|
|
36
|
+
};
|
|
37
|
+
let nodeApi;
|
|
38
|
+
if (typeof param0 === 'string') {
|
|
39
|
+
nodeApi = initializeNodeApi(param0, apiKey);
|
|
40
|
+
}
|
|
41
|
+
else if (typeof param0 === 'function') {
|
|
42
|
+
nodeApi = new NodeProvider('https://1.2.3.4:0');
|
|
43
|
+
(0, types_1.forwardRequests)(nodeApi, param0);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
nodeApi = param0;
|
|
47
|
+
}
|
|
48
|
+
this.wallets = { ...nodeApi.wallets };
|
|
49
|
+
this.infos = { ...nodeApi.infos };
|
|
50
|
+
this.blockflow = { ...nodeApi.blockflow };
|
|
51
|
+
this.addresses = { ...nodeApi.addresses };
|
|
52
|
+
this.transactions = { ...nodeApi.transactions };
|
|
53
|
+
this.mempool = { ...nodeApi.mempool };
|
|
54
|
+
this.contracts = { ...nodeApi.contracts };
|
|
55
|
+
this.multisig = { ...nodeApi.multisig };
|
|
56
|
+
this.utils = { ...nodeApi.utils };
|
|
57
|
+
this.miners = { ...nodeApi.miners };
|
|
58
|
+
this.events = { ...nodeApi.events };
|
|
59
|
+
}
|
|
60
|
+
// This can prevent the proxied node provider from being modified
|
|
61
|
+
static Proxy(nodeProvider) {
|
|
62
|
+
return new NodeProvider(nodeProvider);
|
|
63
|
+
}
|
|
64
|
+
static Remote(handler) {
|
|
65
|
+
return new NodeProvider(handler);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
exports.NodeProvider = NodeProvider;
|
package/dist/src/api/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as node from './api-alephium';
|
|
2
|
-
export declare type Number256 = bigint;
|
|
2
|
+
export declare type Number256 = bigint | string;
|
|
3
3
|
export declare type Val = Number256 | boolean | string | Val[];
|
|
4
4
|
export declare type NamedVals = Record<string, Val>;
|
|
5
5
|
export interface Token {
|
|
@@ -22,3 +22,11 @@ export declare function fromApiVals(vals: node.Val[], names: string[], types: st
|
|
|
22
22
|
export declare function fromApiArray(vals: node.Val[], types: string[]): Val[];
|
|
23
23
|
export declare function fromApiVal(v: node.Val, tpe: string): Val;
|
|
24
24
|
export declare function typeLength(tpe: string): number;
|
|
25
|
+
export interface ApiRequestArguments {
|
|
26
|
+
path: string;
|
|
27
|
+
method: string;
|
|
28
|
+
params: any[];
|
|
29
|
+
}
|
|
30
|
+
export declare type ApiRequestHandler = (args: ApiRequestArguments) => Promise<any>;
|
|
31
|
+
export declare function forwardRequests(api: Record<string, any>, handler: ApiRequestHandler): void;
|
|
32
|
+
export declare function request(provider: Record<string, any>, args: ApiRequestArguments): Promise<any>;
|
package/dist/src/api/types.js
CHANGED
|
@@ -17,7 +17,7 @@ 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
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.typeLength = exports.fromApiVal = exports.fromApiArray = exports.fromApiVals = exports.toApiVal = exports.toApiArray = exports.toApiAddress = exports.toApiByteVec = exports.fromApiNumber256 = exports.toApiNumber256Optional = exports.toApiNumber256 = exports.toApiBoolean = exports.fromApiTokens = exports.fromApiToken = exports.toApiTokens = exports.toApiToken = void 0;
|
|
20
|
+
exports.request = exports.forwardRequests = exports.typeLength = exports.fromApiVal = exports.fromApiArray = exports.fromApiVals = exports.toApiVal = exports.toApiArray = exports.toApiAddress = exports.toApiByteVec = exports.fromApiNumber256 = exports.toApiNumber256Optional = exports.toApiNumber256 = exports.toApiBoolean = exports.fromApiTokens = exports.fromApiToken = exports.toApiTokens = exports.toApiToken = void 0;
|
|
21
21
|
const utils_1 = require("../utils");
|
|
22
22
|
utils_1.assertType;
|
|
23
23
|
function toApiToken(token) {
|
|
@@ -245,3 +245,19 @@ function typeLength(tpe) {
|
|
|
245
245
|
return dims.reduce((a, b) => a * b);
|
|
246
246
|
}
|
|
247
247
|
exports.typeLength = typeLength;
|
|
248
|
+
function forwardRequests(api, handler) {
|
|
249
|
+
// Update class properties to forward requests
|
|
250
|
+
for (const [path, pathObject] of Object.entries(api)) {
|
|
251
|
+
for (const method of Object.keys(pathObject)) {
|
|
252
|
+
pathObject[`${method}`] = async (...params) => {
|
|
253
|
+
return handler({ path, method, params });
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
exports.forwardRequests = forwardRequests;
|
|
259
|
+
async function request(provider, args) {
|
|
260
|
+
const call = provider[`${args.path}`][`${args.method}`];
|
|
261
|
+
return call(...args.params);
|
|
262
|
+
}
|
|
263
|
+
exports.request = request;
|
|
@@ -257,6 +257,8 @@ export interface CallContractResult<R> {
|
|
|
257
257
|
txOutputs: Output[];
|
|
258
258
|
events: ContractEvent[];
|
|
259
259
|
}
|
|
260
|
+
export declare const CreateContractEventAddress: string;
|
|
261
|
+
export declare const DestroyContractEventAddress: string;
|
|
260
262
|
export interface SystemEventSig extends EventSig {
|
|
261
263
|
optionalFieldNames?: string[];
|
|
262
264
|
optionalFieldTypes?: string[];
|
|
@@ -279,10 +281,11 @@ export declare abstract class ContractInstance {
|
|
|
279
281
|
constructor(address: Address);
|
|
280
282
|
}
|
|
281
283
|
export declare function fetchContractState<F extends Fields, I extends ContractInstance>(contract: ContractFactory<I, F>, instance: ContractInstance): Promise<ContractState<F>>;
|
|
282
|
-
export declare function subscribeContractCreatedEvent(
|
|
283
|
-
export declare function subscribeContractDestroyedEvent(
|
|
284
|
+
export declare function subscribeContractCreatedEvent(options: SubscribeOptions<ContractCreatedEvent>, fromCount?: number): EventSubscription;
|
|
285
|
+
export declare function subscribeContractDestroyedEvent(options: SubscribeOptions<ContractDestroyedEvent>, fromCount?: number): EventSubscription;
|
|
284
286
|
export declare function decodeEvent<F extends Fields, M extends ContractEvent<F>>(contract: Contract, instance: ContractInstance, event: node.ContractEvent, targetEventIndex: number): M;
|
|
285
287
|
export declare function subscribeContractEvent<F extends Fields, M extends ContractEvent<F>>(contract: Contract, instance: ContractInstance, options: SubscribeOptions<M>, eventName: string, fromCount?: number): EventSubscription;
|
|
286
|
-
export declare function
|
|
288
|
+
export declare function subscribeContractEvents(contract: Contract, instance: ContractInstance, options: SubscribeOptions<ContractEvent<any>>, fromCount?: number): EventSubscription;
|
|
287
289
|
export declare function callMethod<I, F extends Fields, A extends Arguments, R>(contract: ContractFactory<I, F>, instance: ContractInstance, methodName: string, params: Optional<CallContractParams<A>, 'args'>): Promise<CallContractResult<R>>;
|
|
290
|
+
export declare function getContractEventsCurrentCount(contractAddress: Address): Promise<number>;
|
|
288
291
|
export {};
|
|
@@ -43,7 +43,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
43
43
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
44
44
|
};
|
|
45
45
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
46
|
-
exports.callMethod = exports.
|
|
46
|
+
exports.getContractEventsCurrentCount = exports.callMethod = exports.subscribeContractEvents = exports.subscribeContractEvent = exports.decodeEvent = exports.subscribeContractDestroyedEvent = exports.subscribeContractCreatedEvent = exports.fetchContractState = exports.ContractInstance = exports.testMethod = exports.subscribeEventsFromContract = exports.decodeContractDestroyedEvent = exports.decodeContractCreatedEvent = exports.DestroyContractEventAddress = exports.CreateContractEventAddress = exports.ContractFactory = exports.randomTxId = exports.toApiVals = exports.Script = exports.Contract = exports.Artifact = exports.Project = exports.DEFAULT_COMPILER_OPTIONS = exports.DEFAULT_NODE_COMPILER_OPTIONS = void 0;
|
|
47
47
|
const buffer_1 = require("buffer/");
|
|
48
48
|
const crypto_1 = require("crypto");
|
|
49
49
|
const fs_1 = __importDefault(require("fs"));
|
|
@@ -886,6 +886,13 @@ class ContractFactory {
|
|
|
886
886
|
}
|
|
887
887
|
}
|
|
888
888
|
exports.ContractFactory = ContractFactory;
|
|
889
|
+
function specialContractAddress(n) {
|
|
890
|
+
const bytes = new Uint8Array(32).fill(0);
|
|
891
|
+
bytes[31] = n;
|
|
892
|
+
return (0, utils_1.addressFromContractId)((0, utils_1.binToHex)(bytes));
|
|
893
|
+
}
|
|
894
|
+
exports.CreateContractEventAddress = specialContractAddress(-1);
|
|
895
|
+
exports.DestroyContractEventAddress = specialContractAddress(-2);
|
|
889
896
|
function decodeSystemEvent(event, systemEventSig, eventIndex) {
|
|
890
897
|
if (event.eventIndex !== eventIndex) {
|
|
891
898
|
throw new Error(`Invalid event index: ${event.eventIndex}, expected: ${eventIndex}`);
|
|
@@ -968,20 +975,20 @@ async function fetchContractState(contract, instance) {
|
|
|
968
975
|
};
|
|
969
976
|
}
|
|
970
977
|
exports.fetchContractState = fetchContractState;
|
|
971
|
-
function subscribeContractCreatedEvent(
|
|
972
|
-
return subscribeEventsFromContract(options,
|
|
978
|
+
function subscribeContractCreatedEvent(options, fromCount) {
|
|
979
|
+
return subscribeEventsFromContract(options, exports.CreateContractEventAddress, Contract.ContractCreatedEventIndex, (event) => {
|
|
973
980
|
return {
|
|
974
981
|
...decodeContractCreatedEvent(event),
|
|
975
|
-
contractAddress:
|
|
982
|
+
contractAddress: exports.CreateContractEventAddress
|
|
976
983
|
};
|
|
977
984
|
}, fromCount);
|
|
978
985
|
}
|
|
979
986
|
exports.subscribeContractCreatedEvent = subscribeContractCreatedEvent;
|
|
980
|
-
function subscribeContractDestroyedEvent(
|
|
981
|
-
return subscribeEventsFromContract(options,
|
|
987
|
+
function subscribeContractDestroyedEvent(options, fromCount) {
|
|
988
|
+
return subscribeEventsFromContract(options, exports.DestroyContractEventAddress, Contract.ContractDestroyedEventIndex, (event) => {
|
|
982
989
|
return {
|
|
983
990
|
...decodeContractDestroyedEvent(event),
|
|
984
|
-
contractAddress:
|
|
991
|
+
contractAddress: exports.DestroyContractEventAddress
|
|
985
992
|
};
|
|
986
993
|
}, fromCount);
|
|
987
994
|
}
|
|
@@ -1010,27 +1017,12 @@ function subscribeContractEvent(contract, instance, options, eventName, fromCoun
|
|
|
1010
1017
|
return subscribeEventsFromContract(options, instance.address, eventIndex, (event) => decodeEvent(contract, instance, event, eventIndex), fromCount);
|
|
1011
1018
|
}
|
|
1012
1019
|
exports.subscribeContractEvent = subscribeContractEvent;
|
|
1013
|
-
function
|
|
1020
|
+
function subscribeContractEvents(contract, instance, options, fromCount) {
|
|
1014
1021
|
const messageCallback = (event) => {
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
contractAddress: instance.address
|
|
1020
|
-
});
|
|
1021
|
-
}
|
|
1022
|
-
case Contract.ContractDestroyedEventIndex: {
|
|
1023
|
-
return options.messageCallback({
|
|
1024
|
-
...decodeContractDestroyedEvent(event),
|
|
1025
|
-
contractAddress: instance.address
|
|
1026
|
-
});
|
|
1027
|
-
}
|
|
1028
|
-
default:
|
|
1029
|
-
return options.messageCallback({
|
|
1030
|
-
...decodeEvent(contract, instance, event, event.eventIndex),
|
|
1031
|
-
contractAddress: instance.address
|
|
1032
|
-
});
|
|
1033
|
-
}
|
|
1022
|
+
return options.messageCallback({
|
|
1023
|
+
...decodeEvent(contract, instance, event, event.eventIndex),
|
|
1024
|
+
contractAddress: instance.address
|
|
1025
|
+
});
|
|
1034
1026
|
};
|
|
1035
1027
|
const errorCallback = (err, subscription) => {
|
|
1036
1028
|
return options.errorCallback(err, subscription);
|
|
@@ -1042,7 +1034,7 @@ function subscribeAllEvents(contract, instance, options, fromCount) {
|
|
|
1042
1034
|
};
|
|
1043
1035
|
return (0, events_1.subscribeToEvents)(opt, instance.address, fromCount);
|
|
1044
1036
|
}
|
|
1045
|
-
exports.
|
|
1037
|
+
exports.subscribeContractEvents = subscribeContractEvents;
|
|
1046
1038
|
async function callMethod(contract, instance, methodName, params) {
|
|
1047
1039
|
const methodIndex = contract.contract.getMethodIndex(methodName);
|
|
1048
1040
|
const txId = params?.txId ?? randomTxId();
|
|
@@ -1052,3 +1044,14 @@ async function callMethod(contract, instance, methodName, params) {
|
|
|
1052
1044
|
return callResult;
|
|
1053
1045
|
}
|
|
1054
1046
|
exports.callMethod = callMethod;
|
|
1047
|
+
async function getContractEventsCurrentCount(contractAddress) {
|
|
1048
|
+
return (0, global_1.getCurrentNodeProvider)()
|
|
1049
|
+
.events.getEventsContractContractaddressCurrentCount(contractAddress)
|
|
1050
|
+
.catch((error) => {
|
|
1051
|
+
if (error instanceof Error && error.message.includes(`${contractAddress} not found`)) {
|
|
1052
|
+
return 0;
|
|
1053
|
+
}
|
|
1054
|
+
throw error;
|
|
1055
|
+
});
|
|
1056
|
+
}
|
|
1057
|
+
exports.getContractEventsCurrentCount = getContractEventsCurrentCount;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ExplorerProvider, NodeProvider } from '../api';
|
|
2
2
|
import { node } from '../api';
|
|
3
|
-
import { Account, EnableOptionsBase, Destination, SignDeployContractTxParams, SignDeployContractTxResult, SignExecuteScriptTxParams, SignExecuteScriptTxResult, SignMessageParams, SignMessageResult, SignTransferTxParams, SignTransferTxResult, SignUnsignedTxParams, SignUnsignedTxResult, SubmissionResult, SubmitTransactionParams,
|
|
3
|
+
import { Account, EnableOptionsBase, Destination, SignDeployContractTxParams, SignDeployContractTxResult, SignExecuteScriptTxParams, SignExecuteScriptTxResult, SignMessageParams, SignMessageResult, SignTransferTxParams, SignTransferTxResult, SignUnsignedTxParams, SignUnsignedTxResult, SubmissionResult, SubmitTransactionParams, KeyType, MessageHasher } from './types';
|
|
4
4
|
export declare abstract class SignerProvider {
|
|
5
5
|
abstract get nodeProvider(): NodeProvider | undefined;
|
|
6
6
|
abstract get explorerProvider(): ExplorerProvider | undefined;
|
|
@@ -18,12 +18,6 @@ export declare abstract class InteractiveSignerProvider<EnableOptions extends En
|
|
|
18
18
|
protected abstract unsafeEnable(opt?: EnableOptions): Promise<Account>;
|
|
19
19
|
enable(opt?: EnableOptions): Promise<Account>;
|
|
20
20
|
abstract disconnect(): Promise<void>;
|
|
21
|
-
abstract signAndSubmitTransferTx(params: ExtSignTransferTxParams): Promise<SignTransferTxResult>;
|
|
22
|
-
abstract signAndSubmitDeployContractTx(params: ExtSignDeployContractTxParams): Promise<SignDeployContractTxResult>;
|
|
23
|
-
abstract signAndSubmitExecuteScriptTx(params: ExtSignExecuteScriptTxParams): Promise<SignExecuteScriptTxResult>;
|
|
24
|
-
abstract signAndSubmitUnsignedTx(params: ExtSignUnsignedTxParams): Promise<SignUnsignedTxResult>;
|
|
25
|
-
abstract signUnsignedTx(params: ExtSignUnsignedTxParams): Promise<SignUnsignedTxResult>;
|
|
26
|
-
abstract signMessage(params: ExtSignMessageParams): Promise<SignMessageResult>;
|
|
27
21
|
}
|
|
28
22
|
export declare abstract class SignerProviderSimple extends SignerProvider {
|
|
29
23
|
abstract get nodeProvider(): NodeProvider;
|
|
@@ -58,7 +52,9 @@ export declare abstract class SignerProviderWithCachedAccounts<T extends Account
|
|
|
58
52
|
getAccounts(): Promise<T[]>;
|
|
59
53
|
getAccount(address: string): Promise<T>;
|
|
60
54
|
}
|
|
61
|
-
export declare function
|
|
55
|
+
export declare function extendMessage(message: string): string;
|
|
56
|
+
export declare function hashMessage(message: string, hasher: MessageHasher): string;
|
|
57
|
+
export declare function verifySignedMessage(message: string, messageHasher: MessageHasher, publicKey: string, signature: string, keyType?: KeyType): boolean;
|
|
62
58
|
export declare function toApiDestination(data: Destination): node.Destination;
|
|
63
59
|
export declare function toApiDestinations(data: Destination[]): node.Destination[];
|
|
64
60
|
export declare function fromApiDestination(data: node.Destination): Destination;
|
|
@@ -43,7 +43,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
43
43
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
44
44
|
};
|
|
45
45
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
46
|
-
exports.fromApiDestination = exports.toApiDestinations = exports.toApiDestination = exports.verifySignedMessage = exports.SignerProviderWithCachedAccounts = exports.SignerProviderWithMultipleAccounts = exports.SignerProviderSimple = exports.InteractiveSignerProvider = exports.SignerProvider = void 0;
|
|
46
|
+
exports.fromApiDestination = exports.toApiDestinations = exports.toApiDestination = exports.verifySignedMessage = exports.hashMessage = exports.extendMessage = exports.SignerProviderWithCachedAccounts = exports.SignerProviderWithMultipleAccounts = exports.SignerProviderSimple = exports.InteractiveSignerProvider = exports.SignerProvider = void 0;
|
|
47
|
+
const buffer_1 = require("buffer/");
|
|
48
|
+
const crypto_1 = require("crypto");
|
|
47
49
|
const api_1 = require("../api");
|
|
48
50
|
const utils = __importStar(require("../utils"));
|
|
49
51
|
const blakejs_1 = __importDefault(require("blakejs"));
|
|
@@ -135,9 +137,8 @@ class SignerProviderSimple extends SignerProvider {
|
|
|
135
137
|
return { signature, ...response };
|
|
136
138
|
}
|
|
137
139
|
async signMessage(params) {
|
|
138
|
-
const
|
|
139
|
-
const
|
|
140
|
-
const signature = await this.signRaw(params.signerAddress, utils.binToHex(messageHash));
|
|
140
|
+
const messageHash = hashMessage(params.message, params.messageHasher);
|
|
141
|
+
const signature = await this.signRaw(params.signerAddress, messageHash);
|
|
141
142
|
return { signature: signature };
|
|
142
143
|
}
|
|
143
144
|
}
|
|
@@ -198,10 +199,27 @@ exports.SignerProviderWithCachedAccounts = SignerProviderWithCachedAccounts;
|
|
|
198
199
|
function extendMessage(message) {
|
|
199
200
|
return 'Alephium Signed Message: ' + message;
|
|
200
201
|
}
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
202
|
+
exports.extendMessage = extendMessage;
|
|
203
|
+
function hashMessage(message, hasher) {
|
|
204
|
+
switch (hasher) {
|
|
205
|
+
case 'alephium':
|
|
206
|
+
return utils.binToHex(blakejs_1.default.blake2b(extendMessage(message), undefined, 32));
|
|
207
|
+
case 'sha256':
|
|
208
|
+
const sha256 = (0, crypto_1.createHash)('sha256');
|
|
209
|
+
sha256.update(buffer_1.Buffer.from(message));
|
|
210
|
+
return utils.binToHex(sha256.digest());
|
|
211
|
+
case 'blake2b':
|
|
212
|
+
return utils.binToHex(blakejs_1.default.blake2b(message, undefined, 32));
|
|
213
|
+
case 'identity':
|
|
214
|
+
return message;
|
|
215
|
+
default:
|
|
216
|
+
throw Error(`Invalid message hasher: ${hasher}`);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
exports.hashMessage = hashMessage;
|
|
220
|
+
function verifySignedMessage(message, messageHasher, publicKey, signature, keyType) {
|
|
221
|
+
const messageHash = hashMessage(message, messageHasher);
|
|
222
|
+
return utils.verifySignature(messageHash, publicKey, signature, keyType);
|
|
205
223
|
}
|
|
206
224
|
exports.verifySignedMessage = verifySignedMessage;
|
|
207
225
|
function toApiDestination(data) {
|
|
@@ -88,10 +88,12 @@ export interface SignUnsignedTxResult {
|
|
|
88
88
|
gasAmount: number;
|
|
89
89
|
gasPrice: Number256;
|
|
90
90
|
}
|
|
91
|
+
export declare type MessageHasher = 'alephium' | 'sha256' | 'blake2b' | 'identity';
|
|
91
92
|
export interface SignMessageParams {
|
|
92
93
|
signerAddress: string;
|
|
93
94
|
signerKeyType?: KeyType;
|
|
94
95
|
message: string;
|
|
96
|
+
messageHasher: MessageHasher;
|
|
95
97
|
}
|
|
96
98
|
export interface SignMessageResult {
|
|
97
99
|
signature: string;
|
|
@@ -107,21 +109,7 @@ export interface SubmissionResult {
|
|
|
107
109
|
}
|
|
108
110
|
export interface EnableOptionsBase {
|
|
109
111
|
chainGroup?: number;
|
|
110
|
-
|
|
111
|
-
|
|
112
|
+
keyType?: KeyType;
|
|
113
|
+
networkId?: string;
|
|
114
|
+
onDisconnected: () => Promise<void> | void;
|
|
112
115
|
}
|
|
113
|
-
export declare type ExtSignTransferTxParams = SignTransferTxParams & {
|
|
114
|
-
networkId: string;
|
|
115
|
-
};
|
|
116
|
-
export declare type ExtSignDeployContractTxParams = SignDeployContractTxParams & {
|
|
117
|
-
networkId: string;
|
|
118
|
-
};
|
|
119
|
-
export declare type ExtSignExecuteScriptTxParams = SignExecuteScriptTxParams & {
|
|
120
|
-
networkId: string;
|
|
121
|
-
};
|
|
122
|
-
export declare type ExtSignUnsignedTxParams = SignUnsignedTxParams & {
|
|
123
|
-
networkId: string;
|
|
124
|
-
};
|
|
125
|
-
export declare type ExtSignMessageParams = SignMessageParams & {
|
|
126
|
-
networkId: string;
|
|
127
|
-
};
|
package/dist/src/utils/index.js
CHANGED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Number256 } from '..';
|
|
2
|
+
export declare const isNumeric: (numToCheck: any) => boolean;
|
|
3
|
+
export interface IPrettifyNumberConfig {
|
|
4
|
+
minDecimalPlaces: number;
|
|
5
|
+
maxDecimalPlaces: number;
|
|
6
|
+
/** significant digits to show in decimals while respecting decimal places */
|
|
7
|
+
minDecimalSignificantDigits: number;
|
|
8
|
+
/** special case for zero, e.g. we may want to display $0.00 or 0.0 ALPH */
|
|
9
|
+
decimalPlacesWhenZero: number;
|
|
10
|
+
}
|
|
11
|
+
export declare const prettifyNumberConfig: Record<string, IPrettifyNumberConfig>;
|
|
12
|
+
export declare function prettifyAttoAlphAmount(amount: Number256): string | undefined;
|
|
13
|
+
export declare function prettifyTokenAmount(amount: Number256, decimals: number): string | undefined;
|
|
14
|
+
export declare function prettifyExactAmount(amount: Number256, decimals: number): string | undefined;
|
|
15
|
+
export declare function prettifyNumber(amount: Number256, decimals: number, config: IPrettifyNumberConfig): string | undefined;
|
|
16
|
+
export declare function convertAmountWithDecimals(amount: string | number, decimals: number): bigint | undefined;
|
|
17
|
+
export declare function convertAlphAmount(amount: string | number): bigint | undefined;
|
|
18
|
+
export declare function number256ToBigint(number: Number256): bigint;
|