@alephium/web3 0.2.0-rc.33 → 0.2.0-rc.34

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.
@@ -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
  }
@@ -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) {
@@ -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
- paramsForDeployment(params: BuildDeployContractTx): Promise<SignDeployContractTxParams>;
125
- transactionForDeployment(signer: SignerProvider, params: Omit<BuildDeployContractTx, 'signerAddress'>): Promise<DeployContractTransaction>;
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
- paramsForDeployment(params: BuildExecuteScriptTx): Promise<SignExecuteScriptTxParams>;
138
- transactionForDeployment(signer: SignerProvider, params: Omit<BuildExecuteScriptTx, 'signerAddress'>): Promise<BuildScriptTxResult>;
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 {
@@ -582,10 +582,10 @@ class Contract extends Artifact {
582
582
  debugMessages: result.debugMessages
583
583
  };
584
584
  }
585
- async paramsForDeployment(params) {
585
+ async txParamsForDeployment(signer, params) {
586
586
  const bytecode = this.buildByteCodeToDeploy(params.initialFields ? params.initialFields : {});
587
587
  const signerParams = {
588
- signerAddress: params.signerAddress,
588
+ signerAddress: (await signer.getSelectedAccount()).address,
589
589
  bytecode: bytecode,
590
590
  initialAttoAlphAmount: extractOptionalNumber256(params.initialAttoAlphAmount),
591
591
  issueTokenAmount: extractOptionalNumber256(params.issueTokenAmount),
@@ -595,13 +595,9 @@ class Contract extends Artifact {
595
595
  };
596
596
  return signerParams;
597
597
  }
598
- async transactionForDeployment(signer, params) {
599
- const signerParams = await this.paramsForDeployment({
600
- ...params,
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,9 +648,9 @@ class Script extends Artifact {
652
648
  };
653
649
  return JSON.stringify(object, null, 2);
654
650
  }
655
- async paramsForDeployment(params) {
651
+ async txParamsForExecution(signer, params) {
656
652
  const signerParams = {
657
- signerAddress: params.signerAddress,
653
+ signerAddress: (await signer.getSelectedAccount()).address,
658
654
  bytecode: this.buildByteCodeToDeploy(params.initialFields ? params.initialFields : {}),
659
655
  attoAlphAmount: extractOptionalNumber256(params.attoAlphAmount),
660
656
  tokens: (0, api_1.toApiTokens)(params.tokens),
@@ -663,12 +659,9 @@ class Script extends Artifact {
663
659
  };
664
660
  return signerParams;
665
661
  }
666
- async transactionForDeployment(signer, params) {
667
- const signerParams = await this.paramsForDeployment({
668
- ...params,
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);
@@ -758,8 +751,5 @@ function fromApiOutput(output) {
758
751
  throw new Error(`Unknown output type: ${output}`);
759
752
  }
760
753
  }
761
- function fromApiDeployContractUnsignedTx(result) {
762
- return { ...result, contractId: (0, utils_1.binToHex)((0, utils_1.contractIdFromAddress)(result.contractAddress)) };
763
- }
764
754
  (0, utils_1.assertType)();
765
755
  (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,6 +42,8 @@ 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;
@@ -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
- export interface SignHexStringParams {
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 declare abstract class SignerProvider {
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(unsignedTx: string, signature: string): Promise<SubmissionResult>;
98
- signAndSubmitTransferTx(params: SignTransferTxParams): Promise<SubmissionResult>;
99
- signAndSubmitDeployContractTx(params: SignDeployContractTxParams): Promise<SubmissionResult>;
100
- signAndSubmitExecuteScriptTx(params: SignExecuteScriptTxParams): Promise<SubmissionResult>;
101
- signAndSubmitUnsignedTx(params: SignUnsignedTxParams): Promise<SubmissionResult>;
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 SignerProvider {
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.SignerProviderWrapper = exports.SignerProviderWithMultipleAccounts = exports.SignerProvider = void 0;
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
- (0, utils_1.assertType)();
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(unsignedTx, signature) {
73
- const params = { unsignedTx: unsignedTx, signature: signature };
74
- return this.getNodeProvider().transactions.postTransactionsSubmit(params);
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
- return this.submitTransaction(signResult.unsignedTx, signResult.signature);
75
+ await this.submitTransaction(signResult);
76
+ return signResult;
79
77
  }
80
78
  async signAndSubmitDeployContractTx(params) {
81
79
  const signResult = await this.signDeployContractTx(params);
82
- return this.submitTransaction(signResult.unsignedTx, signResult.signature);
80
+ await this.submitTransaction(signResult);
81
+ return signResult;
83
82
  }
84
83
  async signAndSubmitExecuteScriptTx(params) {
85
84
  const signResult = await this.signExecuteScriptTx(params);
86
- return this.submitTransaction(signResult.unsignedTx, signResult.signature);
85
+ await this.submitTransaction(signResult);
86
+ return signResult;
87
87
  }
88
88
  async signAndSubmitUnsignedTx(params) {
89
89
  const signResult = await this.signUnsignedTx(params);
90
- return this.submitTransaction(signResult.unsignedTx, signResult.signature);
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
- return this.handleSign({ signerAddress: params.signerAddress, ...response });
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 result = await this.handleSign({ signerAddress: params.signerAddress, ...response });
118
+ const signature = await this.signRaw(params.signerAddress, response.txId);
117
119
  const contractId = utils.binToHex(utils.contractIdFromAddress(response.contractAddress));
118
- return { ...result, contractId: contractId, contractAddress: response.contractAddress };
120
+ return { ...response, contractId, signature, gasPrice: (0, api_1.fromApiNumber256)(response.gasPrice) };
119
121
  }
120
122
  async buildContractCreationTx(params) {
121
123
  const data = {
@@ -129,7 +131,8 @@ class SignerProvider {
129
131
  }
130
132
  async signExecuteScriptTx(params) {
131
133
  const response = await this.buildScriptTx(params);
132
- return this.handleSign({ signerAddress: params.signerAddress, ...response });
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 = {
@@ -143,30 +146,17 @@ class SignerProvider {
143
146
  async signUnsignedTx(params) {
144
147
  const data = { unsignedTx: params.unsignedTx };
145
148
  const decoded = await this.getNodeProvider().transactions.postTransactionsDecodeUnsignedTx(data);
146
- return this.handleSign({
149
+ const signature = await this.signRaw(params.signerAddress, decoded.unsignedTx.txId);
150
+ return {
147
151
  fromGroup: decoded.fromGroup,
148
152
  toGroup: decoded.toGroup,
149
- signerAddress: params.signerAddress,
150
153
  unsignedTx: params.unsignedTx,
151
- txId: decoded.unsignedTx.txId
152
- });
153
- }
154
- async handleSign(response) {
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
154
+ txId: decoded.unsignedTx.txId,
155
+ signature,
156
+ gasAmount: decoded.unsignedTx.gasAmount,
157
+ gasPrice: (0, api_1.fromApiNumber256)(decoded.unsignedTx.gasPrice)
164
158
  };
165
159
  }
166
- async signHexString(params) {
167
- const signature = await this.signRaw(params.signerAddress, params.hexString);
168
- return { signature: signature };
169
- }
170
160
  async signMessage(params) {
171
161
  const extendedMessage = extendMessage(params.message);
172
162
  const messageHash = blakejs_1.default.blake2b(extendedMessage, undefined, 32);
@@ -174,8 +164,8 @@ class SignerProvider {
174
164
  return { signature: signature };
175
165
  }
176
166
  }
177
- exports.SignerProvider = SignerProvider;
178
- class SignerProviderWithMultipleAccounts extends SignerProvider {
167
+ exports.SignerProviderSimple = SignerProviderSimple;
168
+ class SignerProviderWithMultipleAccounts extends SignerProviderSimple {
179
169
  async getAccount(signerAddress) {
180
170
  const accounts = await this.getAccounts();
181
171
  const account = accounts.find((a) => a.address === signerAddress);
@@ -188,20 +178,6 @@ class SignerProviderWithMultipleAccounts extends SignerProvider {
188
178
  }
189
179
  }
190
180
  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
181
  function verifyHexString(hexString, publicKey, signature) {
206
182
  try {
207
183
  const key = ec.keyFromPublic(publicKey, 'hex');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alephium/web3",
3
- "version": "0.2.0-rc.33",
3
+ "version": "0.2.0-rc.34",
4
4
  "description": "A JS/TS library to interact with the Alephium platform",
5
5
  "license": "GPL",
6
6
  "main": "dist/src/index.js",
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) {
@@ -808,10 +808,13 @@ export class Contract extends Artifact {
808
808
  }
809
809
  }
810
810
 
811
- async paramsForDeployment(params: BuildDeployContractTx): Promise<SignDeployContractTxParams> {
811
+ async txParamsForDeployment(
812
+ signer: SignerProvider,
813
+ params: Omit<BuildDeployContractTx, 'signerAddress'>
814
+ ): Promise<SignDeployContractTxParams> {
812
815
  const bytecode = this.buildByteCodeToDeploy(params.initialFields ? params.initialFields : {})
813
816
  const signerParams: SignDeployContractTxParams = {
814
- signerAddress: params.signerAddress,
817
+ signerAddress: (await signer.getSelectedAccount()).address,
815
818
  bytecode: bytecode,
816
819
  initialAttoAlphAmount: extractOptionalNumber256(params.initialAttoAlphAmount),
817
820
  issueTokenAmount: extractOptionalNumber256(params.issueTokenAmount),
@@ -822,16 +825,12 @@ export class Contract extends Artifact {
822
825
  return signerParams
823
826
  }
824
827
 
825
- async transactionForDeployment(
828
+ async deploy(
826
829
  signer: SignerProvider,
827
830
  params: Omit<BuildDeployContractTx, 'signerAddress'>
828
831
  ): Promise<DeployContractTransaction> {
829
- const signerParams = await this.paramsForDeployment({
830
- ...params,
831
- signerAddress: (await signer.getSelectedAccount()).address
832
- })
833
- const response = await signer.buildContractCreationTx(signerParams)
834
- return fromApiDeployContractUnsignedTx(response)
832
+ const signerParams = await this.txParamsForDeployment(signer, params)
833
+ return signer.signAndSubmitDeployContractTx(signerParams)
835
834
  }
836
835
 
837
836
  buildByteCodeToDeploy(initialFields: Fields): string {
@@ -896,9 +895,12 @@ export class Script extends Artifact {
896
895
  return JSON.stringify(object, null, 2)
897
896
  }
898
897
 
899
- async paramsForDeployment(params: BuildExecuteScriptTx): Promise<SignExecuteScriptTxParams> {
898
+ async txParamsForExecution(
899
+ signer: SignerProvider,
900
+ params: Omit<BuildExecuteScriptTx, 'signerAddress'>
901
+ ): Promise<SignExecuteScriptTxParams> {
900
902
  const signerParams: SignExecuteScriptTxParams = {
901
- signerAddress: params.signerAddress,
903
+ signerAddress: (await signer.getSelectedAccount()).address,
902
904
  bytecode: this.buildByteCodeToDeploy(params.initialFields ? params.initialFields : {}),
903
905
  attoAlphAmount: extractOptionalNumber256(params.attoAlphAmount),
904
906
  tokens: toApiTokens(params.tokens),
@@ -908,15 +910,12 @@ export class Script extends Artifact {
908
910
  return signerParams
909
911
  }
910
912
 
911
- async transactionForDeployment(
913
+ async execute(
912
914
  signer: SignerProvider,
913
915
  params: Omit<BuildExecuteScriptTx, 'signerAddress'>
914
916
  ): Promise<BuildScriptTxResult> {
915
- const signerParams = await this.paramsForDeployment({
916
- ...params,
917
- signerAddress: (await signer.getSelectedAccount()).address
918
- })
919
- return await signer.buildScriptTx(signerParams)
917
+ const signerParams = await this.txParamsForExecution(signer, params)
918
+ return await signer.signAndSubmitExecuteScriptTx(signerParams)
920
919
  }
921
920
 
922
921
  buildByteCodeToDeploy(initialFields: Fields): string {
@@ -1098,10 +1097,6 @@ export interface DeployContractTransaction {
1098
1097
  contractId: string
1099
1098
  }
1100
1099
 
1101
- function fromApiDeployContractUnsignedTx(result: node.BuildDeployContractTxResult): DeployContractTransaction {
1102
- return { ...result, contractId: binToHex(contractIdFromAddress(result.contractAddress)) }
1103
- }
1104
-
1105
1100
  type BuildTxParams<T> = Omit<T, 'bytecode'> & { initialFields?: Val[] }
1106
1101
 
1107
1102
  export interface BuildDeployContractTx {