quantumcoin 7.0.10 → 7.0.12
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/README-SDK.md +16 -5
- package/README.md +14 -3
- package/config.js +10 -2
- package/examples/example.js +0 -5
- package/examples/example.ts +0 -5
- package/examples/node_modules/.bin/esbuild +16 -0
- package/examples/node_modules/.bin/esbuild.cmd +17 -0
- package/examples/node_modules/.bin/esbuild.ps1 +28 -0
- package/examples/node_modules/.bin/sdkgen +16 -0
- package/examples/node_modules/.bin/sdkgen.cmd +17 -0
- package/examples/node_modules/.bin/sdkgen.ps1 +28 -0
- package/examples/node_modules/.bin/tsx +16 -0
- package/examples/node_modules/.bin/tsx.cmd +17 -0
- package/examples/node_modules/.bin/tsx.ps1 +28 -0
- package/examples/node_modules/.package-lock.json +144 -0
- package/examples/node_modules/@esbuild/win32-x64/README.md +3 -0
- package/examples/node_modules/@esbuild/win32-x64/esbuild.exe +0 -0
- package/examples/node_modules/@esbuild/win32-x64/package.json +20 -0
- package/examples/node_modules/esbuild/LICENSE.md +21 -0
- package/examples/node_modules/esbuild/README.md +3 -0
- package/examples/node_modules/esbuild/bin/esbuild +223 -0
- package/examples/node_modules/esbuild/install.js +289 -0
- package/examples/node_modules/esbuild/lib/main.d.ts +716 -0
- package/examples/node_modules/esbuild/lib/main.js +2532 -0
- package/examples/node_modules/esbuild/package.json +49 -0
- package/examples/node_modules/get-tsconfig/LICENSE +21 -0
- package/examples/node_modules/get-tsconfig/README.md +235 -0
- package/examples/node_modules/get-tsconfig/dist/index.cjs +7 -0
- package/examples/node_modules/get-tsconfig/dist/index.d.cts +2088 -0
- package/examples/node_modules/get-tsconfig/dist/index.d.mts +2088 -0
- package/examples/node_modules/get-tsconfig/dist/index.mjs +7 -0
- package/examples/node_modules/get-tsconfig/package.json +46 -0
- package/examples/node_modules/quantum-coin-js-sdk/LICENSE +21 -0
- package/examples/node_modules/quantum-coin-js-sdk/LICENSE-wasm_exec.js.txt +30 -0
- package/examples/node_modules/quantum-coin-js-sdk/README.md +1675 -0
- package/examples/node_modules/quantum-coin-js-sdk/example/README.md +14 -0
- package/examples/node_modules/quantum-coin-js-sdk/example/conversion-example.js +19 -0
- package/examples/node_modules/quantum-coin-js-sdk/example/example-create-contract.js +396 -0
- package/examples/node_modules/quantum-coin-js-sdk/example/example-encode-decode-rlp.js +225 -0
- package/examples/node_modules/quantum-coin-js-sdk/example/example-event-pack-unpack.js +391 -0
- package/examples/node_modules/quantum-coin-js-sdk/example/example-misc.js +101 -0
- package/examples/node_modules/quantum-coin-js-sdk/example/example-rpc-send-signRawTransaction.js +318 -0
- package/examples/node_modules/quantum-coin-js-sdk/example/example-rpc-send.js +116 -0
- package/examples/node_modules/quantum-coin-js-sdk/example/example-send.js +70 -0
- package/examples/node_modules/quantum-coin-js-sdk/example/example-token-pack-unpack.js +961 -0
- package/examples/node_modules/quantum-coin-js-sdk/example/example-wallet-version4.js +35 -0
- package/examples/node_modules/quantum-coin-js-sdk/example/example-wallet.js +43 -0
- package/examples/node_modules/quantum-coin-js-sdk/example/example.js +405 -0
- package/examples/node_modules/quantum-coin-js-sdk/example/package-lock.json +134 -0
- package/examples/node_modules/quantum-coin-js-sdk/example/package.json +15 -0
- package/examples/node_modules/quantum-coin-js-sdk/index.d.ts +1031 -0
- package/examples/node_modules/quantum-coin-js-sdk/index.js +3144 -0
- package/examples/node_modules/quantum-coin-js-sdk/package.json +34 -0
- package/examples/node_modules/quantum-coin-js-sdk/tests/encrypted-32.json +1 -0
- package/examples/node_modules/quantum-coin-js-sdk/tests/encrypted-36.json +1 -0
- package/examples/node_modules/quantum-coin-js-sdk/tests/encrypted-48.json +1 -0
- package/examples/node_modules/quantum-coin-js-sdk/tests/generate-verify-vectors.js +91 -0
- package/examples/node_modules/quantum-coin-js-sdk/tests/non-transactional.preinit.test.js +41 -0
- package/examples/node_modules/quantum-coin-js-sdk/tests/non-transactional.test.js +1389 -0
- package/examples/node_modules/quantum-coin-js-sdk/tests/sign-raw-keytype5-context-null.test.js +107 -0
- package/examples/node_modules/quantum-coin-js-sdk/tests/sign-raw-transaction.test.js +196 -0
- package/examples/node_modules/quantum-coin-js-sdk/tests/sign-verify.test.js +311 -0
- package/examples/node_modules/quantum-coin-js-sdk/tests/transactional.relay.test.js +131 -0
- package/examples/node_modules/quantum-coin-js-sdk/tests/transactional.rpc.test.js +103 -0
- package/examples/node_modules/quantum-coin-js-sdk/tests/verify-vectors.json +95035 -0
- package/examples/node_modules/quantum-coin-js-sdk/wasmBase64.d.ts +9 -0
- package/examples/node_modules/quantum-coin-js-sdk/wasmBase64.js +16 -0
- package/examples/node_modules/quantum-coin-js-sdk/wasm_exec.d.ts +0 -0
- package/examples/node_modules/quantum-coin-js-sdk/wasm_exec.js +587 -0
- package/examples/node_modules/resolve-pkg-maps/LICENSE +21 -0
- package/examples/node_modules/resolve-pkg-maps/README.md +216 -0
- package/examples/node_modules/resolve-pkg-maps/dist/index.cjs +1 -0
- package/examples/node_modules/resolve-pkg-maps/dist/index.d.cts +11 -0
- package/examples/node_modules/resolve-pkg-maps/dist/index.d.mts +11 -0
- package/examples/node_modules/resolve-pkg-maps/dist/index.mjs +1 -0
- package/examples/node_modules/resolve-pkg-maps/package.json +42 -0
- package/examples/node_modules/seed-words/.github/workflows/publish-npmjs.yaml +22 -0
- package/examples/node_modules/seed-words/BUILD.md +7 -0
- package/examples/node_modules/seed-words/LICENSE +121 -0
- package/examples/node_modules/seed-words/README.md +67 -0
- package/examples/node_modules/seed-words/dist/seedwords.d.ts +39 -0
- package/examples/node_modules/seed-words/package.json +27 -0
- package/examples/node_modules/seed-words/seedwords.js +315 -0
- package/examples/node_modules/seed-words/seedwords.txt +65536 -0
- package/examples/node_modules/seed-words/tsconfig.json +21 -0
- package/examples/node_modules/tsx/LICENSE +21 -0
- package/examples/node_modules/tsx/README.md +32 -0
- package/examples/node_modules/tsx/dist/cjs/api/index.cjs +1 -0
- package/examples/node_modules/tsx/dist/cjs/api/index.d.cts +35 -0
- package/examples/node_modules/tsx/dist/cjs/api/index.d.mts +35 -0
- package/examples/node_modules/tsx/dist/cjs/api/index.mjs +1 -0
- package/examples/node_modules/tsx/dist/cjs/index.cjs +1 -0
- package/examples/node_modules/tsx/dist/cjs/index.mjs +1 -0
- package/examples/node_modules/tsx/dist/cli.cjs +54 -0
- package/examples/node_modules/tsx/dist/cli.mjs +55 -0
- package/examples/node_modules/tsx/dist/client-BQVF1NaW.mjs +1 -0
- package/examples/node_modules/tsx/dist/client-D6NvIMSC.cjs +1 -0
- package/examples/node_modules/tsx/dist/esm/api/index.cjs +1 -0
- package/examples/node_modules/tsx/dist/esm/api/index.d.cts +35 -0
- package/examples/node_modules/tsx/dist/esm/api/index.d.mts +35 -0
- package/examples/node_modules/tsx/dist/esm/api/index.mjs +1 -0
- package/examples/node_modules/tsx/dist/esm/index.cjs +2 -0
- package/examples/node_modules/tsx/dist/esm/index.mjs +2 -0
- package/examples/node_modules/tsx/dist/get-pipe-path-BHW2eJdv.mjs +1 -0
- package/examples/node_modules/tsx/dist/get-pipe-path-BoR10qr8.cjs +1 -0
- package/examples/node_modules/tsx/dist/index-7AaEi15b.mjs +14 -0
- package/examples/node_modules/tsx/dist/index-BWFBUo6r.cjs +1 -0
- package/examples/node_modules/tsx/dist/index-gbaejti9.mjs +1 -0
- package/examples/node_modules/tsx/dist/index-gckBtVBf.cjs +14 -0
- package/examples/node_modules/tsx/dist/lexer-DQCqS3nf.mjs +3 -0
- package/examples/node_modules/tsx/dist/lexer-DgIbo0BU.cjs +3 -0
- package/examples/node_modules/tsx/dist/loader.cjs +1 -0
- package/examples/node_modules/tsx/dist/loader.mjs +1 -0
- package/examples/node_modules/tsx/dist/node-features-_8ZFwP_x.mjs +1 -0
- package/examples/node_modules/tsx/dist/node-features-roYmp9jK.cjs +1 -0
- package/examples/node_modules/tsx/dist/package-CeBgXWuR.mjs +1 -0
- package/examples/node_modules/tsx/dist/package-Dxt5kIHw.cjs +1 -0
- package/examples/node_modules/tsx/dist/patch-repl.cjs +1 -0
- package/examples/node_modules/tsx/dist/patch-repl.mjs +1 -0
- package/examples/node_modules/tsx/dist/preflight.cjs +1 -0
- package/examples/node_modules/tsx/dist/preflight.mjs +1 -0
- package/examples/node_modules/tsx/dist/register-2sWVXuRQ.cjs +1 -0
- package/examples/node_modules/tsx/dist/register-B7jrtLTO.mjs +1 -0
- package/examples/node_modules/tsx/dist/register-CFH5oNdT.mjs +4 -0
- package/examples/node_modules/tsx/dist/register-D46fvsV_.cjs +4 -0
- package/examples/node_modules/tsx/dist/repl.cjs +3 -0
- package/examples/node_modules/tsx/dist/repl.mjs +3 -0
- package/examples/node_modules/tsx/dist/require-D4F1Lv60.cjs +1 -0
- package/examples/node_modules/tsx/dist/require-DQxpCAr4.mjs +1 -0
- package/examples/node_modules/tsx/dist/suppress-warnings.cjs +1 -0
- package/examples/node_modules/tsx/dist/suppress-warnings.mjs +1 -0
- package/examples/node_modules/tsx/dist/temporary-directory-B83uKxJF.cjs +1 -0
- package/examples/node_modules/tsx/dist/temporary-directory-CwHp0_NW.mjs +1 -0
- package/examples/node_modules/tsx/dist/types-Cxp8y2TL.d.ts +5 -0
- package/examples/node_modules/tsx/package.json +68 -0
- package/examples/offline-signing.js +0 -2
- package/examples/offline-signing.ts +0 -1
- package/examples/package-lock.json +422 -73
- package/examples/package.json +1 -1
- package/examples/wallet-offline.js +1 -9
- package/examples/wallet-offline.ts +1 -9
- package/generate-sdk.js +5 -7
- package/package.json +2 -2
- package/src/abi/interface.js +13 -7
- package/src/abi/js-abi-coder.js +23 -18
- package/src/constants.d.ts +0 -5
- package/src/constants.js +0 -7
- package/src/contract/contract-factory.js +9 -3
- package/src/contract/contract.js +9 -3
- package/src/errors/index.js +12 -0
- package/src/index.d.ts +0 -3
- package/src/providers/extra-providers.js +20 -6
- package/src/providers/json-rpc-provider.js +15 -5
- package/src/providers/provider.d.ts +0 -2
- package/src/providers/provider.js +1 -3
- package/src/utils/address.d.ts +0 -14
- package/src/utils/address.js +12 -49
- package/src/utils/hashing.d.ts +0 -6
- package/src/utils/hashing.js +8 -23
- package/src/utils/index.d.ts +0 -3
- package/src/utils/rlp.js +7 -4
- package/src/wallet/wallet.d.ts +7 -13
- package/src/wallet/wallet.js +136 -97
- package/test/security/malformed-input.test.js +295 -1
- package/test/unit/address-wallet.test.js +329 -129
- package/test/unit/address-wallet.test.ts +328 -128
- package/test/unit/hashing.test.js +0 -11
- package/test/unit/hashing.test.ts +0 -11
- package/test/unit/providers.test.js +3 -1
- package/test/unit/providers.test.ts +3 -1
- package/SPEC.md +0 -3845
|
@@ -0,0 +1,391 @@
|
|
|
1
|
+
const qcsdk = require('quantum-coin-js-sdk');
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Example: Event Log Encode/Decode Operations
|
|
5
|
+
*
|
|
6
|
+
* This example demonstrates how to use encodeEventLog and decodeEventLog
|
|
7
|
+
* to encode and decode Ethereum event logs according to the ABI specification.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
// Configuration
|
|
11
|
+
var clientConfigVal = new qcsdk.Config("https://sdk.readrelay.quantumcoinapi.com", "https://sdk.writerelay.quantumcoinapi.com", 123123, "", ""); //Mainnet
|
|
12
|
+
//Mainnet Block Explorer: https://scan.quantumcoin.org
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Example 1: Basic Transfer Event (ERC20)
|
|
16
|
+
* Transfer(address indexed from, address indexed to, uint256 value)
|
|
17
|
+
*/
|
|
18
|
+
async function example1_TransferEvent() {
|
|
19
|
+
console.log("\n=== Example 1: Transfer Event ===");
|
|
20
|
+
|
|
21
|
+
const transferABI = JSON.stringify([{
|
|
22
|
+
"name": "Transfer",
|
|
23
|
+
"type": "event",
|
|
24
|
+
"anonymous": false,
|
|
25
|
+
"inputs": [
|
|
26
|
+
{"name": "from", "type": "address", "indexed": true},
|
|
27
|
+
{"name": "to", "type": "address", "indexed": true},
|
|
28
|
+
{"name": "value", "type": "uint256", "indexed": false}
|
|
29
|
+
]
|
|
30
|
+
}]);
|
|
31
|
+
|
|
32
|
+
const fromAddress = "0xd51773b5dde3f8e4d29ae42b5046510e2a11fd0c8e4175853d6227896eb445c6";
|
|
33
|
+
const toAddress = "0x1Bd75060B22686a9f32Af80BC02348c1BAeDBba06f47ad723885c92a6566B65d";
|
|
34
|
+
const value = "1000000000000000000"; // 1 token (18 decimals)
|
|
35
|
+
|
|
36
|
+
// Encode the event
|
|
37
|
+
const encodeResult = qcsdk.encodeEventLog(transferABI, "Transfer", fromAddress, toAddress, value);
|
|
38
|
+
|
|
39
|
+
if (encodeResult.error) {
|
|
40
|
+
console.error("Encode error:", encodeResult.error);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
console.log("Encoded Transfer Event:");
|
|
45
|
+
console.log(" Topics:", encodeResult.result.topics);
|
|
46
|
+
console.log(" Data:", encodeResult.result.data);
|
|
47
|
+
console.log(" Number of topics:", encodeResult.result.topics.length);
|
|
48
|
+
console.log(" Expected: 3 topics (event signature + from + to)");
|
|
49
|
+
|
|
50
|
+
// Decode the event back
|
|
51
|
+
const decodeResult = qcsdk.decodeEventLog(
|
|
52
|
+
transferABI,
|
|
53
|
+
"Transfer",
|
|
54
|
+
encodeResult.result.topics,
|
|
55
|
+
encodeResult.result.data
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
if (decodeResult.error) {
|
|
59
|
+
console.error("Decode error:", decodeResult.error);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const decoded = JSON.parse(decodeResult.result);
|
|
64
|
+
console.log("\nDecoded Transfer Event:");
|
|
65
|
+
console.log(" From:", decoded.from);
|
|
66
|
+
console.log(" To:", decoded.to);
|
|
67
|
+
console.log(" Value:", decoded.value);
|
|
68
|
+
console.log(" Verification:",
|
|
69
|
+
decoded.from.toLowerCase() === fromAddress.toLowerCase() &&
|
|
70
|
+
decoded.to.toLowerCase() === toAddress.toLowerCase() &&
|
|
71
|
+
decoded.value === value ? "✓ Match" : "✗ Mismatch"
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Example 2: Event with All Indexed Parameters
|
|
77
|
+
* Approval(address indexed owner, address indexed spender, uint256 indexed value)
|
|
78
|
+
*/
|
|
79
|
+
async function example2_AllIndexedEvent() {
|
|
80
|
+
console.log("\n=== Example 2: All Indexed Event (Approval) ===");
|
|
81
|
+
|
|
82
|
+
const approvalABI = JSON.stringify([{
|
|
83
|
+
"name": "Approval",
|
|
84
|
+
"type": "event",
|
|
85
|
+
"anonymous": false,
|
|
86
|
+
"inputs": [
|
|
87
|
+
{"name": "owner", "type": "address", "indexed": true},
|
|
88
|
+
{"name": "spender", "type": "address", "indexed": true},
|
|
89
|
+
{"name": "value", "type": "uint256", "indexed": true}
|
|
90
|
+
]
|
|
91
|
+
}]);
|
|
92
|
+
|
|
93
|
+
const owner = "0xd51773b5dde3f8e4d29ae42b5046510e2a11fd0c8e4175853d6227896eb445c6";
|
|
94
|
+
const spender = "0x1Bd75060B22686a9f32Af80BC02348c1BAeDBba06f47ad723885c92a6566B65d";
|
|
95
|
+
const value = "5000000000000000000"; // 5 tokens
|
|
96
|
+
|
|
97
|
+
// Encode the event
|
|
98
|
+
const encodeResult = qcsdk.encodeEventLog(approvalABI, "Approval", owner, spender, value);
|
|
99
|
+
|
|
100
|
+
if (encodeResult.error) {
|
|
101
|
+
console.error("Encode error:", encodeResult.error);
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
console.log("Encoded Approval Event:");
|
|
106
|
+
console.log(" Topics:", encodeResult.result.topics);
|
|
107
|
+
console.log(" Data:", encodeResult.result.data);
|
|
108
|
+
console.log(" Number of topics:", encodeResult.result.topics.length);
|
|
109
|
+
console.log(" Expected: 4 topics (event signature + owner + spender + value)");
|
|
110
|
+
console.log(" Data should be empty (0x) since all parameters are indexed");
|
|
111
|
+
|
|
112
|
+
// Decode the event back
|
|
113
|
+
const decodeResult = qcsdk.decodeEventLog(
|
|
114
|
+
approvalABI,
|
|
115
|
+
"Approval",
|
|
116
|
+
encodeResult.result.topics,
|
|
117
|
+
encodeResult.result.data
|
|
118
|
+
);
|
|
119
|
+
|
|
120
|
+
if (decodeResult.error) {
|
|
121
|
+
console.error("Decode error:", decodeResult.error);
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const decoded = JSON.parse(decodeResult.result);
|
|
126
|
+
console.log("\nDecoded Approval Event:");
|
|
127
|
+
console.log(" Owner:", decoded.owner);
|
|
128
|
+
console.log(" Spender:", decoded.spender);
|
|
129
|
+
console.log(" Value:", decoded.value);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Example 3: Event with All Non-Indexed Parameters
|
|
134
|
+
* ValueChanged(uint256 newValue, string message)
|
|
135
|
+
*/
|
|
136
|
+
async function example3_AllNonIndexedEvent() {
|
|
137
|
+
console.log("\n=== Example 3: All Non-Indexed Event ===");
|
|
138
|
+
|
|
139
|
+
const valueChangedABI = JSON.stringify([{
|
|
140
|
+
"name": "ValueChanged",
|
|
141
|
+
"type": "event",
|
|
142
|
+
"anonymous": false,
|
|
143
|
+
"inputs": [
|
|
144
|
+
{"name": "newValue", "type": "uint256", "indexed": false},
|
|
145
|
+
{"name": "message", "type": "string", "indexed": false}
|
|
146
|
+
]
|
|
147
|
+
}]);
|
|
148
|
+
|
|
149
|
+
const newValue = "42";
|
|
150
|
+
const message = "Hello, Quantum Coin!";
|
|
151
|
+
|
|
152
|
+
// Encode the event
|
|
153
|
+
const encodeResult = qcsdk.encodeEventLog(valueChangedABI, "ValueChanged", newValue, message);
|
|
154
|
+
|
|
155
|
+
if (encodeResult.error) {
|
|
156
|
+
console.error("Encode error:", encodeResult.error);
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
console.log("Encoded ValueChanged Event:");
|
|
161
|
+
console.log(" Topics:", encodeResult.result.topics);
|
|
162
|
+
console.log(" Data:", encodeResult.result.data);
|
|
163
|
+
console.log(" Number of topics:", encodeResult.result.topics.length);
|
|
164
|
+
console.log(" Expected: 1 topic (event signature only)");
|
|
165
|
+
console.log(" Data contains both parameters");
|
|
166
|
+
|
|
167
|
+
// Decode the event back
|
|
168
|
+
const decodeResult = qcsdk.decodeEventLog(
|
|
169
|
+
valueChangedABI,
|
|
170
|
+
"ValueChanged",
|
|
171
|
+
encodeResult.result.topics,
|
|
172
|
+
encodeResult.result.data
|
|
173
|
+
);
|
|
174
|
+
|
|
175
|
+
if (decodeResult.error) {
|
|
176
|
+
console.error("Decode error:", decodeResult.error);
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const decoded = JSON.parse(decodeResult.result);
|
|
181
|
+
console.log("\nDecoded ValueChanged Event:");
|
|
182
|
+
console.log(" New Value:", decoded.newValue);
|
|
183
|
+
console.log(" Message:", decoded.message);
|
|
184
|
+
console.log(" Verification:",
|
|
185
|
+
decoded.newValue === newValue &&
|
|
186
|
+
decoded.message === message ? "✓ Match" : "✗ Mismatch"
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Example 4: Event with Indexed String
|
|
192
|
+
* StringEvent(string indexed message)
|
|
193
|
+
* Note: Indexed strings are hashed, so we can't recover the original value
|
|
194
|
+
*/
|
|
195
|
+
async function example4_IndexedStringEvent() {
|
|
196
|
+
console.log("\n=== Example 4: Indexed String Event ===");
|
|
197
|
+
|
|
198
|
+
const stringEventABI = JSON.stringify([{
|
|
199
|
+
"name": "StringEvent",
|
|
200
|
+
"type": "event",
|
|
201
|
+
"anonymous": false,
|
|
202
|
+
"inputs": [
|
|
203
|
+
{"name": "message", "type": "string", "indexed": true}
|
|
204
|
+
]
|
|
205
|
+
}]);
|
|
206
|
+
|
|
207
|
+
const message = "Hello, World!";
|
|
208
|
+
|
|
209
|
+
// Encode the event
|
|
210
|
+
const encodeResult = qcsdk.encodeEventLog(stringEventABI, "StringEvent", message);
|
|
211
|
+
|
|
212
|
+
if (encodeResult.error) {
|
|
213
|
+
console.error("Encode error:", encodeResult.error);
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
console.log("Encoded StringEvent:");
|
|
218
|
+
console.log(" Original message:", message);
|
|
219
|
+
console.log(" Topics:", encodeResult.result.topics);
|
|
220
|
+
console.log(" Data:", encodeResult.result.data);
|
|
221
|
+
console.log(" Number of topics:", encodeResult.result.topics.length);
|
|
222
|
+
console.log(" Expected: 2 topics (event signature + hashed string)");
|
|
223
|
+
|
|
224
|
+
// Decode the event back
|
|
225
|
+
const decodeResult = qcsdk.decodeEventLog(
|
|
226
|
+
stringEventABI,
|
|
227
|
+
"StringEvent",
|
|
228
|
+
encodeResult.result.topics,
|
|
229
|
+
encodeResult.result.data
|
|
230
|
+
);
|
|
231
|
+
|
|
232
|
+
if (decodeResult.error) {
|
|
233
|
+
console.error("Decode error:", decodeResult.error);
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
const decoded = JSON.parse(decodeResult.result);
|
|
238
|
+
console.log("\nDecoded StringEvent:");
|
|
239
|
+
console.log(" Message (hash):", decoded.message);
|
|
240
|
+
console.log(" Note: Indexed strings return the hash, not the original value");
|
|
241
|
+
console.log(" This is expected behavior for indexed dynamic types");
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Example 5: Anonymous Event
|
|
246
|
+
* AnonymousEvent(uint256 value)
|
|
247
|
+
*/
|
|
248
|
+
async function example5_AnonymousEvent() {
|
|
249
|
+
console.log("\n=== Example 5: Anonymous Event ===");
|
|
250
|
+
|
|
251
|
+
const anonymousABI = JSON.stringify([{
|
|
252
|
+
"name": "AnonymousEvent",
|
|
253
|
+
"type": "event",
|
|
254
|
+
"anonymous": true,
|
|
255
|
+
"inputs": [
|
|
256
|
+
{"name": "value", "type": "uint256", "indexed": false}
|
|
257
|
+
]
|
|
258
|
+
}]);
|
|
259
|
+
|
|
260
|
+
const value = "12345";
|
|
261
|
+
|
|
262
|
+
// Encode the event
|
|
263
|
+
const encodeResult = qcsdk.encodeEventLog(anonymousABI, "AnonymousEvent", value);
|
|
264
|
+
|
|
265
|
+
if (encodeResult.error) {
|
|
266
|
+
console.error("Encode error:", encodeResult.error);
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
console.log("Encoded AnonymousEvent:");
|
|
271
|
+
console.log(" Topics:", encodeResult.result.topics);
|
|
272
|
+
console.log(" Data:", encodeResult.result.data);
|
|
273
|
+
console.log(" Number of topics:", encodeResult.result.topics.length);
|
|
274
|
+
console.log(" Expected: 0 topics (anonymous events have no signature topic)");
|
|
275
|
+
|
|
276
|
+
// Decode the event back
|
|
277
|
+
const decodeResult = qcsdk.decodeEventLog(
|
|
278
|
+
anonymousABI,
|
|
279
|
+
"AnonymousEvent",
|
|
280
|
+
encodeResult.result.topics,
|
|
281
|
+
encodeResult.result.data
|
|
282
|
+
);
|
|
283
|
+
|
|
284
|
+
if (decodeResult.error) {
|
|
285
|
+
console.error("Decode error:", decodeResult.error);
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
const decoded = JSON.parse(decodeResult.result);
|
|
290
|
+
console.log("\nDecoded AnonymousEvent:");
|
|
291
|
+
console.log(" Value:", decoded.value);
|
|
292
|
+
console.log(" Verification:", decoded.value === value ? "✓ Match" : "✗ Mismatch");
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* Example 6: Complex Event with Mixed Types
|
|
297
|
+
* ComplexEvent(address indexed owner, uint256 indexed tokenId, string name, uint256[] amounts)
|
|
298
|
+
*/
|
|
299
|
+
async function example6_ComplexEvent() {
|
|
300
|
+
console.log("\n=== Example 6: Complex Event with Mixed Types ===");
|
|
301
|
+
|
|
302
|
+
const complexABI = JSON.stringify([{
|
|
303
|
+
"name": "ComplexEvent",
|
|
304
|
+
"type": "event",
|
|
305
|
+
"anonymous": false,
|
|
306
|
+
"inputs": [
|
|
307
|
+
{"name": "owner", "type": "address", "indexed": true},
|
|
308
|
+
{"name": "tokenId", "type": "uint256", "indexed": true},
|
|
309
|
+
{"name": "name", "type": "string", "indexed": false},
|
|
310
|
+
{"name": "amounts", "type": "uint256[]", "indexed": false}
|
|
311
|
+
]
|
|
312
|
+
}]);
|
|
313
|
+
|
|
314
|
+
const owner = "0xd51773b5dde3f8e4d29ae42b5046510e2a11fd0c8e4175853d6227896eb445c6";
|
|
315
|
+
const tokenId = "1";
|
|
316
|
+
const name = "My Token";
|
|
317
|
+
const amounts = ["100", "200", "300"];
|
|
318
|
+
|
|
319
|
+
// Encode the event
|
|
320
|
+
const encodeResult = qcsdk.encodeEventLog(complexABI, "ComplexEvent", owner, tokenId, name, amounts);
|
|
321
|
+
|
|
322
|
+
if (encodeResult.error) {
|
|
323
|
+
console.error("Encode error:", encodeResult.error);
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
console.log("Encoded ComplexEvent:");
|
|
328
|
+
console.log(" Topics:", encodeResult.result.topics);
|
|
329
|
+
console.log(" Data:", encodeResult.result.data);
|
|
330
|
+
console.log(" Number of topics:", encodeResult.result.topics.length);
|
|
331
|
+
console.log(" Expected: 3 topics (event signature + owner + tokenId)");
|
|
332
|
+
console.log(" Data contains name and amounts array");
|
|
333
|
+
|
|
334
|
+
// Decode the event back
|
|
335
|
+
const decodeResult = qcsdk.decodeEventLog(
|
|
336
|
+
complexABI,
|
|
337
|
+
"ComplexEvent",
|
|
338
|
+
encodeResult.result.topics,
|
|
339
|
+
encodeResult.result.data
|
|
340
|
+
);
|
|
341
|
+
|
|
342
|
+
if (decodeResult.error) {
|
|
343
|
+
console.error("Decode error:", decodeResult.error);
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
const decoded = JSON.parse(decodeResult.result);
|
|
348
|
+
console.log("\nDecoded ComplexEvent:");
|
|
349
|
+
console.log(" Owner:", decoded.owner);
|
|
350
|
+
console.log(" Token ID:", decoded.tokenId);
|
|
351
|
+
console.log(" Name:", decoded.name);
|
|
352
|
+
console.log(" Amounts:", decoded.amounts);
|
|
353
|
+
console.log(" Verification:",
|
|
354
|
+
decoded.owner.toLowerCase() === owner.toLowerCase() &&
|
|
355
|
+
decoded.tokenId === tokenId &&
|
|
356
|
+
decoded.name === name &&
|
|
357
|
+
JSON.stringify(decoded.amounts) === JSON.stringify(amounts) ? "✓ Match" : "✗ Mismatch"
|
|
358
|
+
);
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* Main function to run all examples
|
|
363
|
+
*/
|
|
364
|
+
async function runExamples() {
|
|
365
|
+
console.log("==========================================");
|
|
366
|
+
console.log("Event Log Encode/Decode Examples");
|
|
367
|
+
console.log("==========================================");
|
|
368
|
+
|
|
369
|
+
try {
|
|
370
|
+
// Initialize SDK
|
|
371
|
+
await qcsdk.initialize(clientConfigVal);
|
|
372
|
+
console.log("SDK initialized successfully");
|
|
373
|
+
|
|
374
|
+
// Run examples
|
|
375
|
+
await example1_TransferEvent();
|
|
376
|
+
await example2_AllIndexedEvent();
|
|
377
|
+
await example3_AllNonIndexedEvent();
|
|
378
|
+
await example4_IndexedStringEvent();
|
|
379
|
+
await example5_AnonymousEvent();
|
|
380
|
+
await example6_ComplexEvent();
|
|
381
|
+
|
|
382
|
+
console.log("\n==========================================");
|
|
383
|
+
console.log("All examples completed successfully!");
|
|
384
|
+
console.log("==========================================");
|
|
385
|
+
} catch (error) {
|
|
386
|
+
console.error("Error running examples:", error);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
// Run the examples
|
|
391
|
+
runExamples().catch(console.error);
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
const qcsdk = require('quantum-coin-js-sdk');
|
|
2
|
+
const ethers = require('ethers');
|
|
3
|
+
|
|
4
|
+
var clientConfigVal = new qcsdk.Config("https://sdk.readrelay.quantumcoinapi.com", "https://sdk.writerelay.quantumcoinapi.com", 123123, "", ""); //Mainnet
|
|
5
|
+
|
|
6
|
+
//Initialize the client configuration
|
|
7
|
+
//var clientConfigVal = new qcsdk.Config("https://t4-relayread.quantumcoin.org", "https://t4-relaywrite.quantumcoin.org", 310324, "", ""); //Testnet T4
|
|
8
|
+
//Testnet T4 Block Explorer: https://t4.scan.quantumcoin.org
|
|
9
|
+
|
|
10
|
+
//For mainnet, use the following configuration
|
|
11
|
+
//var clientConfigVal = new qcsdk.Config("https://sdk.readrelay.quantumcoinapi.com", "https://sdk.writerelay.quantumcoinapi.com", 123123, "", ""); //Mainnet
|
|
12
|
+
//Mainnet Block Explorer: https://scan.quantumcoin.org
|
|
13
|
+
|
|
14
|
+
//Local testing configuration
|
|
15
|
+
//var clientConfigVal = new qcsdk.Config("http://127.0.0.1:9090", "http://127.0.0.1:9091", 123123, "", ""); //local testing
|
|
16
|
+
//Mainnet Block Explorer: https://scan.quantumcoin.org
|
|
17
|
+
|
|
18
|
+
//Initialize the SDK
|
|
19
|
+
qcsdk.initialize(clientConfigVal).then((initResult) => {
|
|
20
|
+
if (initResult === false) {
|
|
21
|
+
console.error("Initialize failed");
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const digestHashBase64 = "aGkgdGhlcmVvY2tjaGFpbmJiYmJiYmJiYmJiYmJiYmI=";
|
|
26
|
+
const signatureBase64 = "fg/+CQEgj/gs+rQL9EynRPosPfAk/8XFkxXNALhOcGc4Eb+iRddo8oDfbPMZHEiBWUxeA0urzOZo9eQ388HCdzO5F/2sDp2HvJxC37bSoHGooKHqtRuCEWkdsd5w+GDImLOJVMyU9bJ9kCxX6My1f5DMJ62+S9A1ngh3oZyufnYe9A4h7PaC7zU1uBsBiEdCc9/ao10qlpAws0gdRMyXswdNWv4TrTvqASf+AohIpumz/MUfLSw0gfygjq8KWWMG+IBt4pLFv81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MDGRNiwq+0045EhWjrE7/nvcSNpcldBorI25BCMP3fs7iEnJlcmbak2JPJ0c/8DvE0d+ubfk2HXJW2+MzH/ovA7oxDFay7Et4Y1RqXwqaR21bS3Oq2L2LbVPPU463nGZ+sOPioOr+zw/sHAtA7k/oD3F+z5Pq+9F0lq/PBDv1TECIcQ+LCu4u73NRxyjTDWlwZxH3sryDL14iqhuiFxVcgTJ4GJfMO7SfSJh36TqjOazpNF8j1KtS3IjbNXg80CtxRhR11aK7R6uOG7cFu/g88MaVYFIjirnV8OW7kWngbslvr7/H9J+52/Z+AmUs31JxMlYRiVhMSwK/ROpIvUmahO8enn7spaU42I76hXjLeTawUZRx+RLb7EbCcWX4j/r4QQ92PBtCcc5wIAWEq92rG11fXS1c9Dj44hdbgOwO8XvmXdnk3Z0gWml9SeCd4J05zsaaLC3gmMD2hbG2TM/x+YQ+JzJTSZlhDdOnGPIP3+ajNJGSDeSXAKOLEZXSp544n6Wl95pJWp5QLwFaJ5299yhdDCdc8iVwQ6F+vokKOMeXF+Ey4w04Dv4gd0Or3WSplj07vd/1fkV7b0UuVpD5I3dnQ5NCaAC/kKUH0LJFT5bhOq3bhc6HHiEctbqX12TC/y4fKbS9SatisppCxpFUtJAb4GhyL7QfS4jQ50O0xUA5FMJ4l238Wxv+3rHWnbpFDj6jahYw3yUFlQ==";
|
|
27
|
+
|
|
28
|
+
let digest = base64ToBytes(digestHashBase64);
|
|
29
|
+
let signature = base64ToBytes(signatureBase64);
|
|
30
|
+
|
|
31
|
+
let publicKey = qcsdk.publicKeyFromSignature(digest, signature);
|
|
32
|
+
console.log("publicKeyFromSignature publicKey length: " + publicKey.length);
|
|
33
|
+
|
|
34
|
+
// Wallet and signing demo: use CIRCL (newWallet + hybrideds) when available
|
|
35
|
+
const g = typeof globalThis !== 'undefined' ? globalThis : typeof global !== 'undefined' ? global : {};
|
|
36
|
+
const circl = g.circl;
|
|
37
|
+
const walletExample = qcsdk.newWallet();
|
|
38
|
+
if (typeof walletExample === 'object' && walletExample != null && circl && circl.hybrideds) {
|
|
39
|
+
console.log("walletExample.privateKey length " + walletExample.privateKey.length);
|
|
40
|
+
let publicKey2 = qcsdk.publicKeyFromPrivateKey(walletExample.privateKey);
|
|
41
|
+
console.log("publicKeyFromPrivateKey publicKey length: " + publicKey2.length);
|
|
42
|
+
let publicKey2Bytes = hexToBytes(publicKey2);
|
|
43
|
+
if (publicKey2Bytes.length !== walletExample.publicKey.length) {
|
|
44
|
+
throw new Error("public key length compare failed S");
|
|
45
|
+
}
|
|
46
|
+
for (let i = 0; i < publicKey2Bytes.length; i++) {
|
|
47
|
+
if (publicKey2Bytes[i] !== walletExample.publicKey[i]) {
|
|
48
|
+
throw new Error("public key compare failed A");
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
let utf8Encode = new TextEncoder();
|
|
53
|
+
let message = utf8Encode.encode("verifyverifyverifyverifyverifyok");
|
|
54
|
+
const privU8 = walletExample.privateKey instanceof Uint8Array ? walletExample.privateKey : new Uint8Array(walletExample.privateKey);
|
|
55
|
+
const sigRes = circl.hybrideds.signCompact(privU8, message);
|
|
56
|
+
if (sigRes && sigRes.error) throw new Error("CIRCL sign failed: " + sigRes.error);
|
|
57
|
+
let quantumSig = sigRes.result instanceof Uint8Array ? Array.from(sigRes.result) : sigRes.result;
|
|
58
|
+
|
|
59
|
+
let combinedSignatureHex = qcsdk.combinePublicKeySignature(walletExample.publicKey, quantumSig);
|
|
60
|
+
if (combinedSignatureHex === null) {
|
|
61
|
+
throw new Error("combinePublicKeySignature combine failed");
|
|
62
|
+
}
|
|
63
|
+
let combinedSignatureBytes = hexToBytes(combinedSignatureHex);
|
|
64
|
+
let publicKeySigHex = qcsdk.publicKeyFromSignature(message, combinedSignatureBytes);
|
|
65
|
+
let publicKeySigBytes = hexToBytes(publicKeySigHex);
|
|
66
|
+
if (publicKeySigBytes.length !== walletExample.publicKey.length) {
|
|
67
|
+
throw new Error("public key length compare failed B");
|
|
68
|
+
}
|
|
69
|
+
for (let i = 0; i < publicKeySigBytes.length; i++) {
|
|
70
|
+
if (publicKeySigBytes[i] !== walletExample.publicKey[i]) {
|
|
71
|
+
throw new Error("public key compare failed B");
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
} else {
|
|
75
|
+
console.log("CIRCL not loaded or newWallet failed; skipping wallet/signing demo.");
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
function base64ToBytes(base64) {
|
|
80
|
+
const binString = atob(base64);
|
|
81
|
+
return Uint8Array.from(binString, (m) => m.codePointAt(0));
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Convert a hex string to a byte array
|
|
85
|
+
function hexToBytes(hex) {
|
|
86
|
+
let bytes = [];
|
|
87
|
+
for (let c = 0; c < hex.length; c += 2)
|
|
88
|
+
bytes.push(parseInt(hex.substr(c, 2), 16));
|
|
89
|
+
return bytes;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Convert a byte array to a hex string
|
|
93
|
+
function bytesToHex(bytes) {
|
|
94
|
+
let hex = [];
|
|
95
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
96
|
+
let current = bytes[i] < 0 ? bytes[i] + 256 : bytes[i];
|
|
97
|
+
hex.push((current >>> 4).toString(16));
|
|
98
|
+
hex.push((current & 0xF).toString(16));
|
|
99
|
+
}
|
|
100
|
+
return hex.join("");
|
|
101
|
+
}
|