@alephium/web3 0.12.1 → 0.12.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/alephium-web3.min.js +1 -1
- package/dist/alephium-web3.min.js.map +1 -1
- package/dist/src/api/api-alephium.d.ts +1 -1
- package/dist/src/api/api-alephium.js +1 -1
- package/dist/src/api/api-explorer.d.ts +5 -5
- package/dist/src/api/api-explorer.js +6 -6
- package/dist/src/api/utils.d.ts +0 -6
- package/dist/src/api/utils.js +1 -10
- package/dist/src/contract/contract.js +4 -4
- package/dist/src/utils/index.d.ts +1 -0
- package/dist/src/utils/index.js +1 -0
- package/dist/src/utils/webcrypto.d.ts +4 -0
- package/dist/src/utils/webcrypto.js +42 -0
- package/package.json +5 -5
- package/src/api/api-alephium.ts +1 -1
- package/src/api/api-explorer.ts +7 -7
- package/src/api/utils.ts +0 -11
- package/src/contract/contract.ts +4 -2
- package/src/utils/index.ts +1 -0
- package/src/utils/webcrypto.ts +42 -0
|
@@ -938,7 +938,7 @@ export declare class HttpClient<SecurityDataType = unknown> {
|
|
|
938
938
|
}
|
|
939
939
|
/**
|
|
940
940
|
* @title Alephium API
|
|
941
|
-
* @version 2.3.
|
|
941
|
+
* @version 2.3.3
|
|
942
942
|
* @baseUrl ../
|
|
943
943
|
*/
|
|
944
944
|
export declare class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDataType> {
|
|
@@ -669,7 +669,7 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
|
|
|
669
669
|
* @name GetInfosSupplyTotalAlph
|
|
670
670
|
* @request GET:/infos/supply/total-alph
|
|
671
671
|
*/
|
|
672
|
-
getInfosSupplyTotalAlph: (params?: RequestParams) => Promise<
|
|
672
|
+
getInfosSupplyTotalAlph: (params?: RequestParams) => Promise<number>;
|
|
673
673
|
/**
|
|
674
674
|
* @description Get the ALPH circulating supply
|
|
675
675
|
*
|
|
@@ -677,7 +677,7 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
|
|
|
677
677
|
* @name GetInfosSupplyCirculatingAlph
|
|
678
678
|
* @request GET:/infos/supply/circulating-alph
|
|
679
679
|
*/
|
|
680
|
-
getInfosSupplyCirculatingAlph: (params?: RequestParams) => Promise<
|
|
680
|
+
getInfosSupplyCirculatingAlph: (params?: RequestParams) => Promise<number>;
|
|
681
681
|
/**
|
|
682
682
|
* @description Get the ALPH reserved supply
|
|
683
683
|
*
|
|
@@ -685,7 +685,7 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
|
|
|
685
685
|
* @name GetInfosSupplyReservedAlph
|
|
686
686
|
* @request GET:/infos/supply/reserved-alph
|
|
687
687
|
*/
|
|
688
|
-
getInfosSupplyReservedAlph: (params?: RequestParams) => Promise<
|
|
688
|
+
getInfosSupplyReservedAlph: (params?: RequestParams) => Promise<number>;
|
|
689
689
|
/**
|
|
690
690
|
* @description Get the ALPH locked supply
|
|
691
691
|
*
|
|
@@ -693,7 +693,7 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
|
|
|
693
693
|
* @name GetInfosSupplyLockedAlph
|
|
694
694
|
* @request GET:/infos/supply/locked-alph
|
|
695
695
|
*/
|
|
696
|
-
getInfosSupplyLockedAlph: (params?: RequestParams) => Promise<
|
|
696
|
+
getInfosSupplyLockedAlph: (params?: RequestParams) => Promise<number>;
|
|
697
697
|
/**
|
|
698
698
|
* @description Get the total number of transactions
|
|
699
699
|
*
|
|
@@ -701,7 +701,7 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
|
|
|
701
701
|
* @name GetInfosTotalTransactions
|
|
702
702
|
* @request GET:/infos/total-transactions
|
|
703
703
|
*/
|
|
704
|
-
getInfosTotalTransactions: (params?: RequestParams) => Promise<
|
|
704
|
+
getInfosTotalTransactions: (params?: RequestParams) => Promise<number>;
|
|
705
705
|
/**
|
|
706
706
|
* @description Get the average block time for each chain
|
|
707
707
|
*
|
|
@@ -385,7 +385,7 @@ class Api extends HttpClient {
|
|
|
385
385
|
query: query,
|
|
386
386
|
format: 'text',
|
|
387
387
|
...params
|
|
388
|
-
}).then(utils_1.
|
|
388
|
+
}).then(utils_1.convertHttpResponse),
|
|
389
389
|
/**
|
|
390
390
|
* No description
|
|
391
391
|
*
|
|
@@ -454,7 +454,7 @@ class Api extends HttpClient {
|
|
|
454
454
|
method: 'GET',
|
|
455
455
|
format: 'text',
|
|
456
456
|
...params
|
|
457
|
-
}).then(utils_1.
|
|
457
|
+
}).then(utils_1.convertHttpResponse),
|
|
458
458
|
/**
|
|
459
459
|
* @description Get the ALPH circulating supply
|
|
460
460
|
*
|
|
@@ -467,7 +467,7 @@ class Api extends HttpClient {
|
|
|
467
467
|
method: 'GET',
|
|
468
468
|
format: 'text',
|
|
469
469
|
...params
|
|
470
|
-
}).then(utils_1.
|
|
470
|
+
}).then(utils_1.convertHttpResponse),
|
|
471
471
|
/**
|
|
472
472
|
* @description Get the ALPH reserved supply
|
|
473
473
|
*
|
|
@@ -480,7 +480,7 @@ class Api extends HttpClient {
|
|
|
480
480
|
method: 'GET',
|
|
481
481
|
format: 'text',
|
|
482
482
|
...params
|
|
483
|
-
}).then(utils_1.
|
|
483
|
+
}).then(utils_1.convertHttpResponse),
|
|
484
484
|
/**
|
|
485
485
|
* @description Get the ALPH locked supply
|
|
486
486
|
*
|
|
@@ -493,7 +493,7 @@ class Api extends HttpClient {
|
|
|
493
493
|
method: 'GET',
|
|
494
494
|
format: 'text',
|
|
495
495
|
...params
|
|
496
|
-
}).then(utils_1.
|
|
496
|
+
}).then(utils_1.convertHttpResponse),
|
|
497
497
|
/**
|
|
498
498
|
* @description Get the total number of transactions
|
|
499
499
|
*
|
|
@@ -506,7 +506,7 @@ class Api extends HttpClient {
|
|
|
506
506
|
method: 'GET',
|
|
507
507
|
format: 'text',
|
|
508
508
|
...params
|
|
509
|
-
}).then(utils_1.
|
|
509
|
+
}).then(utils_1.convertHttpResponse),
|
|
510
510
|
/**
|
|
511
511
|
* @description Get the average block time for each chain
|
|
512
512
|
*
|
package/dist/src/api/utils.d.ts
CHANGED
|
@@ -5,12 +5,6 @@ export declare function convertHttpResponse<T>(response: {
|
|
|
5
5
|
detail: string;
|
|
6
6
|
};
|
|
7
7
|
}): T;
|
|
8
|
-
export declare function convertTextHttpResponse(response: {
|
|
9
|
-
text: () => Promise<string>;
|
|
10
|
-
error?: {
|
|
11
|
-
detail: string;
|
|
12
|
-
};
|
|
13
|
-
}): Promise<string>;
|
|
14
8
|
export declare function retryFetch(...fetchParams: Parameters<typeof fetch>): ReturnType<typeof fetch>;
|
|
15
9
|
export declare function throttledFetch(ratePerSec: number): typeof fetch;
|
|
16
10
|
export declare const RETRY_LIMIT_WHEN_429 = 3;
|
package/dist/src/api/utils.js
CHANGED
|
@@ -17,7 +17,7 @@ You should have received a copy of the GNU Lesser General Public License
|
|
|
17
17
|
along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
18
18
|
*/
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.DEFAULT_THROTTLE_FETCH = exports.DEFAULT_RATE_LIMIT = exports.RETRY_LIMIT_WHEN_429 = exports.throttledFetch = exports.retryFetch = exports.
|
|
20
|
+
exports.DEFAULT_THROTTLE_FETCH = exports.DEFAULT_RATE_LIMIT = exports.RETRY_LIMIT_WHEN_429 = exports.throttledFetch = exports.retryFetch = exports.convertHttpResponse = void 0;
|
|
21
21
|
require("cross-fetch/polyfill");
|
|
22
22
|
const utils_1 = require("../utils");
|
|
23
23
|
const async_sema_1 = require("async-sema");
|
|
@@ -30,15 +30,6 @@ function convertHttpResponse(response) {
|
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
exports.convertHttpResponse = convertHttpResponse;
|
|
33
|
-
async function convertTextHttpResponse(response) {
|
|
34
|
-
if (response.error) {
|
|
35
|
-
throw new Error(`[API Error] - ${response.error.detail}`);
|
|
36
|
-
}
|
|
37
|
-
else {
|
|
38
|
-
return await response.text();
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
exports.convertTextHttpResponse = convertTextHttpResponse;
|
|
42
33
|
async function retryFetch(...fetchParams) {
|
|
43
34
|
const retry = async (retryCount) => {
|
|
44
35
|
const response = await fetch(...fetchParams);
|
|
@@ -45,7 +45,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
45
45
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
46
46
|
exports.getContractEventsCurrentCount = exports.multicallMethods = exports.callMethod = exports.subscribeContractEvents = exports.subscribeContractEvent = exports.decodeEvent = exports.subscribeContractDestroyedEvent = exports.subscribeContractCreatedEvent = exports.fetchContractState = exports.ContractInstance = exports.testMethod = exports.addStdIdToFields = exports.subscribeEventsFromContract = exports.decodeContractDestroyedEvent = exports.decodeContractCreatedEvent = exports.DestroyContractEventAddress = exports.CreateContractEventAddress = exports.ContractFactory = exports.randomTxId = exports.toApiVals = exports.Script = exports.Contract = exports.Artifact = exports.Project = exports.DEFAULT_COMPILER_OPTIONS = exports.DEFAULT_NODE_COMPILER_OPTIONS = exports.StdIdFieldName = void 0;
|
|
47
47
|
const buffer_1 = require("buffer/");
|
|
48
|
-
const crypto_1 = require("crypto");
|
|
49
48
|
const fs_1 = __importDefault(require("fs"));
|
|
50
49
|
const fs_2 = require("fs");
|
|
51
50
|
const api_1 = require("../api");
|
|
@@ -55,6 +54,7 @@ const global_1 = require("../global");
|
|
|
55
54
|
const path = __importStar(require("path"));
|
|
56
55
|
const events_1 = require("./events");
|
|
57
56
|
const constants_1 = require("../constants");
|
|
57
|
+
const crypto = new utils_1.WebCrypto();
|
|
58
58
|
exports.StdIdFieldName = '__stdInterfaceId';
|
|
59
59
|
var SourceKind;
|
|
60
60
|
(function (SourceKind) {
|
|
@@ -112,7 +112,7 @@ class SourceInfo {
|
|
|
112
112
|
this.isExternal = isExternal;
|
|
113
113
|
}
|
|
114
114
|
static async from(type, name, sourceCode, contractRelativePath, isExternal) {
|
|
115
|
-
const sourceCodeHash = await
|
|
115
|
+
const sourceCodeHash = await crypto.subtle.digest('SHA-256', buffer_1.Buffer.from(sourceCode));
|
|
116
116
|
const sourceCodeHashHex = buffer_1.Buffer.from(sourceCodeHash).toString('hex');
|
|
117
117
|
return new SourceInfo(type, name, sourceCode, sourceCodeHashHex, contractRelativePath, isExternal);
|
|
118
118
|
}
|
|
@@ -553,7 +553,7 @@ class Contract extends Artifact {
|
|
|
553
553
|
// no need to be cryptographically strong random
|
|
554
554
|
static randomAddress() {
|
|
555
555
|
const bytes = new Uint8Array(33);
|
|
556
|
-
|
|
556
|
+
crypto.getRandomValues(bytes);
|
|
557
557
|
bytes[0] = 3;
|
|
558
558
|
return utils_1.bs58.encode(bytes);
|
|
559
559
|
}
|
|
@@ -901,7 +901,7 @@ function fromApiOutput(output) {
|
|
|
901
901
|
}
|
|
902
902
|
function randomTxId() {
|
|
903
903
|
const bytes = new Uint8Array(32);
|
|
904
|
-
|
|
904
|
+
crypto.getRandomValues(bytes);
|
|
905
905
|
return (0, utils_1.binToHex)(bytes);
|
|
906
906
|
}
|
|
907
907
|
exports.randomTxId = randomTxId;
|
package/dist/src/utils/index.js
CHANGED
|
@@ -31,6 +31,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
31
31
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
32
32
|
};
|
|
33
33
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
|
+
__exportStar(require("./webcrypto"), exports);
|
|
34
35
|
__exportStar(require("./address"), exports);
|
|
35
36
|
__exportStar(require("./bs58"), exports);
|
|
36
37
|
__exportStar(require("./djb2"), exports);
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
Copyright 2018 - 2022 The Alephium Authors
|
|
4
|
+
This file is part of the alephium project.
|
|
5
|
+
|
|
6
|
+
The library is free software: you can redistribute it and/or modify
|
|
7
|
+
it under the terms of the GNU Lesser General Public License as published by
|
|
8
|
+
the Free Software Foundation, either version 3 of the License, or
|
|
9
|
+
(at your option) any later version.
|
|
10
|
+
|
|
11
|
+
The library is distributed in the hope that it will be useful,
|
|
12
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14
|
+
GNU Lesser General Public License for more details.
|
|
15
|
+
|
|
16
|
+
You should have received a copy of the GNU Lesser General Public License
|
|
17
|
+
along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
18
|
+
*/
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.WebCrypto = void 0;
|
|
21
|
+
const buffer_1 = require("buffer/");
|
|
22
|
+
const crypto_1 = require("crypto");
|
|
23
|
+
const isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';
|
|
24
|
+
class WebCrypto {
|
|
25
|
+
constructor() {
|
|
26
|
+
this.subtle = isBrowser ? globalThis.crypto.subtle : crypto_1.webcrypto.subtle;
|
|
27
|
+
}
|
|
28
|
+
getRandomValues(array) {
|
|
29
|
+
if (!ArrayBuffer.isView(array)) {
|
|
30
|
+
throw new TypeError("Failed to execute 'getRandomValues' on 'Crypto': parameter 1 is not of type 'ArrayBufferView'");
|
|
31
|
+
}
|
|
32
|
+
const buffer = buffer_1.Buffer.from(array.buffer, array.byteOffset, array.byteLength);
|
|
33
|
+
if (isBrowser) {
|
|
34
|
+
globalThis.crypto.getRandomValues(buffer);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
(0, crypto_1.randomFillSync)(buffer);
|
|
38
|
+
}
|
|
39
|
+
return array;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.WebCrypto = WebCrypto;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alephium/web3",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.3",
|
|
4
4
|
"description": "A JS/TS library to interact with the Alephium platform",
|
|
5
5
|
"license": "GPL",
|
|
6
6
|
"main": "dist/src/index.js",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
},
|
|
28
28
|
"author": "Alephium dev <dev@alephium.org>",
|
|
29
29
|
"config": {
|
|
30
|
-
"alephium_version": "2.3.
|
|
30
|
+
"alephium_version": "2.3.3",
|
|
31
31
|
"explorer_backend_version": "1.13.5"
|
|
32
32
|
},
|
|
33
33
|
"type": "commonjs",
|
|
@@ -40,8 +40,10 @@
|
|
|
40
40
|
"bn.js": "5.2.1",
|
|
41
41
|
"buffer": "^6.0.3",
|
|
42
42
|
"cross-fetch": "^3.1.5",
|
|
43
|
+
"crypto-browserify": "^3.12.0",
|
|
43
44
|
"elliptic": "6.5.4",
|
|
44
|
-
"eventemitter3": "^4.0.7"
|
|
45
|
+
"eventemitter3": "^4.0.7",
|
|
46
|
+
"path-browserify": "^1.0.1"
|
|
45
47
|
},
|
|
46
48
|
"devDependencies": {
|
|
47
49
|
"@babel/eslint-parser": "^7.21.3",
|
|
@@ -55,7 +57,6 @@
|
|
|
55
57
|
"@typescript-eslint/eslint-plugin": "^5.57.0",
|
|
56
58
|
"@typescript-eslint/parser": "^5.57.0",
|
|
57
59
|
"clean-webpack-plugin": "4.0.0",
|
|
58
|
-
"crypto-browserify": "^3.12.0",
|
|
59
60
|
"eslint": "^8.37.0",
|
|
60
61
|
"eslint-config-prettier": "^8.8.0",
|
|
61
62
|
"eslint-plugin-header": "^3.1.1",
|
|
@@ -67,7 +68,6 @@
|
|
|
67
68
|
"jest-websocket-mock": "^2.4.0",
|
|
68
69
|
"mock-fs": "^5.2.0",
|
|
69
70
|
"mock-socket": "^9.2.1",
|
|
70
|
-
"path-browserify": "^1.0.1",
|
|
71
71
|
"prettier": "^2.8.7",
|
|
72
72
|
"process": "^0.11.10",
|
|
73
73
|
"rewire": "^6.0.0",
|
package/src/api/api-alephium.ts
CHANGED
|
@@ -1228,7 +1228,7 @@ export class HttpClient<SecurityDataType = unknown> {
|
|
|
1228
1228
|
|
|
1229
1229
|
/**
|
|
1230
1230
|
* @title Alephium API
|
|
1231
|
-
* @version 2.3.
|
|
1231
|
+
* @version 2.3.3
|
|
1232
1232
|
* @baseUrl ../
|
|
1233
1233
|
*/
|
|
1234
1234
|
export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDataType> {
|
package/src/api/api-explorer.ts
CHANGED
|
@@ -346,7 +346,7 @@ export interface ValU256 {
|
|
|
346
346
|
}
|
|
347
347
|
|
|
348
348
|
import 'cross-fetch/polyfill'
|
|
349
|
-
import { convertHttpResponse
|
|
349
|
+
import { convertHttpResponse } from './utils'
|
|
350
350
|
|
|
351
351
|
export type QueryParamsType = Record<string | number, any>
|
|
352
352
|
export type ResponseFormat = keyof Omit<Body, 'body' | 'bodyUsed'>
|
|
@@ -962,7 +962,7 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
|
|
|
962
962
|
query: query,
|
|
963
963
|
format: 'text',
|
|
964
964
|
...params
|
|
965
|
-
}).then(
|
|
965
|
+
}).then(convertHttpResponse),
|
|
966
966
|
|
|
967
967
|
/**
|
|
968
968
|
* No description
|
|
@@ -1072,7 +1072,7 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
|
|
|
1072
1072
|
method: 'GET',
|
|
1073
1073
|
format: 'text',
|
|
1074
1074
|
...params
|
|
1075
|
-
}).then(
|
|
1075
|
+
}).then(convertHttpResponse),
|
|
1076
1076
|
|
|
1077
1077
|
/**
|
|
1078
1078
|
* @description Get the ALPH circulating supply
|
|
@@ -1087,7 +1087,7 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
|
|
|
1087
1087
|
method: 'GET',
|
|
1088
1088
|
format: 'text',
|
|
1089
1089
|
...params
|
|
1090
|
-
}).then(
|
|
1090
|
+
}).then(convertHttpResponse),
|
|
1091
1091
|
|
|
1092
1092
|
/**
|
|
1093
1093
|
* @description Get the ALPH reserved supply
|
|
@@ -1102,7 +1102,7 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
|
|
|
1102
1102
|
method: 'GET',
|
|
1103
1103
|
format: 'text',
|
|
1104
1104
|
...params
|
|
1105
|
-
}).then(
|
|
1105
|
+
}).then(convertHttpResponse),
|
|
1106
1106
|
|
|
1107
1107
|
/**
|
|
1108
1108
|
* @description Get the ALPH locked supply
|
|
@@ -1117,7 +1117,7 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
|
|
|
1117
1117
|
method: 'GET',
|
|
1118
1118
|
format: 'text',
|
|
1119
1119
|
...params
|
|
1120
|
-
}).then(
|
|
1120
|
+
}).then(convertHttpResponse),
|
|
1121
1121
|
|
|
1122
1122
|
/**
|
|
1123
1123
|
* @description Get the total number of transactions
|
|
@@ -1132,7 +1132,7 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
|
|
|
1132
1132
|
method: 'GET',
|
|
1133
1133
|
format: 'text',
|
|
1134
1134
|
...params
|
|
1135
|
-
}).then(
|
|
1135
|
+
}).then(convertHttpResponse),
|
|
1136
1136
|
|
|
1137
1137
|
/**
|
|
1138
1138
|
* @description Get the average block time for each chain
|
package/src/api/utils.ts
CHANGED
|
@@ -28,17 +28,6 @@ export function convertHttpResponse<T>(response: { data: T; error?: { detail: st
|
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
export async function convertTextHttpResponse(response: {
|
|
32
|
-
text: () => Promise<string>
|
|
33
|
-
error?: { detail: string }
|
|
34
|
-
}): Promise<string> {
|
|
35
|
-
if (response.error) {
|
|
36
|
-
throw new Error(`[API Error] - ${response.error.detail}`)
|
|
37
|
-
} else {
|
|
38
|
-
return await response.text()
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
31
|
export async function retryFetch(...fetchParams: Parameters<typeof fetch>): ReturnType<typeof fetch> {
|
|
43
32
|
const retry = async (retryCount: number): ReturnType<typeof fetch> => {
|
|
44
33
|
const response = await fetch(...fetchParams)
|
package/src/contract/contract.ts
CHANGED
|
@@ -17,7 +17,6 @@ along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
19
|
import { Buffer } from 'buffer/'
|
|
20
|
-
import { webcrypto as crypto } from 'crypto'
|
|
21
20
|
import fs from 'fs'
|
|
22
21
|
import { promises as fsPromises } from 'fs'
|
|
23
22
|
import {
|
|
@@ -54,13 +53,16 @@ import {
|
|
|
54
53
|
Eq,
|
|
55
54
|
Optional,
|
|
56
55
|
groupOfAddress,
|
|
57
|
-
addressFromContractId
|
|
56
|
+
addressFromContractId,
|
|
57
|
+
WebCrypto
|
|
58
58
|
} from '../utils'
|
|
59
59
|
import { getCurrentNodeProvider } from '../global'
|
|
60
60
|
import * as path from 'path'
|
|
61
61
|
import { EventSubscription, subscribeToEvents } from './events'
|
|
62
62
|
import { ONE_ALPH } from '../constants'
|
|
63
63
|
|
|
64
|
+
const crypto = new WebCrypto()
|
|
65
|
+
|
|
64
66
|
export type FieldsSig = node.FieldsSig
|
|
65
67
|
export type EventSig = node.EventSig
|
|
66
68
|
export type FunctionSig = node.FunctionSig
|
package/src/utils/index.ts
CHANGED
|
@@ -16,6 +16,7 @@ You should have received a copy of the GNU Lesser General Public License
|
|
|
16
16
|
along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
|
+
export * from './webcrypto'
|
|
19
20
|
export * from './address'
|
|
20
21
|
export * from './bs58'
|
|
21
22
|
export * from './djb2'
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2018 - 2022 The Alephium Authors
|
|
3
|
+
This file is part of the alephium project.
|
|
4
|
+
|
|
5
|
+
The library is free software: you can redistribute it and/or modify
|
|
6
|
+
it under the terms of the GNU Lesser General Public License as published by
|
|
7
|
+
the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
(at your option) any later version.
|
|
9
|
+
|
|
10
|
+
The library is distributed in the hope that it will be useful,
|
|
11
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
GNU Lesser General Public License for more details.
|
|
14
|
+
|
|
15
|
+
You should have received a copy of the GNU Lesser General Public License
|
|
16
|
+
along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { Buffer } from 'buffer/'
|
|
20
|
+
import { webcrypto, randomFillSync } from 'crypto'
|
|
21
|
+
|
|
22
|
+
const isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined'
|
|
23
|
+
|
|
24
|
+
export class WebCrypto {
|
|
25
|
+
subtle = isBrowser ? globalThis.crypto.subtle : webcrypto.subtle
|
|
26
|
+
|
|
27
|
+
public getRandomValues<T extends ArrayBufferView | null>(array: T): T {
|
|
28
|
+
if (!ArrayBuffer.isView(array)) {
|
|
29
|
+
throw new TypeError(
|
|
30
|
+
"Failed to execute 'getRandomValues' on 'Crypto': parameter 1 is not of type 'ArrayBufferView'"
|
|
31
|
+
)
|
|
32
|
+
}
|
|
33
|
+
const buffer = Buffer.from(array.buffer, array.byteOffset, array.byteLength)
|
|
34
|
+
|
|
35
|
+
if (isBrowser) {
|
|
36
|
+
globalThis.crypto.getRandomValues(buffer)
|
|
37
|
+
} else {
|
|
38
|
+
randomFillSync(buffer)
|
|
39
|
+
}
|
|
40
|
+
return array
|
|
41
|
+
}
|
|
42
|
+
}
|