@alephium/web3 0.2.0-rc.30 → 0.2.0-rc.32
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/index.d.ts +12 -1
- package/dist/src/api/index.js +36 -13
- package/dist/src/contract/contract.d.ts +3 -5
- package/dist/src/contract/contract.js +2 -2
- package/dist/src/signer/signer.d.ts +17 -22
- package/dist/src/signer/signer.js +45 -48
- package/package.json +1 -1
- package/src/api/index.ts +51 -12
- package/src/contract/contract.ts +5 -7
- package/src/signer/signer.ts +65 -80
- package/src/utils/subscription.ts +0 -2
- package/webpack.config.js +3 -0
package/dist/src/api/index.d.ts
CHANGED
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
import { Api as NodeApi } from './api-alephium';
|
|
2
2
|
import { Api as ExplorerApi } from './api-explorer';
|
|
3
|
-
export declare class NodeProvider
|
|
3
|
+
export declare class NodeProvider {
|
|
4
|
+
wallets: NodeApi<string>['wallets'];
|
|
5
|
+
infos: NodeApi<string>['infos'];
|
|
6
|
+
blockflow: NodeApi<string>['blockflow'];
|
|
7
|
+
addresses: NodeApi<string>['addresses'];
|
|
8
|
+
transactions: NodeApi<string>['transactions'];
|
|
9
|
+
contracts: NodeApi<string>['contracts'];
|
|
10
|
+
multisig: NodeApi<string>['multisig'];
|
|
11
|
+
utils: NodeApi<string>['utils'];
|
|
12
|
+
miners: NodeApi<string>['miners'];
|
|
13
|
+
events: NodeApi<string>['events'];
|
|
4
14
|
constructor(baseUrl: string, apiKey?: string);
|
|
15
|
+
reset(baseUrl: string, apiKey?: string): void;
|
|
5
16
|
}
|
|
6
17
|
export declare class ExplorerProvider extends ExplorerApi<null> {
|
|
7
18
|
constructor(baseUrl: string);
|
package/dist/src/api/index.js
CHANGED
|
@@ -46,23 +46,46 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
46
46
|
exports.explorer = exports.node = exports.ExplorerProvider = exports.NodeProvider = void 0;
|
|
47
47
|
const api_alephium_1 = require("./api-alephium");
|
|
48
48
|
const api_explorer_1 = require("./api-explorer");
|
|
49
|
-
|
|
49
|
+
function initializeNodeApi(baseUrl, apiKey) {
|
|
50
|
+
const nodeApi = new api_alephium_1.Api({
|
|
51
|
+
baseUrl: baseUrl,
|
|
52
|
+
baseApiParams: { secure: true },
|
|
53
|
+
securityWorker: (accessToken) => (accessToken !== null ? { headers: { 'X-API-KEY': `${accessToken}` } } : {})
|
|
54
|
+
});
|
|
55
|
+
nodeApi.setSecurityData(apiKey ?? null);
|
|
56
|
+
return nodeApi;
|
|
57
|
+
}
|
|
58
|
+
class NodeProvider {
|
|
50
59
|
constructor(baseUrl, apiKey) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
60
|
+
const nodeApi = initializeNodeApi(baseUrl, apiKey);
|
|
61
|
+
this.wallets = nodeApi.wallets;
|
|
62
|
+
this.infos = nodeApi.infos;
|
|
63
|
+
this.blockflow = nodeApi.blockflow;
|
|
64
|
+
this.addresses = nodeApi.addresses;
|
|
65
|
+
this.transactions = nodeApi.transactions;
|
|
66
|
+
this.contracts = nodeApi.contracts;
|
|
67
|
+
this.multisig = nodeApi.multisig;
|
|
68
|
+
this.utils = nodeApi.utils;
|
|
69
|
+
this.miners = nodeApi.miners;
|
|
70
|
+
this.events = nodeApi.events;
|
|
71
|
+
}
|
|
72
|
+
// Have to duplicate the code above due to proxy pattern
|
|
73
|
+
reset(baseUrl, apiKey) {
|
|
74
|
+
const nodeApi = initializeNodeApi(baseUrl, apiKey);
|
|
75
|
+
this.wallets = nodeApi.wallets;
|
|
76
|
+
this.infos = nodeApi.infos;
|
|
77
|
+
this.blockflow = nodeApi.blockflow;
|
|
78
|
+
this.addresses = nodeApi.addresses;
|
|
79
|
+
this.transactions = nodeApi.transactions;
|
|
80
|
+
this.contracts = nodeApi.contracts;
|
|
81
|
+
this.multisig = nodeApi.multisig;
|
|
82
|
+
this.utils = nodeApi.utils;
|
|
83
|
+
this.miners = nodeApi.miners;
|
|
84
|
+
this.events = nodeApi.events;
|
|
63
85
|
}
|
|
64
86
|
}
|
|
65
87
|
exports.NodeProvider = NodeProvider;
|
|
88
|
+
// TODO: use proxy provider once the endpoints are refined.
|
|
66
89
|
class ExplorerProvider extends api_explorer_1.Api {
|
|
67
90
|
constructor(baseUrl) {
|
|
68
91
|
super({ baseUrl: baseUrl });
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { NamedVals, node, Number256, Token, Val } from '../api';
|
|
2
|
-
import { SignDeployContractTxParams, SignExecuteScriptTxParams,
|
|
2
|
+
import { SignDeployContractTxParams, SignExecuteScriptTxParams, SignerProvider } from '../signer';
|
|
3
3
|
export declare type FieldsSig = node.FieldsSig;
|
|
4
4
|
export declare type EventSig = node.EventSig;
|
|
5
5
|
export declare type FunctionSig = node.FunctionSig;
|
|
@@ -122,7 +122,7 @@ export declare class Contract extends Artifact {
|
|
|
122
122
|
static fromApiEvent(event: node.ContractEventByTxId, codeHash: string | undefined): Promise<ContractEventByTxId>;
|
|
123
123
|
fromTestContractResult(methodIndex: number, result: node.TestContractResult): Promise<TestContractResult>;
|
|
124
124
|
paramsForDeployment(params: BuildDeployContractTx): Promise<SignDeployContractTxParams>;
|
|
125
|
-
transactionForDeployment(signer:
|
|
125
|
+
transactionForDeployment(signer: SignerProvider, params: Omit<BuildDeployContractTx, 'signerAddress'>): Promise<DeployContractTransaction>;
|
|
126
126
|
buildByteCodeToDeploy(initialFields: Fields): string;
|
|
127
127
|
}
|
|
128
128
|
export declare class Script extends Artifact {
|
|
@@ -135,7 +135,7 @@ export declare class Script extends Artifact {
|
|
|
135
135
|
static fromArtifactFile(path: string, bytecodeDebugPatch: string): Promise<Script>;
|
|
136
136
|
toString(): string;
|
|
137
137
|
paramsForDeployment(params: BuildExecuteScriptTx): Promise<SignExecuteScriptTxParams>;
|
|
138
|
-
transactionForDeployment(signer:
|
|
138
|
+
transactionForDeployment(signer: SignerProvider, params: Omit<BuildExecuteScriptTx, 'signerAddress'>): Promise<BuildScriptTxResult>;
|
|
139
139
|
buildByteCodeToDeploy(initialFields: Fields): string;
|
|
140
140
|
}
|
|
141
141
|
export interface Asset {
|
|
@@ -218,7 +218,6 @@ export interface BuildDeployContractTx {
|
|
|
218
218
|
issueTokenAmount?: Number256;
|
|
219
219
|
gasAmount?: number;
|
|
220
220
|
gasPrice?: Number256;
|
|
221
|
-
submitTx?: boolean;
|
|
222
221
|
}
|
|
223
222
|
export interface BuildExecuteScriptTx {
|
|
224
223
|
signerAddress: string;
|
|
@@ -227,7 +226,6 @@ export interface BuildExecuteScriptTx {
|
|
|
227
226
|
tokens?: Token[];
|
|
228
227
|
gasAmount?: number;
|
|
229
228
|
gasPrice?: Number256;
|
|
230
|
-
submitTx?: boolean;
|
|
231
229
|
}
|
|
232
230
|
export interface BuildScriptTxResult {
|
|
233
231
|
fromGroup: number;
|
|
@@ -598,7 +598,7 @@ class Contract extends Artifact {
|
|
|
598
598
|
async transactionForDeployment(signer, params) {
|
|
599
599
|
const signerParams = await this.paramsForDeployment({
|
|
600
600
|
...params,
|
|
601
|
-
signerAddress: (await signer.
|
|
601
|
+
signerAddress: (await signer.getSelectedAccount()).address
|
|
602
602
|
});
|
|
603
603
|
const response = await signer.buildContractCreationTx(signerParams);
|
|
604
604
|
return fromApiDeployContractUnsignedTx(response);
|
|
@@ -666,7 +666,7 @@ class Script extends Artifact {
|
|
|
666
666
|
async transactionForDeployment(signer, params) {
|
|
667
667
|
const signerParams = await this.paramsForDeployment({
|
|
668
668
|
...params,
|
|
669
|
-
signerAddress: (await signer.
|
|
669
|
+
signerAddress: (await signer.getSelectedAccount()).address
|
|
670
670
|
});
|
|
671
671
|
return await signer.buildScriptTx(signerParams);
|
|
672
672
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Number256, Token } from '../api';
|
|
1
|
+
import { NodeProvider, Number256, Token } from '../api';
|
|
2
2
|
import { node } from '../api';
|
|
3
3
|
export declare type OutputRef = node.OutputRef;
|
|
4
4
|
export interface SignResult {
|
|
@@ -13,9 +13,6 @@ export interface Account {
|
|
|
13
13
|
group: number;
|
|
14
14
|
publicKey: string;
|
|
15
15
|
}
|
|
16
|
-
export declare type SubmitTx = {
|
|
17
|
-
submitTx?: boolean;
|
|
18
|
-
};
|
|
19
16
|
export declare type SignerAddress = {
|
|
20
17
|
signerAddress: string;
|
|
21
18
|
};
|
|
@@ -27,7 +24,6 @@ export interface SignTransferTxParams {
|
|
|
27
24
|
utxos?: OutputRef[];
|
|
28
25
|
gasAmount?: number;
|
|
29
26
|
gasPrice?: Number256;
|
|
30
|
-
submitTx?: boolean;
|
|
31
27
|
}
|
|
32
28
|
export interface SignTransferTxResult {
|
|
33
29
|
fromGroup: number;
|
|
@@ -44,7 +40,6 @@ export interface SignDeployContractTxParams {
|
|
|
44
40
|
issueTokenAmount?: Number256;
|
|
45
41
|
gasAmount?: number;
|
|
46
42
|
gasPrice?: Number256;
|
|
47
|
-
submitTx?: boolean;
|
|
48
43
|
}
|
|
49
44
|
export interface SignDeployContractTxResult {
|
|
50
45
|
fromGroup: number;
|
|
@@ -62,7 +57,6 @@ export interface SignExecuteScriptTxParams {
|
|
|
62
57
|
tokens?: Token[];
|
|
63
58
|
gasAmount?: number;
|
|
64
59
|
gasPrice?: string;
|
|
65
|
-
submitTx?: boolean;
|
|
66
60
|
}
|
|
67
61
|
export interface SignExecuteScriptTxResult {
|
|
68
62
|
fromGroup: number;
|
|
@@ -74,7 +68,6 @@ export interface SignExecuteScriptTxResult {
|
|
|
74
68
|
export interface SignUnsignedTxParams {
|
|
75
69
|
signerAddress: string;
|
|
76
70
|
unsignedTx: string;
|
|
77
|
-
submitTx?: boolean;
|
|
78
71
|
}
|
|
79
72
|
export interface SignUnsignedTxResult {
|
|
80
73
|
fromGroup: number;
|
|
@@ -97,8 +90,8 @@ export interface SignMessageParams {
|
|
|
97
90
|
export interface SignMessageResult {
|
|
98
91
|
signature: string;
|
|
99
92
|
}
|
|
100
|
-
export interface
|
|
101
|
-
|
|
93
|
+
export interface SignerProviderWithoutNodeProvider {
|
|
94
|
+
getSelectedAccount(): Promise<Account>;
|
|
102
95
|
signTransferTx(params: SignTransferTxParams): Promise<SignTransferTxResult>;
|
|
103
96
|
signDeployContractTx(params: SignDeployContractTxParams): Promise<SignDeployContractTxResult>;
|
|
104
97
|
signExecuteScriptTx(params: SignExecuteScriptTxParams): Promise<SignExecuteScriptTxResult>;
|
|
@@ -106,17 +99,14 @@ export interface SignerProvider {
|
|
|
106
99
|
signHexString(params: SignHexStringParams): Promise<SignHexStringResult>;
|
|
107
100
|
signMessage(params: SignMessageParams): Promise<SignMessageResult>;
|
|
108
101
|
}
|
|
109
|
-
export declare abstract class
|
|
110
|
-
|
|
111
|
-
abstract
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
constructor(alwaysSubmitTx: boolean);
|
|
118
|
-
submitTransaction(unsignedTx: string, signerAddress?: string): Promise<SubmissionResult>;
|
|
119
|
-
private shouldSubmitTx;
|
|
102
|
+
export declare abstract class SignerProvider implements SignerProviderWithoutNodeProvider {
|
|
103
|
+
abstract get nodeProvider(): NodeProvider;
|
|
104
|
+
abstract getSelectedAccount(): Promise<Account>;
|
|
105
|
+
submitTransaction(unsignedTx: string, signature: string): Promise<SubmissionResult>;
|
|
106
|
+
signAndSubmitTransferTx(params: SignTransferTxParams): Promise<SubmissionResult>;
|
|
107
|
+
signAndSubmitDeployContractTx(params: SignDeployContractTxParams): Promise<SubmissionResult>;
|
|
108
|
+
signAndSubmitExecuteScriptTx(params: SignExecuteScriptTxParams): Promise<SubmissionResult>;
|
|
109
|
+
signAndSubmitUnsignedTx(params: SignUnsignedTxParams): Promise<SubmissionResult>;
|
|
120
110
|
private usePublicKey;
|
|
121
111
|
signTransferTx(params: SignTransferTxParams): Promise<SignTransferTxResult>;
|
|
122
112
|
buildTransferTx(params: SignTransferTxParams): Promise<node.BuildTransactionResult>;
|
|
@@ -131,11 +121,16 @@ export declare abstract class SignerWithNodeProvider implements SignerProvider {
|
|
|
131
121
|
signerAddress: string;
|
|
132
122
|
unsignedTx: string;
|
|
133
123
|
txId: string;
|
|
134
|
-
}
|
|
124
|
+
}): Promise<SignResult>;
|
|
135
125
|
signHexString(params: SignHexStringParams): Promise<SignHexStringResult>;
|
|
136
126
|
signMessage(params: SignMessageParams): Promise<SignMessageResult>;
|
|
137
127
|
abstract signRaw(signerAddress: string, hexString: string): Promise<string>;
|
|
138
128
|
}
|
|
129
|
+
export declare abstract class SignerProviderWithMultipleAccounts extends SignerProvider {
|
|
130
|
+
abstract getAccounts(): Promise<Account[]>;
|
|
131
|
+
getAccount(signerAddress: string): Promise<Account>;
|
|
132
|
+
abstract setSelectedAccount(address: string): Promise<void>;
|
|
133
|
+
}
|
|
139
134
|
export interface SubmissionResult {
|
|
140
135
|
txId: string;
|
|
141
136
|
fromGroup: number;
|
|
@@ -43,13 +43,12 @@ 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.verifyHexString = exports.
|
|
46
|
+
exports.fromApiDestination = exports.toApiDestinations = exports.toApiDestination = exports.verifySignedMessage = exports.verifyHexString = exports.SignerProviderWithMultipleAccounts = exports.SignerProvider = void 0;
|
|
47
47
|
const elliptic_1 = require("elliptic");
|
|
48
48
|
const api_1 = require("../api");
|
|
49
49
|
const utils = __importStar(require("../utils"));
|
|
50
50
|
const utils_1 = require("../utils");
|
|
51
51
|
const blakejs_1 = __importDefault(require("blakejs"));
|
|
52
|
-
const __1 = require("..");
|
|
53
52
|
const ec = new elliptic_1.ec('secp256k1');
|
|
54
53
|
(0, utils_1.assertType)();
|
|
55
54
|
(0, utils_1.assertType)();
|
|
@@ -63,47 +62,40 @@ const ec = new elliptic_1.ec('secp256k1');
|
|
|
63
62
|
(0, utils_1.assertType)();
|
|
64
63
|
(0, utils_1.assertType)();
|
|
65
64
|
(0, utils_1.assertType)();
|
|
66
|
-
class
|
|
67
|
-
|
|
68
|
-
|
|
65
|
+
class SignerProvider {
|
|
66
|
+
async submitTransaction(unsignedTx, signature) {
|
|
67
|
+
const params = { unsignedTx: unsignedTx, signature: signature };
|
|
68
|
+
return this.nodeProvider.transactions.postTransactionsSubmit(params);
|
|
69
69
|
}
|
|
70
|
-
async
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
if (typeof account === 'undefined') {
|
|
74
|
-
throw new Error('Unmatched signerAddress');
|
|
75
|
-
}
|
|
76
|
-
else {
|
|
77
|
-
return account;
|
|
78
|
-
}
|
|
70
|
+
async signAndSubmitTransferTx(params) {
|
|
71
|
+
const signResult = await this.signTransferTx(params);
|
|
72
|
+
return this.submitTransaction(signResult.unsignedTx, signResult.signature);
|
|
79
73
|
}
|
|
80
|
-
async
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
const params = { unsignedTx: unsignedTx, signature: signature };
|
|
88
|
-
return __1.web3.getCurrentNodeProvider().transactions.postTransactionsSubmit(params);
|
|
74
|
+
async signAndSubmitDeployContractTx(params) {
|
|
75
|
+
const signResult = await this.signDeployContractTx(params);
|
|
76
|
+
return this.submitTransaction(signResult.unsignedTx, signResult.signature);
|
|
77
|
+
}
|
|
78
|
+
async signAndSubmitExecuteScriptTx(params) {
|
|
79
|
+
const signResult = await this.signExecuteScriptTx(params);
|
|
80
|
+
return this.submitTransaction(signResult.unsignedTx, signResult.signature);
|
|
89
81
|
}
|
|
90
|
-
|
|
91
|
-
|
|
82
|
+
async signAndSubmitUnsignedTx(params) {
|
|
83
|
+
const signResult = await this.signUnsignedTx(params);
|
|
84
|
+
return this.submitTransaction(signResult.unsignedTx, signResult.signature);
|
|
92
85
|
}
|
|
93
86
|
async usePublicKey(params) {
|
|
94
87
|
const { signerAddress, ...restParams } = params;
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
throw new Error('Unknown signer address');
|
|
88
|
+
const selectedAccount = await this.getSelectedAccount();
|
|
89
|
+
if (signerAddress !== selectedAccount.address) {
|
|
90
|
+
throw new Error('The signer address is not the selected address');
|
|
99
91
|
}
|
|
100
92
|
else {
|
|
101
|
-
return { fromPublicKey:
|
|
93
|
+
return { fromPublicKey: selectedAccount.publicKey, ...restParams };
|
|
102
94
|
}
|
|
103
95
|
}
|
|
104
96
|
async signTransferTx(params) {
|
|
105
97
|
const response = await this.buildTransferTx(params);
|
|
106
|
-
return this.handleSign({ signerAddress: params.signerAddress, ...response }
|
|
98
|
+
return this.handleSign({ signerAddress: params.signerAddress, ...response });
|
|
107
99
|
}
|
|
108
100
|
async buildTransferTx(params) {
|
|
109
101
|
const data = {
|
|
@@ -111,11 +103,11 @@ class SignerWithNodeProvider {
|
|
|
111
103
|
destinations: toApiDestinations(params.destinations),
|
|
112
104
|
gasPrice: (0, api_1.toApiNumber256Optional)(params.gasPrice)
|
|
113
105
|
};
|
|
114
|
-
return
|
|
106
|
+
return this.nodeProvider.transactions.postTransactionsBuild(data);
|
|
115
107
|
}
|
|
116
108
|
async signDeployContractTx(params) {
|
|
117
109
|
const response = await this.buildContractCreationTx(params);
|
|
118
|
-
const result = await this.handleSign({ signerAddress: params.signerAddress, ...response }
|
|
110
|
+
const result = await this.handleSign({ signerAddress: params.signerAddress, ...response });
|
|
119
111
|
const contractId = utils.binToHex(utils.contractIdFromAddress(response.contractAddress));
|
|
120
112
|
return { ...result, contractId: contractId, contractAddress: response.contractAddress };
|
|
121
113
|
}
|
|
@@ -127,43 +119,35 @@ class SignerWithNodeProvider {
|
|
|
127
119
|
issueTokenAmount: (0, api_1.toApiNumber256Optional)(params.issueTokenAmount),
|
|
128
120
|
gasPrice: (0, api_1.toApiNumber256Optional)(params.gasPrice)
|
|
129
121
|
};
|
|
130
|
-
return
|
|
122
|
+
return this.nodeProvider.contracts.postContractsUnsignedTxDeployContract(data);
|
|
131
123
|
}
|
|
132
124
|
async signExecuteScriptTx(params) {
|
|
133
125
|
const response = await this.buildScriptTx(params);
|
|
134
|
-
return this.handleSign({ signerAddress: params.signerAddress, ...response }
|
|
126
|
+
return this.handleSign({ signerAddress: params.signerAddress, ...response });
|
|
135
127
|
}
|
|
136
128
|
async buildScriptTx(params) {
|
|
137
129
|
const data = {
|
|
138
130
|
...(await this.usePublicKey(params)),
|
|
139
131
|
tokens: (0, api_1.toApiTokens)(params.tokens)
|
|
140
132
|
};
|
|
141
|
-
return
|
|
133
|
+
return this.nodeProvider.contracts.postContractsUnsignedTxExecuteScript(data);
|
|
142
134
|
}
|
|
143
135
|
// in general, wallet should show the decoded information to user for confirmation
|
|
144
136
|
// please overwrite this function for real wallet
|
|
145
137
|
async signUnsignedTx(params) {
|
|
146
138
|
const data = { unsignedTx: params.unsignedTx };
|
|
147
|
-
const decoded = await
|
|
139
|
+
const decoded = await this.nodeProvider.transactions.postTransactionsDecodeUnsignedTx(data);
|
|
148
140
|
return this.handleSign({
|
|
149
141
|
fromGroup: decoded.fromGroup,
|
|
150
142
|
toGroup: decoded.toGroup,
|
|
151
143
|
signerAddress: params.signerAddress,
|
|
152
144
|
unsignedTx: params.unsignedTx,
|
|
153
145
|
txId: decoded.unsignedTx.txId
|
|
154
|
-
}
|
|
155
|
-
);
|
|
146
|
+
});
|
|
156
147
|
}
|
|
157
|
-
async handleSign(response
|
|
148
|
+
async handleSign(response) {
|
|
158
149
|
// sign the tx
|
|
159
150
|
const signature = await this.signRaw(response.signerAddress, response.txId);
|
|
160
|
-
// submit the tx if required
|
|
161
|
-
if (submitTx) {
|
|
162
|
-
await __1.web3.getCurrentNodeProvider().transactions.postTransactionsSubmit({
|
|
163
|
-
unsignedTx: response.unsignedTx,
|
|
164
|
-
signature: signature
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
151
|
// return the signature back to the provider
|
|
168
152
|
return {
|
|
169
153
|
fromGroup: response.fromGroup,
|
|
@@ -184,7 +168,20 @@ class SignerWithNodeProvider {
|
|
|
184
168
|
return { signature: signature };
|
|
185
169
|
}
|
|
186
170
|
}
|
|
187
|
-
exports.
|
|
171
|
+
exports.SignerProvider = SignerProvider;
|
|
172
|
+
class SignerProviderWithMultipleAccounts extends SignerProvider {
|
|
173
|
+
async getAccount(signerAddress) {
|
|
174
|
+
const accounts = await this.getAccounts();
|
|
175
|
+
const account = accounts.find((a) => a.address === signerAddress);
|
|
176
|
+
if (typeof account === 'undefined') {
|
|
177
|
+
throw new Error('Unmatched signerAddress');
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
return account;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
exports.SignerProviderWithMultipleAccounts = SignerProviderWithMultipleAccounts;
|
|
188
185
|
function verifyHexString(hexString, publicKey, signature) {
|
|
189
186
|
try {
|
|
190
187
|
const key = ec.keyFromPublic(publicKey, 'hex');
|
package/package.json
CHANGED
package/src/api/index.ts
CHANGED
|
@@ -19,22 +19,61 @@ along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
19
19
|
import { Api as NodeApi } from './api-alephium'
|
|
20
20
|
import { Api as ExplorerApi } from './api-explorer'
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
function initializeNodeApi(baseUrl: string, apiKey?: string): NodeApi<string> {
|
|
23
|
+
const nodeApi = new NodeApi<string>({
|
|
24
|
+
baseUrl: baseUrl,
|
|
25
|
+
baseApiParams: { secure: true },
|
|
26
|
+
securityWorker: (accessToken) => (accessToken !== null ? { headers: { 'X-API-KEY': `${accessToken}` } } : {})
|
|
27
|
+
})
|
|
28
|
+
nodeApi.setSecurityData(apiKey ?? null)
|
|
29
|
+
return nodeApi
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export class NodeProvider {
|
|
33
|
+
wallets: NodeApi<string>['wallets']
|
|
34
|
+
infos: NodeApi<string>['infos']
|
|
35
|
+
blockflow: NodeApi<string>['blockflow']
|
|
36
|
+
addresses: NodeApi<string>['addresses']
|
|
37
|
+
transactions: NodeApi<string>['transactions']
|
|
38
|
+
contracts: NodeApi<string>['contracts']
|
|
39
|
+
multisig: NodeApi<string>['multisig']
|
|
40
|
+
utils: NodeApi<string>['utils']
|
|
41
|
+
miners: NodeApi<string>['miners']
|
|
42
|
+
events: NodeApi<string>['events']
|
|
43
|
+
|
|
23
44
|
constructor(baseUrl: string, apiKey?: string) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
45
|
+
const nodeApi = initializeNodeApi(baseUrl, apiKey)
|
|
46
|
+
|
|
47
|
+
this.wallets = nodeApi.wallets
|
|
48
|
+
this.infos = nodeApi.infos
|
|
49
|
+
this.blockflow = nodeApi.blockflow
|
|
50
|
+
this.addresses = nodeApi.addresses
|
|
51
|
+
this.transactions = nodeApi.transactions
|
|
52
|
+
this.contracts = nodeApi.contracts
|
|
53
|
+
this.multisig = nodeApi.multisig
|
|
54
|
+
this.utils = nodeApi.utils
|
|
55
|
+
this.miners = nodeApi.miners
|
|
56
|
+
this.events = nodeApi.events
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Have to duplicate the code above due to proxy pattern
|
|
60
|
+
reset(baseUrl: string, apiKey?: string): void {
|
|
61
|
+
const nodeApi = initializeNodeApi(baseUrl, apiKey)
|
|
62
|
+
|
|
63
|
+
this.wallets = nodeApi.wallets
|
|
64
|
+
this.infos = nodeApi.infos
|
|
65
|
+
this.blockflow = nodeApi.blockflow
|
|
66
|
+
this.addresses = nodeApi.addresses
|
|
67
|
+
this.transactions = nodeApi.transactions
|
|
68
|
+
this.contracts = nodeApi.contracts
|
|
69
|
+
this.multisig = nodeApi.multisig
|
|
70
|
+
this.utils = nodeApi.utils
|
|
71
|
+
this.miners = nodeApi.miners
|
|
72
|
+
this.events = nodeApi.events
|
|
35
73
|
}
|
|
36
74
|
}
|
|
37
75
|
|
|
76
|
+
// TODO: use proxy provider once the endpoints are refined.
|
|
38
77
|
export class ExplorerProvider extends ExplorerApi<null> {
|
|
39
78
|
constructor(baseUrl: string) {
|
|
40
79
|
super({ baseUrl: baseUrl })
|
package/src/contract/contract.ts
CHANGED
|
@@ -36,7 +36,7 @@ import {
|
|
|
36
36
|
fromApiTokens,
|
|
37
37
|
fromApiVals
|
|
38
38
|
} from '../api'
|
|
39
|
-
import { SignDeployContractTxParams, SignExecuteScriptTxParams,
|
|
39
|
+
import { SignDeployContractTxParams, SignExecuteScriptTxParams, SignerProvider } from '../signer'
|
|
40
40
|
import * as ralph from './ralph'
|
|
41
41
|
import { bs58, binToHex, contractIdFromAddress, assertType, Eq } from '../utils'
|
|
42
42
|
import { getCurrentNodeProvider } from '../global'
|
|
@@ -823,12 +823,12 @@ export class Contract extends Artifact {
|
|
|
823
823
|
}
|
|
824
824
|
|
|
825
825
|
async transactionForDeployment(
|
|
826
|
-
signer:
|
|
826
|
+
signer: SignerProvider,
|
|
827
827
|
params: Omit<BuildDeployContractTx, 'signerAddress'>
|
|
828
828
|
): Promise<DeployContractTransaction> {
|
|
829
829
|
const signerParams = await this.paramsForDeployment({
|
|
830
830
|
...params,
|
|
831
|
-
signerAddress: (await signer.
|
|
831
|
+
signerAddress: (await signer.getSelectedAccount()).address
|
|
832
832
|
})
|
|
833
833
|
const response = await signer.buildContractCreationTx(signerParams)
|
|
834
834
|
return fromApiDeployContractUnsignedTx(response)
|
|
@@ -909,12 +909,12 @@ export class Script extends Artifact {
|
|
|
909
909
|
}
|
|
910
910
|
|
|
911
911
|
async transactionForDeployment(
|
|
912
|
-
signer:
|
|
912
|
+
signer: SignerProvider,
|
|
913
913
|
params: Omit<BuildExecuteScriptTx, 'signerAddress'>
|
|
914
914
|
): Promise<BuildScriptTxResult> {
|
|
915
915
|
const signerParams = await this.paramsForDeployment({
|
|
916
916
|
...params,
|
|
917
|
-
signerAddress: (await signer.
|
|
917
|
+
signerAddress: (await signer.getSelectedAccount()).address
|
|
918
918
|
})
|
|
919
919
|
return await signer.buildScriptTx(signerParams)
|
|
920
920
|
}
|
|
@@ -1112,7 +1112,6 @@ export interface BuildDeployContractTx {
|
|
|
1112
1112
|
issueTokenAmount?: Number256
|
|
1113
1113
|
gasAmount?: number
|
|
1114
1114
|
gasPrice?: Number256
|
|
1115
|
-
submitTx?: boolean
|
|
1116
1115
|
}
|
|
1117
1116
|
assertType<Eq<keyof BuildDeployContractTx, keyof BuildTxParams<SignDeployContractTxParams>>>()
|
|
1118
1117
|
|
|
@@ -1123,7 +1122,6 @@ export interface BuildExecuteScriptTx {
|
|
|
1123
1122
|
tokens?: Token[]
|
|
1124
1123
|
gasAmount?: number
|
|
1125
1124
|
gasPrice?: Number256
|
|
1126
|
-
submitTx?: boolean
|
|
1127
1125
|
}
|
|
1128
1126
|
assertType<Eq<keyof BuildExecuteScriptTx, keyof BuildTxParams<SignExecuteScriptTxParams>>>()
|
|
1129
1127
|
|