@alephium/web3 0.2.0-rc.33 → 0.2.0-rc.35
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 +18 -0
- package/dist/src/api/index.js +16 -1
- package/dist/src/api/types.d.ts +2 -2
- package/dist/src/api/types.js +1 -6
- package/dist/src/contract/contract.d.ts +5 -5
- package/dist/src/contract/contract.js +17 -30
- package/dist/src/signer/signer.d.ts +36 -45
- package/dist/src/signer/signer.js +31 -53
- package/package.json +1 -1
- package/src/api/index.ts +33 -0
- package/src/api/types.ts +3 -7
- package/src/contract/contract.ts +24 -34
- package/src/signer/signer.ts +73 -98
package/dist/src/api/index.d.ts
CHANGED
|
@@ -27,6 +27,24 @@ export declare class NodeProvider implements INodeProvider {
|
|
|
27
27
|
constructor(baseUrl: string, apiKey?: string);
|
|
28
28
|
static Proxy(nodeProvider: NodeProvider): NodeProvider;
|
|
29
29
|
}
|
|
30
|
+
export interface RequestArguments {
|
|
31
|
+
path: string;
|
|
32
|
+
method: string;
|
|
33
|
+
params?: any;
|
|
34
|
+
}
|
|
35
|
+
export declare class RemoteNodeProvider implements INodeProvider {
|
|
36
|
+
readonly wallets: NodeApi<string>['wallets'];
|
|
37
|
+
readonly infos: NodeApi<string>['infos'];
|
|
38
|
+
readonly blockflow: NodeApi<string>['blockflow'];
|
|
39
|
+
readonly addresses: NodeApi<string>['addresses'];
|
|
40
|
+
readonly transactions: NodeApi<string>['transactions'];
|
|
41
|
+
readonly contracts: NodeApi<string>['contracts'];
|
|
42
|
+
readonly multisig: NodeApi<string>['multisig'];
|
|
43
|
+
readonly utils: NodeApi<string>['utils'];
|
|
44
|
+
readonly miners: NodeApi<string>['miners'];
|
|
45
|
+
readonly events: NodeApi<string>['events'];
|
|
46
|
+
constructor(request: (request: RequestArguments) => Promise<any>);
|
|
47
|
+
}
|
|
30
48
|
export declare class ExplorerProvider extends ExplorerApi<null> {
|
|
31
49
|
constructor(baseUrl: string);
|
|
32
50
|
}
|
package/dist/src/api/index.js
CHANGED
|
@@ -43,7 +43,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
43
43
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
44
44
|
};
|
|
45
45
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
46
|
-
exports.explorer = exports.node = exports.ExplorerProvider = exports.NodeProvider = void 0;
|
|
46
|
+
exports.explorer = exports.node = exports.ExplorerProvider = exports.RemoteNodeProvider = 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) {
|
|
@@ -81,6 +81,21 @@ class NodeProvider {
|
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
83
|
exports.NodeProvider = NodeProvider;
|
|
84
|
+
class RemoteNodeProvider {
|
|
85
|
+
constructor(request) {
|
|
86
|
+
const fakeNodeProvide = new NodeProvider('https://1.2.3.4:12973');
|
|
87
|
+
Object.assign(this, fakeNodeProvide); // Initialize the class
|
|
88
|
+
// Update class properties to forward requests
|
|
89
|
+
for (const [path, pathObject] of Object.entries(this)) {
|
|
90
|
+
for (const method of Object.keys(pathObject)) {
|
|
91
|
+
pathObject[`${method}`] = async (params) => {
|
|
92
|
+
return request({ path, method, params });
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
exports.RemoteNodeProvider = RemoteNodeProvider;
|
|
84
99
|
// TODO: use proxy provider once the endpoints are refined.
|
|
85
100
|
class ExplorerProvider extends api_explorer_1.Api {
|
|
86
101
|
constructor(baseUrl) {
|
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 =
|
|
2
|
+
export declare type Number256 = bigint;
|
|
3
3
|
export declare type Val = Number256 | boolean | string | Val[];
|
|
4
4
|
export declare type NamedVals = Record<string, Val>;
|
|
5
5
|
export interface Token {
|
|
@@ -13,7 +13,7 @@ export declare function fromApiTokens(tokens?: node.Token[]): Token[] | undefine
|
|
|
13
13
|
export declare function toApiBoolean(v: Val): boolean;
|
|
14
14
|
export declare function toApiNumber256(v: Val): string;
|
|
15
15
|
export declare function toApiNumber256Optional(v?: Val): string | undefined;
|
|
16
|
-
export declare function fromApiNumber256(n: string):
|
|
16
|
+
export declare function fromApiNumber256(n: string): bigint;
|
|
17
17
|
export declare function toApiByteVec(v: Val): string;
|
|
18
18
|
export declare function toApiAddress(v: Val): string;
|
|
19
19
|
export declare function toApiArray(tpe: string, v: Val): node.Val;
|
package/dist/src/api/types.js
CHANGED
|
@@ -63,12 +63,7 @@ function toApiNumber256Optional(v) {
|
|
|
63
63
|
}
|
|
64
64
|
exports.toApiNumber256Optional = toApiNumber256Optional;
|
|
65
65
|
function fromApiNumber256(n) {
|
|
66
|
-
|
|
67
|
-
return Number(n);
|
|
68
|
-
}
|
|
69
|
-
else {
|
|
70
|
-
return BigInt(n);
|
|
71
|
-
}
|
|
66
|
+
return BigInt(n);
|
|
72
67
|
}
|
|
73
68
|
exports.fromApiNumber256 = fromApiNumber256;
|
|
74
69
|
// TODO: check hex string
|
|
@@ -121,8 +121,8 @@ export declare class Contract extends Artifact {
|
|
|
121
121
|
static ContractDestroyedEvent: EventSig;
|
|
122
122
|
static fromApiEvent(event: node.ContractEventByTxId, codeHash: string | undefined): Promise<ContractEventByTxId>;
|
|
123
123
|
fromTestContractResult(methodIndex: number, result: node.TestContractResult): Promise<TestContractResult>;
|
|
124
|
-
|
|
125
|
-
|
|
124
|
+
txParamsForDeployment(signer: SignerProvider, params: Omit<BuildDeployContractTx, 'signerAddress'>): Promise<SignDeployContractTxParams>;
|
|
125
|
+
deploy(signer: SignerProvider, params: Omit<BuildDeployContractTx, 'signerAddress'>): Promise<DeployContractTransaction>;
|
|
126
126
|
buildByteCodeToDeploy(initialFields: Fields): string;
|
|
127
127
|
}
|
|
128
128
|
export declare class Script extends Artifact {
|
|
@@ -134,8 +134,8 @@ export declare class Script extends Artifact {
|
|
|
134
134
|
static fromJson(artifact: any, bytecodeDebugPatch?: string): Script;
|
|
135
135
|
static fromArtifactFile(path: string, bytecodeDebugPatch: string): Promise<Script>;
|
|
136
136
|
toString(): string;
|
|
137
|
-
|
|
138
|
-
|
|
137
|
+
txParamsForExecution(signer: SignerProvider, params: Omit<BuildExecuteScriptTx, 'signerAddress'>): Promise<SignExecuteScriptTxParams>;
|
|
138
|
+
execute(signer: SignerProvider, params: Omit<BuildExecuteScriptTx, 'signerAddress'>): Promise<BuildScriptTxResult>;
|
|
139
139
|
buildByteCodeToDeploy(initialFields: Fields): string;
|
|
140
140
|
}
|
|
141
141
|
export interface Asset {
|
|
@@ -213,7 +213,7 @@ export interface DeployContractTransaction {
|
|
|
213
213
|
export interface BuildDeployContractTx {
|
|
214
214
|
signerAddress: string;
|
|
215
215
|
initialFields?: Fields;
|
|
216
|
-
initialAttoAlphAmount?:
|
|
216
|
+
initialAttoAlphAmount?: Number256;
|
|
217
217
|
initialTokenAmounts?: Token[];
|
|
218
218
|
issueTokenAmount?: Number256;
|
|
219
219
|
gasAmount?: number;
|
|
@@ -582,26 +582,22 @@ class Contract extends Artifact {
|
|
|
582
582
|
debugMessages: result.debugMessages
|
|
583
583
|
};
|
|
584
584
|
}
|
|
585
|
-
async
|
|
585
|
+
async txParamsForDeployment(signer, params) {
|
|
586
586
|
const bytecode = this.buildByteCodeToDeploy(params.initialFields ? params.initialFields : {});
|
|
587
587
|
const signerParams = {
|
|
588
|
-
signerAddress:
|
|
588
|
+
signerAddress: (await signer.getSelectedAccount()).address,
|
|
589
589
|
bytecode: bytecode,
|
|
590
|
-
initialAttoAlphAmount:
|
|
591
|
-
issueTokenAmount:
|
|
592
|
-
initialTokenAmounts:
|
|
590
|
+
initialAttoAlphAmount: params.initialAttoAlphAmount,
|
|
591
|
+
issueTokenAmount: params.issueTokenAmount,
|
|
592
|
+
initialTokenAmounts: params.initialTokenAmounts,
|
|
593
593
|
gasAmount: params.gasAmount,
|
|
594
|
-
gasPrice:
|
|
594
|
+
gasPrice: params.gasPrice
|
|
595
595
|
};
|
|
596
596
|
return signerParams;
|
|
597
597
|
}
|
|
598
|
-
async
|
|
599
|
-
const signerParams = await this.
|
|
600
|
-
|
|
601
|
-
signerAddress: (await signer.getSelectedAccount()).address
|
|
602
|
-
});
|
|
603
|
-
const response = await signer.buildContractCreationTx(signerParams);
|
|
604
|
-
return fromApiDeployContractUnsignedTx(response);
|
|
598
|
+
async deploy(signer, params) {
|
|
599
|
+
const signerParams = await this.txParamsForDeployment(signer, params);
|
|
600
|
+
return signer.signAndSubmitDeployContractTx(signerParams);
|
|
605
601
|
}
|
|
606
602
|
buildByteCodeToDeploy(initialFields) {
|
|
607
603
|
return ralph.buildContractByteCode(this.bytecode, initialFields, this.fieldsSig);
|
|
@@ -652,32 +648,26 @@ class Script extends Artifact {
|
|
|
652
648
|
};
|
|
653
649
|
return JSON.stringify(object, null, 2);
|
|
654
650
|
}
|
|
655
|
-
async
|
|
651
|
+
async txParamsForExecution(signer, params) {
|
|
656
652
|
const signerParams = {
|
|
657
|
-
signerAddress:
|
|
653
|
+
signerAddress: (await signer.getSelectedAccount()).address,
|
|
658
654
|
bytecode: this.buildByteCodeToDeploy(params.initialFields ? params.initialFields : {}),
|
|
659
|
-
attoAlphAmount:
|
|
660
|
-
tokens:
|
|
655
|
+
attoAlphAmount: params.attoAlphAmount,
|
|
656
|
+
tokens: params.tokens,
|
|
661
657
|
gasAmount: params.gasAmount,
|
|
662
|
-
gasPrice:
|
|
658
|
+
gasPrice: params.gasPrice
|
|
663
659
|
};
|
|
664
660
|
return signerParams;
|
|
665
661
|
}
|
|
666
|
-
async
|
|
667
|
-
const signerParams = await this.
|
|
668
|
-
|
|
669
|
-
signerAddress: (await signer.getSelectedAccount()).address
|
|
670
|
-
});
|
|
671
|
-
return await signer.buildScriptTx(signerParams);
|
|
662
|
+
async execute(signer, params) {
|
|
663
|
+
const signerParams = await this.txParamsForExecution(signer, params);
|
|
664
|
+
return await signer.signAndSubmitExecuteScriptTx(signerParams);
|
|
672
665
|
}
|
|
673
666
|
buildByteCodeToDeploy(initialFields) {
|
|
674
667
|
return ralph.buildScriptByteCode(this.bytecodeTemplate, initialFields, this.fieldsSig);
|
|
675
668
|
}
|
|
676
669
|
}
|
|
677
670
|
exports.Script = Script;
|
|
678
|
-
function extractOptionalNumber256(v) {
|
|
679
|
-
return typeof v !== 'undefined' ? (0, api_1.toApiNumber256)(v) : undefined;
|
|
680
|
-
}
|
|
681
671
|
function fromApiFields(vals, fieldsSig) {
|
|
682
672
|
return (0, api_1.fromApiVals)(vals, fieldsSig.names, fieldsSig.types);
|
|
683
673
|
}
|
|
@@ -758,8 +748,5 @@ function fromApiOutput(output) {
|
|
|
758
748
|
throw new Error(`Unknown output type: ${output}`);
|
|
759
749
|
}
|
|
760
750
|
}
|
|
761
|
-
function fromApiDeployContractUnsignedTx(result) {
|
|
762
|
-
return { ...result, contractId: (0, utils_1.binToHex)((0, utils_1.contractIdFromAddress)(result.contractAddress)) };
|
|
763
|
-
}
|
|
764
751
|
(0, utils_1.assertType)();
|
|
765
752
|
(0, utils_1.assertType)();
|
|
@@ -1,13 +1,6 @@
|
|
|
1
1
|
import { NodeProvider, Number256, Token } from '../api';
|
|
2
2
|
import { node } from '../api';
|
|
3
3
|
export declare type OutputRef = node.OutputRef;
|
|
4
|
-
export interface SignResult {
|
|
5
|
-
fromGroup: number;
|
|
6
|
-
toGroup: number;
|
|
7
|
-
unsignedTx: string;
|
|
8
|
-
txId: string;
|
|
9
|
-
signature: string;
|
|
10
|
-
}
|
|
11
4
|
export interface Account {
|
|
12
5
|
address: string;
|
|
13
6
|
group: number;
|
|
@@ -16,8 +9,6 @@ export interface Account {
|
|
|
16
9
|
export declare type SignerAddress = {
|
|
17
10
|
signerAddress: string;
|
|
18
11
|
};
|
|
19
|
-
export declare type GetAccountsParams = undefined;
|
|
20
|
-
export declare type GetAccountsResult = Account[];
|
|
21
12
|
export interface SignTransferTxParams {
|
|
22
13
|
signerAddress: string;
|
|
23
14
|
destinations: Destination[];
|
|
@@ -31,6 +22,8 @@ export interface SignTransferTxResult {
|
|
|
31
22
|
unsignedTx: string;
|
|
32
23
|
txId: string;
|
|
33
24
|
signature: string;
|
|
25
|
+
gasAmount: number;
|
|
26
|
+
gasPrice: Number256;
|
|
34
27
|
}
|
|
35
28
|
export interface SignDeployContractTxParams {
|
|
36
29
|
signerAddress: string;
|
|
@@ -49,14 +42,16 @@ export interface SignDeployContractTxResult {
|
|
|
49
42
|
signature: string;
|
|
50
43
|
contractId: string;
|
|
51
44
|
contractAddress: string;
|
|
45
|
+
gasAmount: number;
|
|
46
|
+
gasPrice: Number256;
|
|
52
47
|
}
|
|
53
48
|
export interface SignExecuteScriptTxParams {
|
|
54
49
|
signerAddress: string;
|
|
55
50
|
bytecode: string;
|
|
56
|
-
attoAlphAmount?:
|
|
51
|
+
attoAlphAmount?: Number256;
|
|
57
52
|
tokens?: Token[];
|
|
58
53
|
gasAmount?: number;
|
|
59
|
-
gasPrice?:
|
|
54
|
+
gasPrice?: Number256;
|
|
60
55
|
}
|
|
61
56
|
export interface SignExecuteScriptTxResult {
|
|
62
57
|
fromGroup: number;
|
|
@@ -64,6 +59,8 @@ export interface SignExecuteScriptTxResult {
|
|
|
64
59
|
unsignedTx: string;
|
|
65
60
|
txId: string;
|
|
66
61
|
signature: string;
|
|
62
|
+
gasAmount: number;
|
|
63
|
+
gasPrice: Number256;
|
|
67
64
|
}
|
|
68
65
|
export interface SignUnsignedTxParams {
|
|
69
66
|
signerAddress: string;
|
|
@@ -75,13 +72,8 @@ export interface SignUnsignedTxResult {
|
|
|
75
72
|
unsignedTx: string;
|
|
76
73
|
txId: string;
|
|
77
74
|
signature: string;
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
signerAddress: string;
|
|
81
|
-
hexString: string;
|
|
82
|
-
}
|
|
83
|
-
export interface SignHexStringResult {
|
|
84
|
-
signature: string;
|
|
75
|
+
gasAmount: number;
|
|
76
|
+
gasPrice: Number256;
|
|
85
77
|
}
|
|
86
78
|
export interface SignMessageParams {
|
|
87
79
|
signerAddress: string;
|
|
@@ -90,15 +82,34 @@ export interface SignMessageParams {
|
|
|
90
82
|
export interface SignMessageResult {
|
|
91
83
|
signature: string;
|
|
92
84
|
}
|
|
93
|
-
export
|
|
85
|
+
export interface SubmitTransactionParams {
|
|
86
|
+
unsignedTx: string;
|
|
87
|
+
signature: string;
|
|
88
|
+
}
|
|
89
|
+
export interface SubmissionResult {
|
|
90
|
+
txId: string;
|
|
91
|
+
fromGroup: number;
|
|
92
|
+
toGroup: number;
|
|
93
|
+
}
|
|
94
|
+
export interface SignerProvider {
|
|
95
|
+
get nodeProvider(): NodeProvider | undefined;
|
|
96
|
+
getSelectedAccount(): Promise<Account>;
|
|
97
|
+
signAndSubmitTransferTx(params: SignTransferTxParams): Promise<SignTransferTxResult>;
|
|
98
|
+
signAndSubmitDeployContractTx(params: SignDeployContractTxParams): Promise<SignDeployContractTxResult>;
|
|
99
|
+
signAndSubmitExecuteScriptTx(params: SignExecuteScriptTxParams): Promise<SignExecuteScriptTxResult>;
|
|
100
|
+
signAndSubmitUnsignedTx(params: SignUnsignedTxParams): Promise<SignUnsignedTxResult>;
|
|
101
|
+
signUnsignedTx(params: SignUnsignedTxParams): Promise<SignUnsignedTxResult>;
|
|
102
|
+
signMessage(params: SignMessageParams): Promise<SignMessageResult>;
|
|
103
|
+
}
|
|
104
|
+
export declare abstract class SignerProviderSimple implements SignerProvider {
|
|
94
105
|
abstract get nodeProvider(): NodeProvider | undefined;
|
|
95
106
|
abstract getSelectedAccount(): Promise<Account>;
|
|
96
107
|
private getNodeProvider;
|
|
97
|
-
submitTransaction(
|
|
98
|
-
signAndSubmitTransferTx(params: SignTransferTxParams): Promise<
|
|
99
|
-
signAndSubmitDeployContractTx(params: SignDeployContractTxParams): Promise<
|
|
100
|
-
signAndSubmitExecuteScriptTx(params: SignExecuteScriptTxParams): Promise<
|
|
101
|
-
signAndSubmitUnsignedTx(params: SignUnsignedTxParams): Promise<
|
|
108
|
+
submitTransaction(params: SubmitTransactionParams): Promise<SubmissionResult>;
|
|
109
|
+
signAndSubmitTransferTx(params: SignTransferTxParams): Promise<SignTransferTxResult>;
|
|
110
|
+
signAndSubmitDeployContractTx(params: SignDeployContractTxParams): Promise<SignDeployContractTxResult>;
|
|
111
|
+
signAndSubmitExecuteScriptTx(params: SignExecuteScriptTxParams): Promise<SignExecuteScriptTxResult>;
|
|
112
|
+
signAndSubmitUnsignedTx(params: SignUnsignedTxParams): Promise<SignUnsignedTxResult>;
|
|
102
113
|
private usePublicKey;
|
|
103
114
|
signTransferTx(params: SignTransferTxParams): Promise<SignTransferTxResult>;
|
|
104
115
|
buildTransferTx(params: SignTransferTxParams): Promise<node.BuildTransactionResult>;
|
|
@@ -107,34 +118,14 @@ export declare abstract class SignerProvider {
|
|
|
107
118
|
signExecuteScriptTx(params: SignExecuteScriptTxParams): Promise<SignExecuteScriptTxResult>;
|
|
108
119
|
buildScriptTx(params: SignExecuteScriptTxParams): Promise<node.BuildExecuteScriptTxResult>;
|
|
109
120
|
signUnsignedTx(params: SignUnsignedTxParams): Promise<SignUnsignedTxResult>;
|
|
110
|
-
protected handleSign(response: {
|
|
111
|
-
fromGroup: number;
|
|
112
|
-
toGroup: number;
|
|
113
|
-
signerAddress: string;
|
|
114
|
-
unsignedTx: string;
|
|
115
|
-
txId: string;
|
|
116
|
-
}): Promise<SignResult>;
|
|
117
|
-
signHexString(params: SignHexStringParams): Promise<SignHexStringResult>;
|
|
118
121
|
signMessage(params: SignMessageParams): Promise<SignMessageResult>;
|
|
119
122
|
abstract signRaw(signerAddress: string, hexString: string): Promise<string>;
|
|
120
123
|
}
|
|
121
|
-
export declare abstract class SignerProviderWithMultipleAccounts extends
|
|
124
|
+
export declare abstract class SignerProviderWithMultipleAccounts extends SignerProviderSimple {
|
|
122
125
|
abstract getAccounts(): Promise<Account[]>;
|
|
123
126
|
getAccount(signerAddress: string): Promise<Account>;
|
|
124
127
|
abstract setSelectedAccount(address: string): Promise<void>;
|
|
125
128
|
}
|
|
126
|
-
export declare class SignerProviderWrapper extends SignerProvider {
|
|
127
|
-
signer: SignerProvider;
|
|
128
|
-
nodeProvider: NodeProvider;
|
|
129
|
-
constructor(signer: SignerProvider, nodeProvider: NodeProvider);
|
|
130
|
-
getSelectedAccount(): Promise<Account>;
|
|
131
|
-
signRaw(signerAddress: string, hexString: string): Promise<string>;
|
|
132
|
-
}
|
|
133
|
-
export interface SubmissionResult {
|
|
134
|
-
txId: string;
|
|
135
|
-
fromGroup: number;
|
|
136
|
-
toGroup: number;
|
|
137
|
-
}
|
|
138
129
|
export declare function verifyHexString(hexString: string, publicKey: string, signature: string): boolean;
|
|
139
130
|
export declare function verifySignedMessage(message: string, publicKey: string, signature: string): boolean;
|
|
140
131
|
export interface Destination {
|
|
@@ -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.fromApiDestination = exports.toApiDestinations = exports.toApiDestination = exports.verifySignedMessage = exports.verifyHexString = exports.
|
|
46
|
+
exports.fromApiDestination = exports.toApiDestinations = exports.toApiDestination = exports.verifySignedMessage = exports.verifyHexString = exports.SignerProviderWithMultipleAccounts = exports.SignerProviderSimple = void 0;
|
|
47
47
|
const elliptic_1 = require("elliptic");
|
|
48
48
|
const api_1 = require("../api");
|
|
49
49
|
const utils = __importStar(require("../utils"));
|
|
@@ -57,37 +57,38 @@ const ec = new elliptic_1.ec('secp256k1');
|
|
|
57
57
|
(0, utils_1.assertType)();
|
|
58
58
|
(0, utils_1.assertType)();
|
|
59
59
|
(0, utils_1.assertType)();
|
|
60
|
+
utils_1.assertType;
|
|
60
61
|
(0, utils_1.assertType)();
|
|
61
|
-
|
|
62
|
-
(0, utils_1.assertType)();
|
|
63
|
-
(0, utils_1.assertType)();
|
|
64
|
-
(0, utils_1.assertType)();
|
|
65
|
-
class SignerProvider {
|
|
62
|
+
class SignerProviderSimple {
|
|
66
63
|
getNodeProvider() {
|
|
67
64
|
if (this.nodeProvider === undefined) {
|
|
68
65
|
throw Error('The signer does not contain a node provider');
|
|
69
66
|
}
|
|
70
67
|
return this.nodeProvider;
|
|
71
68
|
}
|
|
72
|
-
async submitTransaction(
|
|
73
|
-
const
|
|
74
|
-
return this.getNodeProvider().transactions.postTransactionsSubmit(
|
|
69
|
+
async submitTransaction(params) {
|
|
70
|
+
const data = { unsignedTx: params.unsignedTx, signature: params.signature };
|
|
71
|
+
return this.getNodeProvider().transactions.postTransactionsSubmit(data);
|
|
75
72
|
}
|
|
76
73
|
async signAndSubmitTransferTx(params) {
|
|
77
74
|
const signResult = await this.signTransferTx(params);
|
|
78
|
-
|
|
75
|
+
await this.submitTransaction(signResult);
|
|
76
|
+
return signResult;
|
|
79
77
|
}
|
|
80
78
|
async signAndSubmitDeployContractTx(params) {
|
|
81
79
|
const signResult = await this.signDeployContractTx(params);
|
|
82
|
-
|
|
80
|
+
await this.submitTransaction(signResult);
|
|
81
|
+
return signResult;
|
|
83
82
|
}
|
|
84
83
|
async signAndSubmitExecuteScriptTx(params) {
|
|
85
84
|
const signResult = await this.signExecuteScriptTx(params);
|
|
86
|
-
|
|
85
|
+
await this.submitTransaction(signResult);
|
|
86
|
+
return signResult;
|
|
87
87
|
}
|
|
88
88
|
async signAndSubmitUnsignedTx(params) {
|
|
89
89
|
const signResult = await this.signUnsignedTx(params);
|
|
90
|
-
|
|
90
|
+
await this.submitTransaction(signResult);
|
|
91
|
+
return signResult;
|
|
91
92
|
}
|
|
92
93
|
async usePublicKey(params) {
|
|
93
94
|
const { signerAddress, ...restParams } = params;
|
|
@@ -101,7 +102,8 @@ class SignerProvider {
|
|
|
101
102
|
}
|
|
102
103
|
async signTransferTx(params) {
|
|
103
104
|
const response = await this.buildTransferTx(params);
|
|
104
|
-
|
|
105
|
+
const signature = await this.signRaw(params.signerAddress, response.txId);
|
|
106
|
+
return { ...response, signature, gasPrice: (0, api_1.fromApiNumber256)(response.gasPrice) };
|
|
105
107
|
}
|
|
106
108
|
async buildTransferTx(params) {
|
|
107
109
|
const data = {
|
|
@@ -113,9 +115,9 @@ class SignerProvider {
|
|
|
113
115
|
}
|
|
114
116
|
async signDeployContractTx(params) {
|
|
115
117
|
const response = await this.buildContractCreationTx(params);
|
|
116
|
-
const
|
|
118
|
+
const signature = await this.signRaw(params.signerAddress, response.txId);
|
|
117
119
|
const contractId = utils.binToHex(utils.contractIdFromAddress(response.contractAddress));
|
|
118
|
-
return { ...
|
|
120
|
+
return { ...response, contractId, signature, gasPrice: (0, api_1.fromApiNumber256)(response.gasPrice) };
|
|
119
121
|
}
|
|
120
122
|
async buildContractCreationTx(params) {
|
|
121
123
|
const data = {
|
|
@@ -129,12 +131,15 @@ class SignerProvider {
|
|
|
129
131
|
}
|
|
130
132
|
async signExecuteScriptTx(params) {
|
|
131
133
|
const response = await this.buildScriptTx(params);
|
|
132
|
-
|
|
134
|
+
const signature = await this.signRaw(params.signerAddress, response.txId);
|
|
135
|
+
return { ...response, signature, gasPrice: (0, api_1.fromApiNumber256)(response.gasPrice) };
|
|
133
136
|
}
|
|
134
137
|
async buildScriptTx(params) {
|
|
135
138
|
const data = {
|
|
136
139
|
...(await this.usePublicKey(params)),
|
|
137
|
-
|
|
140
|
+
attoAlphAmount: (0, api_1.toApiNumber256Optional)(params.attoAlphAmount),
|
|
141
|
+
tokens: (0, api_1.toApiTokens)(params.tokens),
|
|
142
|
+
gasPrice: (0, api_1.toApiNumber256Optional)(params.gasPrice)
|
|
138
143
|
};
|
|
139
144
|
return this.getNodeProvider().contracts.postContractsUnsignedTxExecuteScript(data);
|
|
140
145
|
}
|
|
@@ -143,30 +148,17 @@ class SignerProvider {
|
|
|
143
148
|
async signUnsignedTx(params) {
|
|
144
149
|
const data = { unsignedTx: params.unsignedTx };
|
|
145
150
|
const decoded = await this.getNodeProvider().transactions.postTransactionsDecodeUnsignedTx(data);
|
|
146
|
-
|
|
151
|
+
const signature = await this.signRaw(params.signerAddress, decoded.unsignedTx.txId);
|
|
152
|
+
return {
|
|
147
153
|
fromGroup: decoded.fromGroup,
|
|
148
154
|
toGroup: decoded.toGroup,
|
|
149
|
-
signerAddress: params.signerAddress,
|
|
150
155
|
unsignedTx: params.unsignedTx,
|
|
151
|
-
txId: decoded.unsignedTx.txId
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
// sign the tx
|
|
156
|
-
const signature = await this.signRaw(response.signerAddress, response.txId);
|
|
157
|
-
// return the signature back to the provider
|
|
158
|
-
return {
|
|
159
|
-
fromGroup: response.fromGroup,
|
|
160
|
-
toGroup: response.toGroup,
|
|
161
|
-
unsignedTx: response.unsignedTx,
|
|
162
|
-
txId: response.txId,
|
|
163
|
-
signature: signature
|
|
156
|
+
txId: decoded.unsignedTx.txId,
|
|
157
|
+
signature,
|
|
158
|
+
gasAmount: decoded.unsignedTx.gasAmount,
|
|
159
|
+
gasPrice: (0, api_1.fromApiNumber256)(decoded.unsignedTx.gasPrice)
|
|
164
160
|
};
|
|
165
161
|
}
|
|
166
|
-
async signHexString(params) {
|
|
167
|
-
const signature = await this.signRaw(params.signerAddress, params.hexString);
|
|
168
|
-
return { signature: signature };
|
|
169
|
-
}
|
|
170
162
|
async signMessage(params) {
|
|
171
163
|
const extendedMessage = extendMessage(params.message);
|
|
172
164
|
const messageHash = blakejs_1.default.blake2b(extendedMessage, undefined, 32);
|
|
@@ -174,8 +166,8 @@ class SignerProvider {
|
|
|
174
166
|
return { signature: signature };
|
|
175
167
|
}
|
|
176
168
|
}
|
|
177
|
-
exports.
|
|
178
|
-
class SignerProviderWithMultipleAccounts extends
|
|
169
|
+
exports.SignerProviderSimple = SignerProviderSimple;
|
|
170
|
+
class SignerProviderWithMultipleAccounts extends SignerProviderSimple {
|
|
179
171
|
async getAccount(signerAddress) {
|
|
180
172
|
const accounts = await this.getAccounts();
|
|
181
173
|
const account = accounts.find((a) => a.address === signerAddress);
|
|
@@ -188,20 +180,6 @@ class SignerProviderWithMultipleAccounts extends SignerProvider {
|
|
|
188
180
|
}
|
|
189
181
|
}
|
|
190
182
|
exports.SignerProviderWithMultipleAccounts = SignerProviderWithMultipleAccounts;
|
|
191
|
-
class SignerProviderWrapper extends SignerProvider {
|
|
192
|
-
constructor(signer, nodeProvider) {
|
|
193
|
-
super();
|
|
194
|
-
this.signer = signer;
|
|
195
|
-
this.nodeProvider = nodeProvider;
|
|
196
|
-
}
|
|
197
|
-
getSelectedAccount() {
|
|
198
|
-
return this.signer.getSelectedAccount();
|
|
199
|
-
}
|
|
200
|
-
signRaw(signerAddress, hexString) {
|
|
201
|
-
return this.signer.signRaw(signerAddress, hexString);
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
exports.SignerProviderWrapper = SignerProviderWrapper;
|
|
205
183
|
function verifyHexString(hexString, publicKey, signature) {
|
|
206
184
|
try {
|
|
207
185
|
const key = ec.keyFromPublic(publicKey, 'hex');
|
package/package.json
CHANGED
package/src/api/index.ts
CHANGED
|
@@ -82,6 +82,39 @@ export class NodeProvider implements INodeProvider {
|
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
+
export interface RequestArguments {
|
|
86
|
+
path: string
|
|
87
|
+
method: string
|
|
88
|
+
params?: any
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export class RemoteNodeProvider implements INodeProvider {
|
|
92
|
+
readonly wallets!: NodeApi<string>['wallets']
|
|
93
|
+
readonly infos!: NodeApi<string>['infos']
|
|
94
|
+
readonly blockflow!: NodeApi<string>['blockflow']
|
|
95
|
+
readonly addresses!: NodeApi<string>['addresses']
|
|
96
|
+
readonly transactions!: NodeApi<string>['transactions']
|
|
97
|
+
readonly contracts!: NodeApi<string>['contracts']
|
|
98
|
+
readonly multisig!: NodeApi<string>['multisig']
|
|
99
|
+
readonly utils!: NodeApi<string>['utils']
|
|
100
|
+
readonly miners!: NodeApi<string>['miners']
|
|
101
|
+
readonly events!: NodeApi<string>['events']
|
|
102
|
+
|
|
103
|
+
constructor(request: (request: RequestArguments) => Promise<any>) {
|
|
104
|
+
const fakeNodeProvide = new NodeProvider('https://1.2.3.4:12973')
|
|
105
|
+
Object.assign(this, fakeNodeProvide) // Initialize the class
|
|
106
|
+
|
|
107
|
+
// Update class properties to forward requests
|
|
108
|
+
for (const [path, pathObject] of Object.entries(this)) {
|
|
109
|
+
for (const method of Object.keys(pathObject)) {
|
|
110
|
+
pathObject[`${method}`] = async (params: any): Promise<any> => {
|
|
111
|
+
return request({ path, method, params })
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
85
118
|
// TODO: use proxy provider once the endpoints are refined.
|
|
86
119
|
export class ExplorerProvider extends ExplorerApi<null> {
|
|
87
120
|
constructor(baseUrl: string) {
|
package/src/api/types.ts
CHANGED
|
@@ -19,7 +19,7 @@ along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
19
19
|
import { assertType, bs58, Eq } from '../utils'
|
|
20
20
|
import * as node from './api-alephium'
|
|
21
21
|
|
|
22
|
-
export type Number256 =
|
|
22
|
+
export type Number256 = bigint
|
|
23
23
|
export type Val = Number256 | boolean | string | Val[]
|
|
24
24
|
export type NamedVals = Record<string, Val>
|
|
25
25
|
|
|
@@ -68,12 +68,8 @@ export function toApiNumber256Optional(v?: Val): string | undefined {
|
|
|
68
68
|
return v === undefined ? undefined : toApiNumber256(v)
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
export function fromApiNumber256(n: string):
|
|
72
|
-
|
|
73
|
-
return Number(n)
|
|
74
|
-
} else {
|
|
75
|
-
return BigInt(n)
|
|
76
|
-
}
|
|
71
|
+
export function fromApiNumber256(n: string): bigint {
|
|
72
|
+
return BigInt(n)
|
|
77
73
|
}
|
|
78
74
|
|
|
79
75
|
// TODO: check hex string
|