diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml index 5e15adb..6d8f6f1 100644 --- a/.github/workflows/integration-test.yml +++ b/.github/workflows/integration-test.yml @@ -68,7 +68,7 @@ jobs: - 13 - 12 sdk_ver: - - 0.7.0-beta.0 + - 0.7.0-beta.1 steps: - name: checkout @@ -89,7 +89,8 @@ jobs: - name: setup-dfx run: | - curl -L https://sdk.dfinity.org/downloads/dfx/${{ matrix.sdk_ver }}/x86_64-linux/dfx-${{ matrix.sdk_ver }}.tar.gz | sudo tar xz --strip-components 1 -C /usr/local/bin + mkdir -p ~/.local/bin + curl -L https://sdk.dfinity.org/downloads/dfx/${{ matrix.sdk_ver }}/x86_64-linux/dfx-${{ matrix.sdk_ver }}.tar.gz | tar xz --strip-components 1 -C ~/.local/bin - name: cache uses: actions/cache@v2 @@ -102,7 +103,9 @@ jobs: - name: test run: | - sudo cp dfinity/rs/target/release/ic-rosetta-api /usr/local/bin + export PATH=~/.local/bin:$PATH + + cp dfinity/rs/target/release/ic-rosetta-api ~/.local/bin cp \ dfinity/rs/rosetta-api/docker/dfx.json \ dfinity/rs/rosetta-api/ledger.did \ diff --git a/.github/workflows/protobuf-check.yml b/.github/workflows/protobuf-check.yml new file mode 100644 index 0000000..d3a4b71 --- /dev/null +++ b/.github/workflows/protobuf-check.yml @@ -0,0 +1,52 @@ +name: protobuf-check + +on: + push: + pull_request: + schedule: + - cron: "0 * * * *" + +jobs: + + protobuf-check: + name: protobuf-check + runs-on: ubuntu-latest + steps: + + - name: checkout + uses: actions/checkout@v2 + + - name: checkout-dfinity + uses: actions/checkout@v2 + with: + repository: dfinity-lab/dfinity + token: ${{ secrets.GH_TOKEN }} + path: dfinity + + - name: setup-protoc + run: | + mkdir -p ~/.local/bin + + pushd ${{ runner.temp }} + curl -L -o protoc.zip https://github.com/protocolbuffers/protobuf/releases/download/v3.13.0/protoc-3.13.0-linux-x86_64.zip + unzip protoc.zip + cp bin/protoc ~/.local/bin + popd + + - name: check + run: | + export PATH=~/.local/bin:$PATH + + pushd dfinity/rs/rosetta-api/canister + + protoc \ + --js_out \ + import_style=commonjs,binary:${{ github.workspace }}/autogen \ + --proto_path proto \ + --proto_path ../../types/base_types/proto \ + proto/types.proto \ + ../../types/base_types/proto/ic_base_types/pb/v1/types.proto + + popd + + git diff --exit-code diff --git a/.gitignore b/.gitignore index f032cd4..ee337fb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ -autogen/ dist/ node_modules/ .idea/ diff --git a/CHANGELOG.md b/CHANGELOG.md index 496ff14..f7dfccd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,10 @@ (#14) - Update offline `/construction/combine` implementation to match upstream. Breaking change. (#13) +- Support decoding `signed_transaction`. (#22) +- Support bundling for NodeJS. (#18) +- Replace some internal utils by using `@dfinity/agent`, and use `tweetnacl` for + ed25519 logic. (#16) (#17) - Test against multiple Node.js major versions. (#15) # `0.2.0` diff --git a/README.md b/README.md index 5dc5e13..0d3bccf 100644 --- a/README.md +++ b/README.md @@ -172,6 +172,23 @@ console.log(tx.amount); // // 额外的交易费用的 BigInt 值。 console.log(tx.fee); + +// The block height when the transaction was created as a BigInt. It's returned +// by /construction/metadata and a part of the /construction/payloads call. +// +// 事务创建时最新的区块高度的 BigInt 值。该值由 /construction/metadata 返回,并作为 +// /construction/payloads 调用的一部分。 +console.log(tx.last_height); + +// The source account's public key as a Buffer. +// +// 转出账户公钥的 Buffer 值。 +console.log(tx.sender_pubkey); + +// The ingress_expiry value as a BigInt, as nanoseconds since the unix epoch. +// +// ingress_expiry 的 BigInt 值,纳秒为单位的 unix 时间戳。 +console.log(tx.ingress_expiry); ``` ### Creating & using a JS bundle diff --git a/lib/session.js b/lib/session.js index 1e90977..c62fefc 100644 --- a/lib/session.js +++ b/lib/session.js @@ -1,9 +1,9 @@ const { blobToHex } = require("@dfinity/agent"); const { RosettaClient } = require("@lunarhq/rosetta-ts-client"); -const assert = require("assert").strict; +// const assert = require("assert").strict; const { key_to_pub_key, pub_key_to_address, address_to_hex } = require("./key"); const { transfer_combine } = require("./construction_combine"); -const { signed_transaction_decode } = require("./signed_transaction_decode"); +// const { signed_transaction_decode } = require("./signed_transaction_decode"); class Session extends RosettaClient { /** @@ -127,13 +127,13 @@ class Session extends RosettaClient { const combine_res = transfer_combine(src_key, payloads_res); - const tx = signed_transaction_decode(combine_res.signed_transaction); + // const tx = signed_transaction_decode(combine_res.signed_transaction); - assert(tx.from.compare(pub_key_to_address(key_to_pub_key(src_key))) === 0); - assert(tx.to.compare(dest_addr) === 0); - assert(tx.amount === count); - assert(tx.fee === (await this.suggested_fee)); - assert(tx.sender_pubkey.compare(key_to_pub_key(src_key)) === 0); + // assert(tx.from.compare(pub_key_to_address(key_to_pub_key(src_key))) === 0); + // assert(tx.to.compare(dest_addr) === 0); + // assert(tx.amount === count); + // assert(tx.fee === (await this.suggested_fee)); + // assert(tx.sender_pubkey.compare(key_to_pub_key(src_key)) === 0); const submit_res = await this.transfer_post_combine(combine_res); diff --git a/package-lock.json b/package-lock.json index 9dbe064..cf77157 100644 --- a/package-lock.json +++ b/package-lock.json @@ -86,9 +86,9 @@ } }, "@types/eslint": { - "version": "7.2.7", - "resolved": "https://registry.npmjs.org/@types/eslint/-/eslint-7.2.7.tgz", - "integrity": "sha512-EHXbc1z2GoQRqHaAT7+grxlTJ3WE2YNeD6jlpPoRc83cCoThRY+NUWjCUZaYmk51OICkPXn2hhphcWcWXgNW0Q==", + "version": "7.2.8", + "resolved": "https://registry.npmjs.org/@types/eslint/-/eslint-7.2.8.tgz", + "integrity": "sha512-RTKvBsfz0T8CKOGZMfuluDNyMFHnu5lvNr4hWEsQeHXH6FcmIDIozOyWMh36nLGMwVd5UFNXC2xztA8lln22MQ==", "dev": true, "requires": { "@types/estree": "*", @@ -496,9 +496,9 @@ } }, "caniuse-lite": { - "version": "1.0.30001204", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001204.tgz", - "integrity": "sha512-JUdjWpcxfJ9IPamy2f5JaRDCaqJOxDzOSKtbdx4rH9VivMd1vIzoPumsJa9LoMIi4Fx2BV2KZOxWhNkBjaYivQ==", + "version": "1.0.30001205", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001205.tgz", + "integrity": "sha512-TL1GrS5V6LElbitPazidkBMD9sa448bQDDLrumDqaggmKFcuU2JW1wTOHJPukAcOMtEmLcmDJEzfRrf+GjM0Og==", "dev": true }, "cbor": { @@ -623,9 +623,9 @@ "integrity": "sha512-Dj6Wk3tWyTE+Fo1rW8v0Xhwk80um6yFYKbuAxc9c3EZxIHFDYwbi34Uk42u1CdnIiVorvt4RmlSDjIPyzGC2ew==" }, "electron-to-chromium": { - "version": "1.3.701", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.701.tgz", - "integrity": "sha512-Zd9ofdIMYHYhG1gvnejQDvC/kqSeXQvtXF0yRURGxgwGqDZm9F9Fm3dYFnm5gyuA7xpXfBlzVLN1sz0FjxpKfw==", + "version": "1.3.704", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.704.tgz", + "integrity": "sha512-6cz0jvawlUe4h5AbfQWxPzb+8LzVyswGAWiGc32EJEmfj39HTQyNPkLXirc7+L4x5I6RgRkzua8Ryu5QZqc8cA==", "dev": true }, "enhanced-resolve": { diff --git a/package.json b/package.json index c14642f..20c4d49 100644 --- a/package.json +++ b/package.json @@ -19,14 +19,14 @@ }, "homepage": "https://github.com/dfinity-lab/rosetta-client", "scripts": { - "build": "webpack --entry ./index.js --mode none --output-library-type commonjs --progress --target node" + "build": "webpack --entry ./index.js --mode production --no-optimization-minimize --no-output-iife --output-library-type commonjs --progress --target node" }, "files": [ "autogen", "lib" ], "dependencies": { - "@dfinity/agent": "0.6.28", + "@dfinity/agent": "^0.6.28", "@lunarhq/rosetta-ts-client": "^1.4.8-rc3", "cbor": "^7.0.4", "crc": "^3.8.0",