@alephium/web3 3.0.0-test.6 → 3.0.0-test.7
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/MIGRATION.md +22 -19
- package/dist/_cjs/api/api-alephium.d.ts +3 -0
- package/dist/_cjs/api/api-alephium.js.map +1 -1
- package/dist/_cjs/contract/contract.d.ts +3 -2
- package/dist/_cjs/contract/contract.js +7 -6
- package/dist/_cjs/contract/contract.js.map +1 -1
- package/dist/_cjs/utils/sign.js +1 -2
- package/dist/_cjs/utils/sign.js.map +1 -1
- package/dist/_esm/api/api-alephium.d.ts +3 -0
- package/dist/_esm/api/api-alephium.js.map +1 -1
- package/dist/_esm/contract/contract.d.ts +3 -2
- package/dist/_esm/contract/contract.js +7 -6
- package/dist/_esm/contract/contract.js.map +1 -1
- package/dist/_esm/utils/sign.js +2 -3
- package/dist/_esm/utils/sign.js.map +1 -1
- package/package.json +9 -20
- package/src/api/api-alephium.ts +8 -2
- package/src/contract/contract.ts +13 -6
- package/src/utils/sign.ts +2 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alephium/web3",
|
|
3
|
-
"version": "3.0.0-test.
|
|
3
|
+
"version": "3.0.0-test.7",
|
|
4
4
|
"description": "A JS/TS library to interact with the Alephium platform",
|
|
5
5
|
"license": "GPL",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -60,13 +60,13 @@
|
|
|
60
60
|
},
|
|
61
61
|
"author": "Alephium dev <dev@alephium.org>",
|
|
62
62
|
"config": {
|
|
63
|
-
"alephium_version": "4.
|
|
63
|
+
"alephium_version": "4.4.1",
|
|
64
64
|
"explorer_backend_version": "3.3.2"
|
|
65
65
|
},
|
|
66
66
|
"dependencies": {
|
|
67
|
-
"@noble/curves": "1.
|
|
68
|
-
"@noble/hashes": "1.
|
|
69
|
-
"@noble/secp256k1": "1.7.
|
|
67
|
+
"@noble/curves": "1.9.7",
|
|
68
|
+
"@noble/hashes": "1.8.0",
|
|
69
|
+
"@noble/secp256k1": "1.7.2",
|
|
70
70
|
"base-x": "4.0.0",
|
|
71
71
|
"bignumber.js": "^9.1.1",
|
|
72
72
|
"eventemitter3": "^4.0.7"
|
|
@@ -74,33 +74,21 @@
|
|
|
74
74
|
"devDependencies": {
|
|
75
75
|
"@arethetypeswrong/cli": "^0.18.2",
|
|
76
76
|
"@babel/eslint-parser": "^7.21.3",
|
|
77
|
-
"@size-limit/esbuild": "^11.0.0",
|
|
78
|
-
"@size-limit/file": "^11.0.0",
|
|
79
77
|
"@types/find-up": "^2.1.1",
|
|
80
78
|
"@types/fs-extra": "^9.0.13",
|
|
81
|
-
"@types/jest": "^27.5.2",
|
|
82
|
-
"@types/mock-fs": "^4.13.1",
|
|
83
79
|
"@types/node": "^20.0.0",
|
|
84
|
-
"@types/rewire": "^2.5.28",
|
|
85
80
|
"@typescript-eslint/eslint-plugin": "^5.57.0",
|
|
86
81
|
"@typescript-eslint/parser": "^5.57.0",
|
|
87
82
|
"eslint": "^8.37.0",
|
|
88
83
|
"eslint-config-prettier": "^8.8.0",
|
|
89
84
|
"eslint-plugin-prettier": "^4.2.1",
|
|
90
85
|
"eslint-plugin-security": "1.6.0",
|
|
91
|
-
"jest": "^28.1.3",
|
|
92
|
-
"jest-localstorage-mock": "^2.4.26",
|
|
93
|
-
"jest-websocket-mock": "^2.4.0",
|
|
94
|
-
"mock-fs": "^5.2.0",
|
|
95
|
-
"mock-socket": "^9.2.1",
|
|
96
86
|
"prettier": "^2.8.7",
|
|
97
87
|
"process": "^0.11.10",
|
|
98
88
|
"publint": "^0.3.18",
|
|
99
|
-
"rewire": "^6.0.0",
|
|
100
89
|
"shelljs": "^0.8.5",
|
|
101
90
|
"size-limit": "^11.0.0",
|
|
102
91
|
"swagger-typescript-api": "12.0.3",
|
|
103
|
-
"ts-jest": "^28.0.8",
|
|
104
92
|
"ts-node": "^10.9.1",
|
|
105
93
|
"tsc-alias": "^1.8.16",
|
|
106
94
|
"tslib": "^2.5.0",
|
|
@@ -111,12 +99,13 @@
|
|
|
111
99
|
"npm": ">=7.0.0"
|
|
112
100
|
},
|
|
113
101
|
"scripts": {
|
|
114
|
-
"
|
|
115
|
-
"build": "rm -rf dist && pnpm build:cjs && pnpm build:esm",
|
|
102
|
+
"build": "pnpm clean && pnpm build:cjs && pnpm build:esm",
|
|
116
103
|
"build:cjs": "tsc --project tsconfig.build.json --module commonjs --moduleResolution node --outDir dist/_cjs --declaration --verbatimModuleSyntax false && printf '{\"type\":\"commonjs\"}' > dist/_cjs/package.json",
|
|
117
104
|
"build:esm": "tsc --project tsconfig.build.json --outDir dist/_esm --declaration && tsc-alias --project tsconfig.build.json --outDir dist/_esm --resolve-full-paths && printf '{\"type\":\"module\",\"sideEffects\":false}' > dist/_esm/package.json",
|
|
105
|
+
"clean": "rm -rf dist",
|
|
106
|
+
"clean:all": "pnpm clean && rm -rf node_modules",
|
|
118
107
|
"check": "publint && attw --pack --ignore-rules internal-resolution-error",
|
|
119
|
-
"test": "
|
|
108
|
+
"test": "vitest run",
|
|
120
109
|
"update-schemas": "npm run update-schema:alephium && npm run update-schema:explorer",
|
|
121
110
|
"update-schema:alephium": "npx swagger-typescript-api --disable-throw-on-error -t ./configs -o ./src/api -n api-alephium.ts -p https://raw.githubusercontent.com/alephium/alephium/v${npm_package_config_alephium_version}/api/src/main/resources/openapi.json",
|
|
122
111
|
"update-schema:explorer": "npx swagger-typescript-api --disable-throw-on-error -t ./configs -o ./src/api -n api-explorer.ts -p https://raw.githubusercontent.com/alephium/explorer-backend/v${npm_package_config_explorer_backend_version}/app/src/main/resources/explorer-backend-openapi.json",
|
package/src/api/api-alephium.ts
CHANGED
|
@@ -723,6 +723,8 @@ export interface ContractEvent {
|
|
|
723
723
|
blockHash: string
|
|
724
724
|
/** @format 32-byte-hash */
|
|
725
725
|
txId: string
|
|
726
|
+
/** @format int64 */
|
|
727
|
+
timestamp: number
|
|
726
728
|
/** @format int32 */
|
|
727
729
|
eventIndex: number
|
|
728
730
|
fields: Val[]
|
|
@@ -732,6 +734,8 @@ export interface ContractEvent {
|
|
|
732
734
|
export interface ContractEventByBlockHash {
|
|
733
735
|
/** @format 32-byte-hash */
|
|
734
736
|
txId: string
|
|
737
|
+
/** @format int64 */
|
|
738
|
+
timestamp: number
|
|
735
739
|
/** @format address */
|
|
736
740
|
contractAddress: string
|
|
737
741
|
/** @format int32 */
|
|
@@ -743,6 +747,8 @@ export interface ContractEventByBlockHash {
|
|
|
743
747
|
export interface ContractEventByTxId {
|
|
744
748
|
/** @format block-hash */
|
|
745
749
|
blockHash: string
|
|
750
|
+
/** @format int64 */
|
|
751
|
+
timestamp: number
|
|
746
752
|
/** @format address */
|
|
747
753
|
contractAddress: string
|
|
748
754
|
/** @format int32 */
|
|
@@ -1503,7 +1509,7 @@ export interface ValByteVec {
|
|
|
1503
1509
|
|
|
1504
1510
|
/** ValI256 */
|
|
1505
1511
|
export interface ValI256 {
|
|
1506
|
-
/** @format
|
|
1512
|
+
/** @format int256 */
|
|
1507
1513
|
value: string
|
|
1508
1514
|
type: string
|
|
1509
1515
|
}
|
|
@@ -1779,7 +1785,7 @@ export class HttpClient<SecurityDataType = unknown> {
|
|
|
1779
1785
|
|
|
1780
1786
|
/**
|
|
1781
1787
|
* @title Alephium API
|
|
1782
|
-
* @version 4.
|
|
1788
|
+
* @version 4.4.1
|
|
1783
1789
|
* @baseUrl ../
|
|
1784
1790
|
*/
|
|
1785
1791
|
export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDataType> {
|
package/src/contract/contract.ts
CHANGED
|
@@ -371,15 +371,14 @@ export class Contract extends Artifact {
|
|
|
371
371
|
)
|
|
372
372
|
}
|
|
373
373
|
|
|
374
|
-
// support both 'code.ral' and 'code.ral.json'
|
|
375
374
|
static async fromArtifactFile(
|
|
376
375
|
path: string,
|
|
376
|
+
readFile: (path: string) => Promise<string | Uint8Array>,
|
|
377
377
|
bytecodeDebugPatch: string,
|
|
378
378
|
codeHashDebug: string,
|
|
379
379
|
structs: Struct[] = []
|
|
380
380
|
): Promise<Contract> {
|
|
381
|
-
const
|
|
382
|
-
const content = await fs.promises.readFile(path)
|
|
381
|
+
const content = await readFile(path)
|
|
383
382
|
const artifact = JSON.parse(content.toString())
|
|
384
383
|
return Contract.fromJson(artifact, bytecodeDebugPatch, codeHashDebug, structs)
|
|
385
384
|
}
|
|
@@ -568,6 +567,7 @@ export class Contract extends Artifact {
|
|
|
568
567
|
return {
|
|
569
568
|
txId: txId,
|
|
570
569
|
blockHash: event.blockHash,
|
|
570
|
+
timestamp: event.timestamp,
|
|
571
571
|
contractAddress: event.contractAddress,
|
|
572
572
|
name: name,
|
|
573
573
|
eventIndex: event.eventIndex,
|
|
@@ -779,9 +779,13 @@ export class Script extends Artifact {
|
|
|
779
779
|
)
|
|
780
780
|
}
|
|
781
781
|
|
|
782
|
-
static async fromArtifactFile(
|
|
783
|
-
|
|
784
|
-
|
|
782
|
+
static async fromArtifactFile(
|
|
783
|
+
path: string,
|
|
784
|
+
readFile: (path: string) => Promise<string | Uint8Array>,
|
|
785
|
+
bytecodeDebugPatch: string,
|
|
786
|
+
structs: Struct[] = []
|
|
787
|
+
): Promise<Script> {
|
|
788
|
+
const content = await readFile(path)
|
|
785
789
|
const artifact = JSON.parse(content.toString())
|
|
786
790
|
return this.fromJson(artifact, bytecodeDebugPatch, structs)
|
|
787
791
|
}
|
|
@@ -1011,6 +1015,7 @@ export interface TestContractParams<
|
|
|
1011
1015
|
export interface ContractEvent<T extends Fields = Fields> {
|
|
1012
1016
|
txId: string
|
|
1013
1017
|
blockHash: string
|
|
1018
|
+
timestamp: number
|
|
1014
1019
|
contractAddress: string
|
|
1015
1020
|
eventIndex: number
|
|
1016
1021
|
name: string
|
|
@@ -1304,6 +1309,7 @@ export function decodeContractCreatedEvent(event: node.ContractEvent): Omit<Cont
|
|
|
1304
1309
|
return {
|
|
1305
1310
|
blockHash: event.blockHash,
|
|
1306
1311
|
txId: event.txId,
|
|
1312
|
+
timestamp: event.timestamp,
|
|
1307
1313
|
eventIndex: event.eventIndex,
|
|
1308
1314
|
name: Contract.ContractCreatedEvent.name,
|
|
1309
1315
|
fields: toContractCreatedEventFields(fields)
|
|
@@ -1317,6 +1323,7 @@ export function decodeContractDestroyedEvent(
|
|
|
1317
1323
|
return {
|
|
1318
1324
|
blockHash: event.blockHash,
|
|
1319
1325
|
txId: event.txId,
|
|
1326
|
+
timestamp: event.timestamp,
|
|
1320
1327
|
eventIndex: event.eventIndex,
|
|
1321
1328
|
name: Contract.ContractDestroyedEvent.name,
|
|
1322
1329
|
fields: { address: fields['address'] as Address }
|
package/src/utils/sign.ts
CHANGED
|
@@ -16,7 +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
|
-
import { binToHex, encodeSignature, hexToBinUnsafe
|
|
19
|
+
import { binToHex, encodeSignature, hexToBinUnsafe } from '../utils'
|
|
20
20
|
import { KeyType } from '../signer'
|
|
21
21
|
import * as secp from '@noble/secp256k1'
|
|
22
22
|
import { sha256 } from '@noble/hashes/sha256'
|
|
@@ -61,8 +61,7 @@ export function verifySignature(hash: string, publicKey: string, signature: stri
|
|
|
61
61
|
|
|
62
62
|
try {
|
|
63
63
|
if (keyType === 'default' || keyType === 'gl-secp256k1') {
|
|
64
|
-
const
|
|
65
|
-
const sig = secp.Signature.fromCompact(decoded.r + decoded.s)
|
|
64
|
+
const sig = secp.Signature.fromCompact(signature)
|
|
66
65
|
return secp.verify(sig, hexToBinUnsafe(hash), hexToBinUnsafe(publicKey))
|
|
67
66
|
} else {
|
|
68
67
|
return secp.schnorr.verifySync(hexToBinUnsafe(signature), hexToBinUnsafe(hash), hexToBinUnsafe(publicKey))
|