@alephium/web3 0.5.0-rc.1 → 0.5.0-rc.10
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.LICENSE.txt +2 -0
- package/dist/alephium-web3.min.js.map +1 -1
- package/dist/src/api/api-alephium.d.ts +57 -20
- package/dist/src/api/api-alephium.js +57 -15
- package/dist/src/api/index.d.ts +1 -0
- package/dist/src/api/index.js +1 -0
- package/dist/src/api/types.d.ts +1 -1
- package/dist/src/api/types.js +6 -2
- package/dist/src/constants.d.ts +1 -0
- package/dist/src/constants.js +2 -1
- package/dist/src/contract/contract.d.ts +9 -4
- package/dist/src/contract/contract.js +31 -14
- package/dist/src/signer/signer.d.ts +29 -30
- package/dist/src/signer/signer.js +34 -25
- package/dist/src/signer/tx-builder.d.ts +2 -7
- package/dist/src/signer/tx-builder.js +10 -7
- package/dist/src/signer/types.d.ts +8 -0
- package/dist/src/transaction/sign-verify.d.ts +3 -2
- package/dist/src/transaction/sign-verify.js +4 -14
- package/dist/src/utils/index.d.ts +1 -0
- package/dist/src/utils/index.js +1 -0
- package/dist/src/utils/sign.d.ts +3 -0
- package/dist/src/utils/sign.js +89 -0
- package/dist/src/utils/utils.d.ts +4 -3
- package/dist/src/utils/utils.js +25 -10
- package/package.json +2 -1
- package/src/api/api-alephium.ts +88 -32
- package/src/api/index.ts +2 -0
- package/src/api/types.ts +12 -2
- package/src/constants.ts +1 -0
- package/src/contract/contract.ts +49 -20
- package/src/signer/signer.ts +69 -55
- package/src/signer/tx-builder.ts +13 -7
- package/src/signer/types.ts +10 -2
- package/src/transaction/sign-verify.ts +10 -15
- package/src/utils/index.ts +1 -0
- package/src/utils/sign.ts +66 -0
- package/src/utils/utils.ts +26 -10
|
@@ -145,9 +145,11 @@ export interface BrokerInfo {
|
|
|
145
145
|
};
|
|
146
146
|
}
|
|
147
147
|
export interface BuildDeployContractTx {
|
|
148
|
-
/** @format
|
|
148
|
+
/** @format hex-string */
|
|
149
149
|
fromPublicKey: string;
|
|
150
150
|
/** @format hex-string */
|
|
151
|
+
fromPublicKeyType?: string;
|
|
152
|
+
/** @format hex-string */
|
|
151
153
|
bytecode: string;
|
|
152
154
|
/** @format uint256 */
|
|
153
155
|
initialAttoAlphAmount?: string;
|
|
@@ -177,9 +179,11 @@ export interface BuildDeployContractTxResult {
|
|
|
177
179
|
contractAddress: string;
|
|
178
180
|
}
|
|
179
181
|
export interface BuildExecuteScriptTx {
|
|
180
|
-
/** @format
|
|
182
|
+
/** @format hex-string */
|
|
181
183
|
fromPublicKey: string;
|
|
182
184
|
/** @format hex-string */
|
|
185
|
+
fromPublicKeyType?: string;
|
|
186
|
+
/** @format hex-string */
|
|
183
187
|
bytecode: string;
|
|
184
188
|
/** @format uint256 */
|
|
185
189
|
attoAlphAmount?: string;
|
|
@@ -249,8 +253,10 @@ export interface BuildSweepAddressTransactionsResult {
|
|
|
249
253
|
toGroup: number;
|
|
250
254
|
}
|
|
251
255
|
export interface BuildTransaction {
|
|
252
|
-
/** @format
|
|
256
|
+
/** @format hex-string */
|
|
253
257
|
fromPublicKey: string;
|
|
258
|
+
/** @format hex-string */
|
|
259
|
+
fromPublicKeyType?: string;
|
|
254
260
|
destinations: Destination[];
|
|
255
261
|
utxos?: OutputRef[];
|
|
256
262
|
/** @format gas */
|
|
@@ -519,6 +525,13 @@ export interface InternalServerError {
|
|
|
519
525
|
export interface MemPooled {
|
|
520
526
|
type: string;
|
|
521
527
|
}
|
|
528
|
+
export interface MempoolTransactions {
|
|
529
|
+
/** @format int32 */
|
|
530
|
+
fromGroup: number;
|
|
531
|
+
/** @format int32 */
|
|
532
|
+
toGroup: number;
|
|
533
|
+
transactions: TransactionTemplate[];
|
|
534
|
+
}
|
|
522
535
|
export interface MinerAddresses {
|
|
523
536
|
addresses: string[];
|
|
524
537
|
}
|
|
@@ -756,13 +769,6 @@ export interface Unban {
|
|
|
756
769
|
peers: string[];
|
|
757
770
|
type: string;
|
|
758
771
|
}
|
|
759
|
-
export interface UnconfirmedTransactions {
|
|
760
|
-
/** @format int32 */
|
|
761
|
-
fromGroup: number;
|
|
762
|
-
/** @format int32 */
|
|
763
|
-
toGroup: number;
|
|
764
|
-
unconfirmedTransactions: TransactionTemplate[];
|
|
765
|
-
}
|
|
766
772
|
export interface Unreachable {
|
|
767
773
|
peers: string[];
|
|
768
774
|
type: string;
|
|
@@ -910,7 +916,7 @@ export declare class HttpClient<SecurityDataType = unknown> {
|
|
|
910
916
|
}
|
|
911
917
|
/**
|
|
912
918
|
* @title Alephium API
|
|
913
|
-
* @version 1.7.
|
|
919
|
+
* @version 1.7.1
|
|
914
920
|
* @baseUrl ../
|
|
915
921
|
*/
|
|
916
922
|
export declare class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDataType> {
|
|
@@ -1323,15 +1329,6 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
|
|
|
1323
1329
|
getAddressesAddressGroup: (address: string, params?: RequestParams) => Promise<Group>;
|
|
1324
1330
|
};
|
|
1325
1331
|
transactions: {
|
|
1326
|
-
/**
|
|
1327
|
-
* No description
|
|
1328
|
-
*
|
|
1329
|
-
* @tags Transactions
|
|
1330
|
-
* @name GetTransactionsUnconfirmed
|
|
1331
|
-
* @summary List unconfirmed transactions
|
|
1332
|
-
* @request GET:/transactions/unconfirmed
|
|
1333
|
-
*/
|
|
1334
|
-
getTransactionsUnconfirmed: (params?: RequestParams) => Promise<UnconfirmedTransactions[]>;
|
|
1335
1332
|
/**
|
|
1336
1333
|
* No description
|
|
1337
1334
|
*
|
|
@@ -1394,6 +1391,46 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
|
|
|
1394
1391
|
toGroup?: number;
|
|
1395
1392
|
}, params?: RequestParams) => Promise<Confirmed | MemPooled | TxNotFound>;
|
|
1396
1393
|
};
|
|
1394
|
+
mempool: {
|
|
1395
|
+
/**
|
|
1396
|
+
* No description
|
|
1397
|
+
*
|
|
1398
|
+
* @tags Mempool
|
|
1399
|
+
* @name GetMempoolTransactions
|
|
1400
|
+
* @summary List mempool transactions
|
|
1401
|
+
* @request GET:/mempool/transactions
|
|
1402
|
+
*/
|
|
1403
|
+
getMempoolTransactions: (params?: RequestParams) => Promise<MempoolTransactions[]>;
|
|
1404
|
+
/**
|
|
1405
|
+
* No description
|
|
1406
|
+
*
|
|
1407
|
+
* @tags Mempool
|
|
1408
|
+
* @name DeleteMempoolTransactions
|
|
1409
|
+
* @summary Remove all transactions from mempool
|
|
1410
|
+
* @request DELETE:/mempool/transactions
|
|
1411
|
+
*/
|
|
1412
|
+
deleteMempoolTransactions: (params?: RequestParams) => Promise<void>;
|
|
1413
|
+
/**
|
|
1414
|
+
* No description
|
|
1415
|
+
*
|
|
1416
|
+
* @tags Mempool
|
|
1417
|
+
* @name PutMempoolTransactionsRebroadcast
|
|
1418
|
+
* @summary Rebroadcase a mempool transaction to the network
|
|
1419
|
+
* @request PUT:/mempool/transactions/rebroadcast
|
|
1420
|
+
*/
|
|
1421
|
+
putMempoolTransactionsRebroadcast: (query: {
|
|
1422
|
+
txId: string;
|
|
1423
|
+
}, params?: RequestParams) => Promise<void>;
|
|
1424
|
+
/**
|
|
1425
|
+
* No description
|
|
1426
|
+
*
|
|
1427
|
+
* @tags Mempool
|
|
1428
|
+
* @name PutMempoolTransactionsValidate
|
|
1429
|
+
* @summary Validate all mempool transactions and remove invalid ones
|
|
1430
|
+
* @request PUT:/mempool/transactions/validate
|
|
1431
|
+
*/
|
|
1432
|
+
putMempoolTransactionsValidate: (params?: RequestParams) => Promise<void>;
|
|
1433
|
+
};
|
|
1397
1434
|
contracts: {
|
|
1398
1435
|
/**
|
|
1399
1436
|
* No description
|
|
@@ -149,7 +149,7 @@ class HttpClient {
|
|
|
149
149
|
exports.HttpClient = HttpClient;
|
|
150
150
|
/**
|
|
151
151
|
* @title Alephium API
|
|
152
|
-
* @version 1.7.
|
|
152
|
+
* @version 1.7.1
|
|
153
153
|
* @baseUrl ../
|
|
154
154
|
*/
|
|
155
155
|
class Api extends HttpClient {
|
|
@@ -778,20 +778,6 @@ class Api extends HttpClient {
|
|
|
778
778
|
}).then(utils_1.convertHttpResponse)
|
|
779
779
|
};
|
|
780
780
|
this.transactions = {
|
|
781
|
-
/**
|
|
782
|
-
* No description
|
|
783
|
-
*
|
|
784
|
-
* @tags Transactions
|
|
785
|
-
* @name GetTransactionsUnconfirmed
|
|
786
|
-
* @summary List unconfirmed transactions
|
|
787
|
-
* @request GET:/transactions/unconfirmed
|
|
788
|
-
*/
|
|
789
|
-
getTransactionsUnconfirmed: (params = {}) => this.request({
|
|
790
|
-
path: `/transactions/unconfirmed`,
|
|
791
|
-
method: 'GET',
|
|
792
|
-
format: 'json',
|
|
793
|
-
...params
|
|
794
|
-
}).then(utils_1.convertHttpResponse),
|
|
795
781
|
/**
|
|
796
782
|
* No description
|
|
797
783
|
*
|
|
@@ -887,6 +873,62 @@ class Api extends HttpClient {
|
|
|
887
873
|
...params
|
|
888
874
|
}).then(utils_1.convertHttpResponse)
|
|
889
875
|
};
|
|
876
|
+
this.mempool = {
|
|
877
|
+
/**
|
|
878
|
+
* No description
|
|
879
|
+
*
|
|
880
|
+
* @tags Mempool
|
|
881
|
+
* @name GetMempoolTransactions
|
|
882
|
+
* @summary List mempool transactions
|
|
883
|
+
* @request GET:/mempool/transactions
|
|
884
|
+
*/
|
|
885
|
+
getMempoolTransactions: (params = {}) => this.request({
|
|
886
|
+
path: `/mempool/transactions`,
|
|
887
|
+
method: 'GET',
|
|
888
|
+
format: 'json',
|
|
889
|
+
...params
|
|
890
|
+
}).then(utils_1.convertHttpResponse),
|
|
891
|
+
/**
|
|
892
|
+
* No description
|
|
893
|
+
*
|
|
894
|
+
* @tags Mempool
|
|
895
|
+
* @name DeleteMempoolTransactions
|
|
896
|
+
* @summary Remove all transactions from mempool
|
|
897
|
+
* @request DELETE:/mempool/transactions
|
|
898
|
+
*/
|
|
899
|
+
deleteMempoolTransactions: (params = {}) => this.request({
|
|
900
|
+
path: `/mempool/transactions`,
|
|
901
|
+
method: 'DELETE',
|
|
902
|
+
...params
|
|
903
|
+
}).then(utils_1.convertHttpResponse),
|
|
904
|
+
/**
|
|
905
|
+
* No description
|
|
906
|
+
*
|
|
907
|
+
* @tags Mempool
|
|
908
|
+
* @name PutMempoolTransactionsRebroadcast
|
|
909
|
+
* @summary Rebroadcase a mempool transaction to the network
|
|
910
|
+
* @request PUT:/mempool/transactions/rebroadcast
|
|
911
|
+
*/
|
|
912
|
+
putMempoolTransactionsRebroadcast: (query, params = {}) => this.request({
|
|
913
|
+
path: `/mempool/transactions/rebroadcast`,
|
|
914
|
+
method: 'PUT',
|
|
915
|
+
query: query,
|
|
916
|
+
...params
|
|
917
|
+
}).then(utils_1.convertHttpResponse),
|
|
918
|
+
/**
|
|
919
|
+
* No description
|
|
920
|
+
*
|
|
921
|
+
* @tags Mempool
|
|
922
|
+
* @name PutMempoolTransactionsValidate
|
|
923
|
+
* @summary Validate all mempool transactions and remove invalid ones
|
|
924
|
+
* @request PUT:/mempool/transactions/validate
|
|
925
|
+
*/
|
|
926
|
+
putMempoolTransactionsValidate: (params = {}) => this.request({
|
|
927
|
+
path: `/mempool/transactions/validate`,
|
|
928
|
+
method: 'PUT',
|
|
929
|
+
...params
|
|
930
|
+
}).then(utils_1.convertHttpResponse)
|
|
931
|
+
};
|
|
890
932
|
this.contracts = {
|
|
891
933
|
/**
|
|
892
934
|
* No description
|
package/dist/src/api/index.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export declare class NodeProvider {
|
|
|
11
11
|
readonly blockflow: NodeApi<string>['blockflow'];
|
|
12
12
|
readonly addresses: NodeApi<string>['addresses'];
|
|
13
13
|
readonly transactions: NodeApi<string>['transactions'];
|
|
14
|
+
readonly mempool: NodeApi<string>['mempool'];
|
|
14
15
|
readonly contracts: NodeApi<string>['contracts'];
|
|
15
16
|
readonly multisig: NodeApi<string>['multisig'];
|
|
16
17
|
readonly utils: NodeApi<string>['utils'];
|
package/dist/src/api/index.js
CHANGED
|
@@ -90,6 +90,7 @@ class NodeProvider {
|
|
|
90
90
|
this.blockflow = { ...nodeApi.blockflow };
|
|
91
91
|
this.addresses = { ...nodeApi.addresses };
|
|
92
92
|
this.transactions = { ...nodeApi.transactions };
|
|
93
|
+
this.mempool = { ...nodeApi.mempool };
|
|
93
94
|
this.contracts = { ...nodeApi.contracts };
|
|
94
95
|
this.multisig = { ...nodeApi.multisig };
|
|
95
96
|
this.utils = { ...nodeApi.utils };
|
package/dist/src/api/types.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ 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;
|
|
20
20
|
export declare function toApiVal(v: Val, tpe: string): node.Val;
|
|
21
|
-
export declare function fromApiVals(vals: node.Val[], names: string[], types: string[]): NamedVals;
|
|
21
|
+
export declare function fromApiVals(vals: node.Val[], names: string[], types: string[], optionalNames?: string[], optionalTypes?: string[]): NamedVals;
|
|
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;
|
package/dist/src/api/types.js
CHANGED
|
@@ -165,7 +165,7 @@ function _fromApiVal(vals, valIndex, tpe) {
|
|
|
165
165
|
}
|
|
166
166
|
}
|
|
167
167
|
}
|
|
168
|
-
function fromApiVals(vals, names, types) {
|
|
168
|
+
function fromApiVals(vals, names, types, optionalNames = [], optionalTypes = []) {
|
|
169
169
|
let valIndex = 0;
|
|
170
170
|
const result = {};
|
|
171
171
|
types.forEach((currentType, index) => {
|
|
@@ -174,7 +174,11 @@ function fromApiVals(vals, names, types) {
|
|
|
174
174
|
valIndex = nextIndex;
|
|
175
175
|
result[`${currentName}`] = val;
|
|
176
176
|
});
|
|
177
|
-
|
|
177
|
+
if (valIndex === vals.length) {
|
|
178
|
+
return result;
|
|
179
|
+
}
|
|
180
|
+
const optionalFields = fromApiVals(vals.slice(valIndex), optionalNames, optionalTypes);
|
|
181
|
+
return { ...result, ...optionalFields };
|
|
178
182
|
}
|
|
179
183
|
exports.fromApiVals = fromApiVals;
|
|
180
184
|
function fromApiArray(vals, types) {
|
package/dist/src/constants.d.ts
CHANGED
package/dist/src/constants.js
CHANGED
|
@@ -17,8 +17,9 @@ 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.ONE_ALPH = exports.ALPH_TOKEN_ID = exports.MIN_UTXO_SET_AMOUNT = exports.TOTAL_NUMBER_OF_GROUPS = void 0;
|
|
20
|
+
exports.DUST_AMOUNT = exports.ONE_ALPH = exports.ALPH_TOKEN_ID = exports.MIN_UTXO_SET_AMOUNT = exports.TOTAL_NUMBER_OF_GROUPS = void 0;
|
|
21
21
|
exports.TOTAL_NUMBER_OF_GROUPS = 4;
|
|
22
22
|
exports.MIN_UTXO_SET_AMOUNT = BigInt(1000000000000);
|
|
23
23
|
exports.ALPH_TOKEN_ID = ''.padStart(64, '0');
|
|
24
24
|
exports.ONE_ALPH = 10n ** 18n;
|
|
25
|
+
exports.DUST_AMOUNT = 10n ** 15n;
|
|
@@ -123,9 +123,9 @@ export declare class Contract extends Artifact {
|
|
|
123
123
|
fromApiContractState(state: node.ContractState): ContractState<Fields>;
|
|
124
124
|
static fromApiContractState(state: node.ContractState): ContractState;
|
|
125
125
|
static ContractCreatedEventIndex: number;
|
|
126
|
-
static ContractCreatedEvent:
|
|
126
|
+
static ContractCreatedEvent: SystemEventSig;
|
|
127
127
|
static ContractDestroyedEventIndex: number;
|
|
128
|
-
static ContractDestroyedEvent:
|
|
128
|
+
static ContractDestroyedEvent: SystemEventSig;
|
|
129
129
|
static fromApiEvent(event: node.ContractEventByTxId, codeHash: string | undefined, txId: string): ContractEvent;
|
|
130
130
|
fromApiTestContractResult(methodName: string, result: node.TestContractResult, txId: string): TestContractResult<unknown>;
|
|
131
131
|
txParamsForDeployment<P extends Fields>(signer: SignerProvider, params: DeployContractParams<P>): Promise<SignDeployContractTxParams>;
|
|
@@ -257,11 +257,16 @@ export interface CallContractResult<R> {
|
|
|
257
257
|
txOutputs: Output[];
|
|
258
258
|
events: ContractEvent[];
|
|
259
259
|
}
|
|
260
|
+
export interface SystemEventSig extends EventSig {
|
|
261
|
+
optionalFieldNames?: string[];
|
|
262
|
+
optionalFieldTypes?: string[];
|
|
263
|
+
}
|
|
260
264
|
export declare type ContractCreatedEvent = ContractEvent<{
|
|
261
|
-
address:
|
|
265
|
+
address: Address;
|
|
266
|
+
parentAddress?: Address;
|
|
262
267
|
}>;
|
|
263
268
|
export declare type ContractDestroyedEvent = ContractEvent<{
|
|
264
|
-
address:
|
|
269
|
+
address: Address;
|
|
265
270
|
}>;
|
|
266
271
|
export declare function decodeContractCreatedEvent(event: node.ContractEvent): Omit<ContractCreatedEvent, 'contractAddress'>;
|
|
267
272
|
export declare function decodeContractDestroyedEvent(event: node.ContractEvent): Omit<ContractDestroyedEvent, 'contractAddress'>;
|
|
@@ -579,24 +579,29 @@ class Contract extends Artifact {
|
|
|
579
579
|
return contract.fromApiContractState(state);
|
|
580
580
|
}
|
|
581
581
|
static fromApiEvent(event, codeHash, txId) {
|
|
582
|
-
let
|
|
582
|
+
let fields;
|
|
583
|
+
let name;
|
|
583
584
|
if (event.eventIndex == Contract.ContractCreatedEventIndex) {
|
|
584
|
-
|
|
585
|
+
fields = fromApiSystemEventFields(event.fields, Contract.ContractCreatedEvent);
|
|
586
|
+
name = Contract.ContractCreatedEvent.name;
|
|
585
587
|
}
|
|
586
588
|
else if (event.eventIndex == Contract.ContractDestroyedEventIndex) {
|
|
587
|
-
|
|
589
|
+
fields = fromApiSystemEventFields(event.fields, Contract.ContractDestroyedEvent);
|
|
590
|
+
name = Contract.ContractDestroyedEvent.name;
|
|
588
591
|
}
|
|
589
592
|
else {
|
|
590
593
|
const contract = Project.currentProject.contractByCodeHash(codeHash);
|
|
591
|
-
eventSig = contract.eventsSig[event.eventIndex];
|
|
594
|
+
const eventSig = contract.eventsSig[event.eventIndex];
|
|
595
|
+
fields = fromApiEventFields(event.fields, eventSig);
|
|
596
|
+
name = eventSig.name;
|
|
592
597
|
}
|
|
593
598
|
return {
|
|
594
599
|
txId: txId,
|
|
595
600
|
blockHash: event.blockHash,
|
|
596
601
|
contractAddress: event.contractAddress,
|
|
597
|
-
name:
|
|
602
|
+
name: name,
|
|
598
603
|
eventIndex: event.eventIndex,
|
|
599
|
-
fields:
|
|
604
|
+
fields: fields
|
|
600
605
|
};
|
|
601
606
|
}
|
|
602
607
|
fromApiTestContractResult(methodName, result, txId) {
|
|
@@ -620,8 +625,10 @@ class Contract extends Artifact {
|
|
|
620
625
|
}
|
|
621
626
|
async txParamsForDeployment(signer, params) {
|
|
622
627
|
const bytecode = this.buildByteCodeToDeploy(params.initialFields ?? {});
|
|
628
|
+
const selectedAccount = await signer.getSelectedAccount();
|
|
623
629
|
const signerParams = {
|
|
624
|
-
signerAddress:
|
|
630
|
+
signerAddress: selectedAccount.address,
|
|
631
|
+
signerKeyType: selectedAccount.keyType,
|
|
625
632
|
bytecode: bytecode,
|
|
626
633
|
initialAttoAlphAmount: params?.initialAttoAlphAmount,
|
|
627
634
|
issueTokenAmount: params?.issueTokenAmount,
|
|
@@ -678,7 +685,9 @@ Contract.ContractCreatedEventIndex = -1;
|
|
|
678
685
|
Contract.ContractCreatedEvent = {
|
|
679
686
|
name: 'ContractCreated',
|
|
680
687
|
fieldNames: ['address'],
|
|
681
|
-
fieldTypes: ['Address']
|
|
688
|
+
fieldTypes: ['Address'],
|
|
689
|
+
optionalFieldNames: ['parentAddress'],
|
|
690
|
+
optionalFieldTypes: ['Address']
|
|
682
691
|
};
|
|
683
692
|
Contract.ContractDestroyedEventIndex = -2;
|
|
684
693
|
Contract.ContractDestroyedEvent = {
|
|
@@ -723,8 +732,10 @@ class Script extends Artifact {
|
|
|
723
732
|
return JSON.stringify(object, null, 2);
|
|
724
733
|
}
|
|
725
734
|
async txParamsForExecution(signer, params) {
|
|
735
|
+
const selectedAccount = await signer.getSelectedAccount();
|
|
726
736
|
const signerParams = {
|
|
727
|
-
signerAddress:
|
|
737
|
+
signerAddress: selectedAccount.address,
|
|
738
|
+
signerKeyType: selectedAccount.keyType,
|
|
728
739
|
bytecode: this.buildByteCodeToDeploy(params.initialFields ?? {}),
|
|
729
740
|
attoAlphAmount: params.attoAlphAmount,
|
|
730
741
|
tokens: params.tokens,
|
|
@@ -758,6 +769,9 @@ function fromApiFields(immFields, mutFields, fieldsSig) {
|
|
|
758
769
|
function fromApiEventFields(vals, eventSig) {
|
|
759
770
|
return (0, api_1.fromApiVals)(vals, eventSig.fieldNames, eventSig.fieldTypes);
|
|
760
771
|
}
|
|
772
|
+
function fromApiSystemEventFields(vals, systemEventSig) {
|
|
773
|
+
return (0, api_1.fromApiVals)(vals, systemEventSig.fieldNames, systemEventSig.fieldTypes, systemEventSig.optionalFieldNames ?? [], systemEventSig.optionalFieldTypes ?? []);
|
|
774
|
+
}
|
|
761
775
|
function toApiAsset(asset) {
|
|
762
776
|
return {
|
|
763
777
|
attoAlphAmount: (0, api_1.toApiNumber256)(asset.alphAmount),
|
|
@@ -872,25 +886,28 @@ class ContractFactory {
|
|
|
872
886
|
}
|
|
873
887
|
}
|
|
874
888
|
exports.ContractFactory = ContractFactory;
|
|
875
|
-
function
|
|
889
|
+
function decodeSystemEvent(event, systemEventSig, eventIndex) {
|
|
876
890
|
if (event.eventIndex !== eventIndex) {
|
|
877
891
|
throw new Error(`Invalid event index: ${event.eventIndex}, expected: ${eventIndex}`);
|
|
878
892
|
}
|
|
879
|
-
return (
|
|
893
|
+
return fromApiSystemEventFields(event.fields, systemEventSig);
|
|
880
894
|
}
|
|
881
895
|
function decodeContractCreatedEvent(event) {
|
|
882
|
-
const fields =
|
|
896
|
+
const fields = decodeSystemEvent(event, Contract.ContractCreatedEvent, Contract.ContractCreatedEventIndex);
|
|
883
897
|
return {
|
|
884
898
|
blockHash: event.blockHash,
|
|
885
899
|
txId: event.txId,
|
|
886
900
|
eventIndex: event.eventIndex,
|
|
887
901
|
name: Contract.ContractCreatedEvent.name,
|
|
888
|
-
fields: {
|
|
902
|
+
fields: {
|
|
903
|
+
address: fields['address'],
|
|
904
|
+
parentAddress: fields['parentAddress'] === undefined ? undefined : fields['parentAddress']
|
|
905
|
+
}
|
|
889
906
|
};
|
|
890
907
|
}
|
|
891
908
|
exports.decodeContractCreatedEvent = decodeContractCreatedEvent;
|
|
892
909
|
function decodeContractDestroyedEvent(event) {
|
|
893
|
-
const fields =
|
|
910
|
+
const fields = decodeSystemEvent(event, Contract.ContractDestroyedEvent, Contract.ContractDestroyedEventIndex);
|
|
894
911
|
return {
|
|
895
912
|
blockHash: event.blockHash,
|
|
896
913
|
txId: event.txId,
|
|
@@ -1,32 +1,32 @@
|
|
|
1
1
|
import { ExplorerProvider, NodeProvider } from '../api';
|
|
2
2
|
import { node } from '../api';
|
|
3
|
-
import { Account,
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
get
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
3
|
+
import { Account, EnableOptionsBase, Destination, SignDeployContractTxParams, SignDeployContractTxResult, SignExecuteScriptTxParams, SignExecuteScriptTxResult, SignMessageParams, SignMessageResult, SignTransferTxParams, SignTransferTxResult, SignUnsignedTxParams, SignUnsignedTxResult, SubmissionResult, SubmitTransactionParams, ExtSignTransferTxParams, ExtSignDeployContractTxParams, ExtSignExecuteScriptTxParams, ExtSignUnsignedTxParams, ExtSignMessageParams, KeyType } from './types';
|
|
4
|
+
export declare abstract class SignerProvider {
|
|
5
|
+
abstract get nodeProvider(): NodeProvider | undefined;
|
|
6
|
+
abstract get explorerProvider(): ExplorerProvider | undefined;
|
|
7
|
+
protected abstract unsafeGetSelectedAccount(): Promise<Account>;
|
|
8
|
+
getSelectedAccount(): Promise<Account>;
|
|
9
|
+
static validateAccount(account: Account): void;
|
|
10
|
+
abstract signAndSubmitTransferTx(params: SignTransferTxParams): Promise<SignTransferTxResult>;
|
|
11
|
+
abstract signAndSubmitDeployContractTx(params: SignDeployContractTxParams): Promise<SignDeployContractTxResult>;
|
|
12
|
+
abstract signAndSubmitExecuteScriptTx(params: SignExecuteScriptTxParams): Promise<SignExecuteScriptTxResult>;
|
|
13
|
+
abstract signAndSubmitUnsignedTx(params: SignUnsignedTxParams): Promise<SignUnsignedTxResult>;
|
|
14
|
+
abstract signUnsignedTx(params: SignUnsignedTxParams): Promise<SignUnsignedTxResult>;
|
|
15
|
+
abstract signMessage(params: SignMessageParams): Promise<SignMessageResult>;
|
|
15
16
|
}
|
|
16
|
-
export
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
17
|
+
export declare abstract class InteractiveSignerProvider<EnableOptions extends EnableOptionsBase = EnableOptionsBase> extends SignerProvider {
|
|
18
|
+
protected abstract unsafeEnable(opt?: EnableOptions): Promise<Account>;
|
|
19
|
+
enable(opt?: EnableOptions): Promise<Account>;
|
|
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>;
|
|
25
27
|
}
|
|
26
|
-
export declare abstract class SignerProviderSimple extends
|
|
27
|
-
abstract get
|
|
28
|
-
abstract getSelectedAccount(): Promise<Account>;
|
|
29
|
-
getSelectedAddress(): Promise<Address>;
|
|
28
|
+
export declare abstract class SignerProviderSimple extends SignerProvider {
|
|
29
|
+
abstract get nodeProvider(): NodeProvider;
|
|
30
30
|
submitTransaction(params: SubmitTransactionParams): Promise<SubmissionResult>;
|
|
31
31
|
signAndSubmitTransferTx(params: SignTransferTxParams): Promise<SignTransferTxResult>;
|
|
32
32
|
signAndSubmitDeployContractTx(params: SignDeployContractTxParams): Promise<SignDeployContractTxResult>;
|
|
@@ -45,7 +45,7 @@ export declare abstract class SignerProviderSimple extends TransactionBuilder im
|
|
|
45
45
|
abstract signRaw(signerAddress: string, hexString: string): Promise<string>;
|
|
46
46
|
}
|
|
47
47
|
export declare abstract class SignerProviderWithMultipleAccounts extends SignerProviderSimple {
|
|
48
|
-
abstract
|
|
48
|
+
abstract setSelectedAccount(address: string): Promise<void>;
|
|
49
49
|
abstract getAccounts(): Promise<Account[]>;
|
|
50
50
|
getAccount(signerAddress: string): Promise<Account>;
|
|
51
51
|
getPublicKey(signerAddress: string): Promise<string>;
|
|
@@ -53,13 +53,12 @@ export declare abstract class SignerProviderWithMultipleAccounts extends SignerP
|
|
|
53
53
|
export declare abstract class SignerProviderWithCachedAccounts<T extends Account> extends SignerProviderWithMultipleAccounts {
|
|
54
54
|
private _selectedAccount;
|
|
55
55
|
protected readonly _accounts: Map<string, T>;
|
|
56
|
-
|
|
57
|
-
|
|
56
|
+
protected unsafeGetSelectedAccount(): Promise<T>;
|
|
57
|
+
setSelectedAccount(address: string): Promise<void>;
|
|
58
58
|
getAccounts(): Promise<T[]>;
|
|
59
59
|
getAccount(address: string): Promise<T>;
|
|
60
60
|
}
|
|
61
|
-
export declare function
|
|
62
|
-
export declare function verifySignedMessage(message: string, publicKey: string, signature: string): boolean;
|
|
61
|
+
export declare function verifySignedMessage(message: string, publicKey: string, signature: string, keyType: KeyType): boolean;
|
|
63
62
|
export declare function toApiDestination(data: Destination): node.Destination;
|
|
64
63
|
export declare function toApiDestinations(data: Destination[]): node.Destination[];
|
|
65
64
|
export declare function fromApiDestination(data: node.Destination): Destination;
|
|
@@ -43,18 +43,37 @@ 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.
|
|
47
|
-
const elliptic_1 = require("elliptic");
|
|
46
|
+
exports.fromApiDestination = exports.toApiDestinations = exports.toApiDestination = exports.verifySignedMessage = exports.SignerProviderWithCachedAccounts = exports.SignerProviderWithMultipleAccounts = exports.SignerProviderSimple = exports.InteractiveSignerProvider = exports.SignerProvider = void 0;
|
|
48
47
|
const api_1 = require("../api");
|
|
49
48
|
const utils = __importStar(require("../utils"));
|
|
50
49
|
const blakejs_1 = __importDefault(require("blakejs"));
|
|
51
50
|
const tx_builder_1 = require("./tx-builder");
|
|
52
|
-
const
|
|
53
|
-
class
|
|
54
|
-
async
|
|
55
|
-
const account = await this.
|
|
56
|
-
|
|
51
|
+
const utils_1 = require("../utils");
|
|
52
|
+
class SignerProvider {
|
|
53
|
+
async getSelectedAccount() {
|
|
54
|
+
const account = await this.unsafeGetSelectedAccount();
|
|
55
|
+
SignerProvider.validateAccount(account);
|
|
56
|
+
return account;
|
|
57
|
+
}
|
|
58
|
+
static validateAccount(account) {
|
|
59
|
+
const derivedAddress = (0, utils_1.addressFromPublicKey)(account.publicKey, account.keyType);
|
|
60
|
+
const derivedGroup = (0, utils_1.groupOfAddress)(derivedAddress);
|
|
61
|
+
if (derivedAddress !== account.address || derivedGroup !== account.group) {
|
|
62
|
+
throw Error(`Invalid accounot data: ${JSON.stringify(account)}`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
exports.SignerProvider = SignerProvider;
|
|
67
|
+
// Abstraction for interactive signer (e.g. WalletConnect instance, Extension wallet object)
|
|
68
|
+
class InteractiveSignerProvider extends SignerProvider {
|
|
69
|
+
async enable(opt) {
|
|
70
|
+
const account = await this.unsafeEnable(opt);
|
|
71
|
+
SignerProvider.validateAccount(account);
|
|
72
|
+
return account;
|
|
57
73
|
}
|
|
74
|
+
}
|
|
75
|
+
exports.InteractiveSignerProvider = InteractiveSignerProvider;
|
|
76
|
+
class SignerProviderSimple extends SignerProvider {
|
|
58
77
|
async submitTransaction(params) {
|
|
59
78
|
const data = { unsignedTx: params.unsignedTx, signature: params.signature };
|
|
60
79
|
return this.nodeProvider.transactions.postTransactionsSubmit(data);
|
|
@@ -90,7 +109,7 @@ class SignerProviderSimple extends tx_builder_1.TransactionBuilder {
|
|
|
90
109
|
return { signature, ...response };
|
|
91
110
|
}
|
|
92
111
|
async buildTransferTx(params) {
|
|
93
|
-
return
|
|
112
|
+
return tx_builder_1.TransactionBuilder.from(this.nodeProvider).buildTransferTx(params, await this.getPublicKey(params.signerAddress));
|
|
94
113
|
}
|
|
95
114
|
async signDeployContractTx(params) {
|
|
96
115
|
const response = await this.buildDeployContractTx(params);
|
|
@@ -98,7 +117,7 @@ class SignerProviderSimple extends tx_builder_1.TransactionBuilder {
|
|
|
98
117
|
return { signature, ...response };
|
|
99
118
|
}
|
|
100
119
|
async buildDeployContractTx(params) {
|
|
101
|
-
return
|
|
120
|
+
return tx_builder_1.TransactionBuilder.from(this.nodeProvider).buildDeployContractTx(params, await this.getPublicKey(params.signerAddress));
|
|
102
121
|
}
|
|
103
122
|
async signExecuteScriptTx(params) {
|
|
104
123
|
const response = await this.buildExecuteScriptTx(params);
|
|
@@ -106,12 +125,12 @@ class SignerProviderSimple extends tx_builder_1.TransactionBuilder {
|
|
|
106
125
|
return { signature, ...response };
|
|
107
126
|
}
|
|
108
127
|
async buildExecuteScriptTx(params) {
|
|
109
|
-
return
|
|
128
|
+
return tx_builder_1.TransactionBuilder.from(this.nodeProvider).buildExecuteScriptTx(params, await this.getPublicKey(params.signerAddress));
|
|
110
129
|
}
|
|
111
130
|
// in general, wallet should show the decoded information to user for confirmation
|
|
112
131
|
// please overwrite this function for real wallet
|
|
113
132
|
async signUnsignedTx(params) {
|
|
114
|
-
const response = await this.buildUnsignedTx(params);
|
|
133
|
+
const response = await tx_builder_1.TransactionBuilder.from(this.nodeProvider).buildUnsignedTx(params);
|
|
115
134
|
const signature = await this.signRaw(params.signerAddress, response.txId);
|
|
116
135
|
return { signature, ...response };
|
|
117
136
|
}
|
|
@@ -146,7 +165,7 @@ class SignerProviderWithCachedAccounts extends SignerProviderWithMultipleAccount
|
|
|
146
165
|
this._selectedAccount = undefined;
|
|
147
166
|
this._accounts = new Map();
|
|
148
167
|
}
|
|
149
|
-
|
|
168
|
+
unsafeGetSelectedAccount() {
|
|
150
169
|
if (this._selectedAccount === undefined) {
|
|
151
170
|
throw Error('No account is selected yet');
|
|
152
171
|
}
|
|
@@ -154,7 +173,7 @@ class SignerProviderWithCachedAccounts extends SignerProviderWithMultipleAccount
|
|
|
154
173
|
return Promise.resolve(this._selectedAccount);
|
|
155
174
|
}
|
|
156
175
|
}
|
|
157
|
-
|
|
176
|
+
setSelectedAccount(address) {
|
|
158
177
|
const accountOpt = this._accounts.get(address);
|
|
159
178
|
if (accountOpt === undefined) {
|
|
160
179
|
throw Error('The address is not in the accounts');
|
|
@@ -176,23 +195,13 @@ class SignerProviderWithCachedAccounts extends SignerProviderWithMultipleAccount
|
|
|
176
195
|
}
|
|
177
196
|
}
|
|
178
197
|
exports.SignerProviderWithCachedAccounts = SignerProviderWithCachedAccounts;
|
|
179
|
-
function verifyHexString(hexString, publicKey, signature) {
|
|
180
|
-
try {
|
|
181
|
-
const key = ec.keyFromPublic(publicKey, 'hex');
|
|
182
|
-
return key.verify(hexString, utils.signatureDecode(ec, signature));
|
|
183
|
-
}
|
|
184
|
-
catch (error) {
|
|
185
|
-
return false;
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
exports.verifyHexString = verifyHexString;
|
|
189
198
|
function extendMessage(message) {
|
|
190
199
|
return 'Alephium Signed Message: ' + message;
|
|
191
200
|
}
|
|
192
|
-
function verifySignedMessage(message, publicKey, signature) {
|
|
201
|
+
function verifySignedMessage(message, publicKey, signature, keyType) {
|
|
193
202
|
const extendedMessage = extendMessage(message);
|
|
194
203
|
const messageHash = blakejs_1.default.blake2b(extendedMessage, undefined, 32);
|
|
195
|
-
return
|
|
204
|
+
return utils.verifySignature(utils.binToHex(messageHash), publicKey, signature, keyType);
|
|
196
205
|
}
|
|
197
206
|
exports.verifySignedMessage = verifySignedMessage;
|
|
198
207
|
function toApiDestination(data) {
|