diff --git a/.github/workflows/bundle.yml b/.github/workflows/bundle.yml index abf083da..e58fc573 100644 --- a/.github/workflows/bundle.yml +++ b/.github/workflows/bundle.yml @@ -35,12 +35,10 @@ jobs: - name: Compile run: | lerna run tsc - echo "module.exports = require('@nervosnetwork/ckb-sdk-core').default;" > ./packages/ckb-sdk-core/ckb.js - npx browserify ./packages/ckb-sdk-core/ckb.js -o ./ckb-sdk.js - npx terser --compress --mangle -o ckb-sdk.min.js -- ckb-sdk.js - + npm run build:umd + - name: Upload Files uses: actions/upload-artifact@v2 with: name: ckb-sdk-js - path: ./ckb-sdk.min.js + path: packages/ckb-sdk-core/umd/ckb-sdk.min.js diff --git a/.gitignore b/.gitignore index b4a404d1..a1b4fc9c 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,5 @@ package-lock.json # coverage coverage + +*/**/umd diff --git a/CHANGELOG.md b/CHANGELOG.md index 037146cc..564c013c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,22 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [0.102.1](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.101.0...v0.102.1) (2022-02-17) + +**Note:** Version bump only for package ckb-sdk-js + + + + + +# [0.102.0](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.101.0...v0.102.0) (2022-02-16) + +**Note:** Version bump only for package ckb-sdk-js + + + + + # [0.101.0](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.43.0...v0.101.0) (2021-10-25) diff --git a/LICENSE b/LICENSE index d1ef1557..594771f0 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2019 Nervos Foundation +Copyright (c) 2019 - 2022 Nervos Foundation Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index c5677d60..ac50df43 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ JavaScript SDK for Nervos [CKB](https://github.com/nervosnetwork/ckb). -The ckb-sdk-js is still under development and NOT production ready. You should get familiar with CKB transaction structure and RPC before using it. +The ckb-sdk-js is still under development and aim for providing low-level APIs of data construction. You should get familiar with CKB transaction structure and RPCs before using it and design your own DApp SDK based on this one.
ToC diff --git a/lerna.json b/lerna.json index 65083de0..44293f30 100644 --- a/lerna.json +++ b/lerna.json @@ -4,5 +4,5 @@ ], "npmClient": "yarn", "useWorkspaces": true, - "version": "0.101.0" + "version": "0.102.1" } diff --git a/package.json b/package.json index 88e80e21..b121dbd4 100644 --- a/package.json +++ b/package.json @@ -9,8 +9,9 @@ "tsc": "lerna run tsc", "cm": "git-cz", "build:lib": "lerna run tsc", + "build:umd": "./scripts/bundle-umd.sh", "clean:lib": "rimraf **/packages/*/lib", - "docs": "typedoc --out docs --mode file --includes packages --name CKB-SDK.js --includeDeclarations --excludeExternals --ignoreCompilerErrors --theme default --readme README.md", + "docs": "typedoc --out docs --entryPointStrategy packages 'packages/*' --name CKB-SDK.js --excludeExternals --theme default --readme README.md", "publish": "lerna run tsc && lerna publish --from-package", "test": "jest --coverage" }, diff --git a/packages/ckb-sdk-core/CHANGELOG.md b/packages/ckb-sdk-core/CHANGELOG.md index 21f8d237..a05d753d 100644 --- a/packages/ckb-sdk-core/CHANGELOG.md +++ b/packages/ckb-sdk-core/CHANGELOG.md @@ -3,6 +3,22 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [0.102.1](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.101.0...v0.102.1) (2022-02-17) + +**Note:** Version bump only for package @nervosnetwork/ckb-sdk-core + + + + + +# [0.102.0](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.101.0...v0.102.0) (2022-02-16) + +**Note:** Version bump only for package @nervosnetwork/ckb-sdk-core + + + + + # [0.101.0](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.43.0...v0.101.0) (2021-10-25) diff --git a/packages/ckb-sdk-core/package.json b/packages/ckb-sdk-core/package.json index 2cbb4dc8..485bd77a 100644 --- a/packages/ckb-sdk-core/package.json +++ b/packages/ckb-sdk-core/package.json @@ -1,6 +1,6 @@ { "name": "@nervosnetwork/ckb-sdk-core", - "version": "0.101.0", + "version": "0.102.1", "description": "JavaScript SDK for Nervos Network CKB Project", "author": "Nervos ", "homepage": "https://github.com/nervosnetwork/ckb-sdk-js#readme", @@ -9,10 +9,12 @@ "typings": "lib/index.d.ts", "directories": { "lib": "lib", + "umd": "umd", "test": "__tests__" }, "files": [ "lib", + "umd", "types" ], "publishConfig": { @@ -31,10 +33,10 @@ "url": "https://github.com/nervosnetwork/ckb-sdk-js/issues" }, "dependencies": { - "@nervosnetwork/ckb-sdk-rpc": "0.101.0", - "@nervosnetwork/ckb-sdk-utils": "0.101.0", - "@nervosnetwork/ckb-types": "0.101.0", + "@nervosnetwork/ckb-sdk-rpc": "0.102.1", + "@nervosnetwork/ckb-sdk-utils": "0.102.1", + "@nervosnetwork/ckb-types": "0.102.1", "tslib": "2.3.1" }, - "gitHead": "19434575f22752458bfcce58f68faae483daa23d" + "gitHead": "78ef8aea8ca68f25528c8eb3aed4506ea4a37241" } diff --git a/packages/ckb-sdk-core/src/index.ts b/packages/ckb-sdk-core/src/index.ts index a1431ed0..96662a38 100644 --- a/packages/ckb-sdk-core/src/index.ts +++ b/packages/ckb-sdk-core/src/index.ts @@ -130,6 +130,80 @@ class CKB { } } + /** + * @description Generate a raw transaction object to sign + * @param {object} txObject, 1-1 tx or m-n tx + * @returns rawTxToSign + * @example 1-1 tx + *``` + * { + * fromAddress: Address, specify the address of inputs + * toAddress: Address, specify the address included in outputs + * capacity: Capacity, specify the value to transfer in this tx + * + * cells?: Array, provide + * live cells to generate input cells in this tx + * + * fee?: Fee, specify the fee or fee reconciler + * along with this tx, fee reconciler allows + * fee calculation on the fly + * + * safeMode: boolean, specify whether to skip cell + * containing data or type script or not, + * default to be true + * + * deps: DepCellInfo | Array + * specify deps included in this tx, filling + * in the `cellDeps` field of a raw tx + * + * capacityThreshold?: Capacity, specify the minimal capacity of + * each outputs, default to be 6_100_000_000 + * shannon(61 CKB) for a bare cell + * + * changeThreshold?: Capacity, specify the minimal capacity of + * the change cell, default to be 6_100_000_000 + * shannon(61 CKB) for a bare cell, useful on + * sending a tx without change by setting it 0 + * + * changeLockScript?: CKBComponents.Script, specify the change + * receiver of this tx, default to be the owner + * of the first input + * + * witnesses?: Array + * specify the witness list of this tx + * + * outputsData?: Array, specify the output data list + * of this tx + * } + * ``` + * @example m-n tx + * ``` + * { + * fromAddresses: Address[], specify the address of inputs + * + * receivePairs: Array<{ + * address: Address; + * capacity: Capacity; + * type?: CKBComponents.Script | null + * }> + * specify address, capacity and type lock + * of outputs + * + * cells: Map + * provide live cells to generate input cells + * in this tx + * + * fee?: same as that in 1-1 tx + * safeMode: same as that in 1-1 tx + * deps: same as that in 1-1 tx + * capacityThreshold?: same as that in 1-1 tx + * changeThreshold?: same as that in 1-1 tx + * changeLockScript?: same as that in 1-1 tx + * witnesses?: same as that in 1-1 tx + * outputsData?: same as that in 1-1 tx + * } + * ``` + */ public generateRawTransaction = ({ fee, safeMode = true, diff --git a/packages/ckb-sdk-rpc/CHANGELOG.md b/packages/ckb-sdk-rpc/CHANGELOG.md index 06e8ca9c..0a92b086 100644 --- a/packages/ckb-sdk-rpc/CHANGELOG.md +++ b/packages/ckb-sdk-rpc/CHANGELOG.md @@ -3,6 +3,22 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [0.102.1](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.101.0...v0.102.1) (2022-02-17) + +**Note:** Version bump only for package @nervosnetwork/ckb-sdk-rpc + + + + + +# [0.102.0](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.101.0...v0.102.0) (2022-02-16) + +**Note:** Version bump only for package @nervosnetwork/ckb-sdk-rpc + + + + + # [0.101.0](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.43.0...v0.101.0) (2021-10-25) diff --git a/packages/ckb-sdk-rpc/package.json b/packages/ckb-sdk-rpc/package.json index a3a13a5c..674f53f7 100644 --- a/packages/ckb-sdk-rpc/package.json +++ b/packages/ckb-sdk-rpc/package.json @@ -1,6 +1,6 @@ { "name": "@nervosnetwork/ckb-sdk-rpc", - "version": "0.101.0", + "version": "0.102.1", "description": "RPC module of @nervosnetwork/ckb-sdk-core", "author": "Nervos ", "homepage": "https://github.com/nervosnetwork/ckb-sdk-js/packages/ckb-rpc#readme", @@ -33,12 +33,12 @@ "url": "https://github.com/nervosnetwork/ckb-sdk-js/issues" }, "dependencies": { - "@nervosnetwork/ckb-sdk-utils": "0.101.0", + "@nervosnetwork/ckb-sdk-utils": "0.102.1", "axios": "0.21.4", "tslib": "2.3.1" }, "devDependencies": { - "@nervosnetwork/ckb-types": "0.101.0" + "@nervosnetwork/ckb-types": "0.102.1" }, - "gitHead": "19434575f22752458bfcce58f68faae483daa23d" + "gitHead": "78ef8aea8ca68f25528c8eb3aed4506ea4a37241" } diff --git a/packages/ckb-sdk-utils/CHANGELOG.md b/packages/ckb-sdk-utils/CHANGELOG.md index 65ec4e30..e7e7f120 100644 --- a/packages/ckb-sdk-utils/CHANGELOG.md +++ b/packages/ckb-sdk-utils/CHANGELOG.md @@ -3,6 +3,22 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [0.102.1](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.101.0...v0.102.1) (2022-02-17) + +**Note:** Version bump only for package @nervosnetwork/ckb-sdk-utils + + + + + +# [0.102.0](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.101.0...v0.102.0) (2022-02-16) + +**Note:** Version bump only for package @nervosnetwork/ckb-sdk-utils + + + + + # [0.101.0](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.43.0...v0.101.0) (2021-10-25) diff --git a/packages/ckb-sdk-utils/package.json b/packages/ckb-sdk-utils/package.json index ab5177d5..14852c2e 100644 --- a/packages/ckb-sdk-utils/package.json +++ b/packages/ckb-sdk-utils/package.json @@ -1,6 +1,6 @@ { "name": "@nervosnetwork/ckb-sdk-utils", - "version": "0.101.0", + "version": "0.102.1", "description": "Utils module of @nervosnetwork/ckb-sdk-core", "author": "Nervos ", "homepage": "https://github.com/nervosnetwork/ckb-sdk-js#readme", @@ -31,7 +31,7 @@ "url": "https://github.com/nervosnetwork/ckb-sdk-js/issues" }, "dependencies": { - "@nervosnetwork/ckb-types": "0.101.0", + "@nervosnetwork/ckb-types": "0.102.1", "bech32": "2.0.0", "elliptic": "6.5.4", "jsbi": "3.1.3", @@ -41,5 +41,5 @@ "@types/bitcoinjs-lib": "5.0.0", "@types/elliptic": "6.4.12" }, - "gitHead": "19434575f22752458bfcce58f68faae483daa23d" + "gitHead": "78ef8aea8ca68f25528c8eb3aed4506ea4a37241" } diff --git a/packages/ckb-types/CHANGELOG.md b/packages/ckb-types/CHANGELOG.md index adb32f50..86a5ea6e 100644 --- a/packages/ckb-types/CHANGELOG.md +++ b/packages/ckb-types/CHANGELOG.md @@ -3,6 +3,22 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [0.102.1](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.101.0...v0.102.1) (2022-02-17) + +**Note:** Version bump only for package @nervosnetwork/ckb-types + + + + + +# [0.102.0](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.101.0...v0.102.0) (2022-02-16) + +**Note:** Version bump only for package @nervosnetwork/ckb-types + + + + + # [0.101.0](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.43.0...v0.101.0) (2021-10-25) diff --git a/packages/ckb-types/package.json b/packages/ckb-types/package.json index a430d9da..cceb383d 100644 --- a/packages/ckb-types/package.json +++ b/packages/ckb-types/package.json @@ -1,6 +1,6 @@ { "name": "@nervosnetwork/ckb-types", - "version": "0.101.0", + "version": "0.102.1", "description": "Type module of @nervosnetwork/ckb-sdk-core", "author": "Nervos ", "homepage": "https://github.com/nervosnetwork/ckb-sdk-js#readme", @@ -20,8 +20,5 @@ "bugs": { "url": "https://github.com/nervosnetwork/ckb-sdk-js/issues" }, - "scripts": { - "doc": "../../node_modules/.bin/typedoc --out docs ./index.d.ts --mode modules --includeDeclarations --excludeExternals --ignoreCompilerErrors --theme default --readme README.md" - }, - "gitHead": "19434575f22752458bfcce58f68faae483daa23d" + "gitHead": "78ef8aea8ca68f25528c8eb3aed4506ea4a37241" } diff --git a/packages/ckb-types/tsconfig.json b/packages/ckb-types/tsconfig.json index da67782f..4494ad55 100644 --- a/packages/ckb-types/tsconfig.json +++ b/packages/ckb-types/tsconfig.json @@ -3,5 +3,5 @@ "compilerOptions": { "outDir": "./lib" }, - "include": ["./src"] + "files": ["index.d.ts"] } diff --git a/scripts/bundle-umd.sh b/scripts/bundle-umd.sh new file mode 100755 index 00000000..147a1c3e --- /dev/null +++ b/scripts/bundle-umd.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +BASE_DIR="packages/ckb-sdk-core/umd/" + +npx rimraf $BASE_DIR +mkdir $BASE_DIR +echo "module.exports = require('@nervosnetwork/ckb-sdk-core').default;" > "${BASE_DIR}entry.js" +npx browserify "${BASE_DIR}entry.js" -o "${BASE_DIR}ckb-sdk.js" -s CKBCore +npx terser --compress --mangle -o "${BASE_DIR}ckb-sdk.umd.js" -- "${BASE_DIR}ckb-sdk.js" +npx rimraf "${BASE_DIR}/entry.js" +npx rimraf "${BASE_DIR}/ckb-sdk.js" + diff --git a/yarn.lock b/yarn.lock index c275c2df..484a2758 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3890,9 +3890,9 @@ flatted@^3.1.0: integrity sha512-JaTY/wtrcSyvXJl4IMFHPKyFur1sE9AUqc0QnhOaJ0CxHtAoIV8pYDzeEfAaNEtGkOfq4gr3LBFmdXW5mOQFnA== follow-redirects@^1.14.0: - version "1.14.4" - resolved "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.4.tgz#838fdf48a8bbdd79e52ee51fb1c94e3ed98b9379" - integrity sha512-zwGkiSXC1MUJG/qmeIFH2HBJx9u0V46QGUe3YR1fXG8bXQxq7fLj0RjLZQ5nubr9qNJUZrH+xUcwXEoXNpfS+g== + version "1.14.8" + resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.14.8.tgz#016996fb9a11a100566398b1c6839337d7bfa8fc" + integrity sha512-1x0S9UVJHsQprFcEC/qnNzBLcIxsjAV905f/UkQxbclCsoTWlacCNOpQa/anodLl2uaEKFhfWOvM2Qg77+15zA== for-in@^1.0.2: version "1.0.2" @@ -5705,11 +5705,6 @@ lodash.merge@^4.6.2: resolved "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz#558aa53b43b661e1925a0afdfa36a9a1085fe57a" integrity sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ== -lodash.sortby@^4.7.0: - version "4.7.0" - resolved "https://registry.npmjs.org/lodash.sortby/-/lodash.sortby-4.7.0.tgz#edd14c824e2cc9c1e0b0a1b42bb5210516a42438" - integrity sha1-7dFMgk4sycHgsKG0K7UhBRakJDg= - lodash.template@^4.5.0: version "4.5.0" resolved "https://registry.npmjs.org/lodash.template/-/lodash.template-4.5.0.tgz#f976195cf3f347d0d5f52483569fe8031ccce8ab" @@ -6198,9 +6193,11 @@ neo-async@^2.6.0: integrity sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw== node-fetch@^2.6.1: - version "2.6.1" - resolved "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz#045bd323631f76ed2e2b55573394416b639a0052" - integrity sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw== + version "2.6.7" + resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.7.tgz#24de9fba827e3b4ae44dc8b20256a379160052ad" + integrity sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ== + dependencies: + whatwg-url "^5.0.0" node-gyp@^5.0.2: version "5.1.1" @@ -8053,13 +8050,6 @@ tough-cookie@~2.5.0: psl "^1.1.28" punycode "^2.1.1" -tr46@^2.0.2: - version "2.0.2" - resolved "https://registry.npmjs.org/tr46/-/tr46-2.0.2.tgz#03273586def1595ae08fedb38d7733cee91d2479" - integrity sha512-3n1qG+/5kg+jrbTzwAykB5yRYtQCTqOGKq5U5PE3b0a1/mzo6snDhjGS0zJVJunO0NrT3Dg1MLy5TjWP/UJppg== - dependencies: - punycode "^2.1.1" - tr46@^2.1.0: version "2.1.0" resolved "https://registry.npmjs.org/tr46/-/tr46-2.1.0.tgz#fa87aa81ca5d5941da8cbf1f9b749dc969a4e240" @@ -8067,6 +8057,11 @@ tr46@^2.1.0: dependencies: punycode "^2.1.1" +tr46@~0.0.3: + version "0.0.3" + resolved "https://registry.yarnpkg.com/tr46/-/tr46-0.0.3.tgz#8184fd347dac9cdc185992f3a6622e14b9d9ab6a" + integrity sha1-gYT9NH2snNwYWZLzpmIuFLnZq2o= + trim-newlines@^3.0.0: version "3.0.1" resolved "https://registry.yarnpkg.com/trim-newlines/-/trim-newlines-3.0.1.tgz#260a5d962d8b752425b32f3a7db0dcacd176c144" @@ -8382,6 +8377,11 @@ wcwidth@^1.0.0: dependencies: defaults "^1.0.3" +webidl-conversions@^3.0.0: + version "3.0.1" + resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-3.0.1.tgz#24534275e2a7bc6be7bc86611cc16ae0a5654871" + integrity sha1-JFNCdeKnvGvnvIZhHMFq4KVlSHE= + webidl-conversions@^5.0.0: version "5.0.0" resolved "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-5.0.0.tgz#ae59c8a00b121543a2acc65c0434f57b0fc11aff" @@ -8404,16 +8404,15 @@ whatwg-mimetype@^2.3.0: resolved "https://registry.npmjs.org/whatwg-mimetype/-/whatwg-mimetype-2.3.0.tgz#3d4b1e0312d2079879f826aff18dbeeca5960fbf" integrity sha512-M4yMwr6mAnQz76TbJm914+gPpB/nCwvZbJU28cUD6dR004SAxDLOOSUaB1JDRqLtaOV/vi0IC5lEAGFgrjGv/g== -whatwg-url@^8.0.0: - version "8.4.0" - resolved "https://registry.npmjs.org/whatwg-url/-/whatwg-url-8.4.0.tgz#50fb9615b05469591d2b2bd6dfaed2942ed72837" - integrity sha512-vwTUFf6V4zhcPkWp/4CQPr1TW9Ml6SF4lVyaIMBdJw5i6qUUJ1QWM4Z6YYVkfka0OUIzVo/0aNtGVGk256IKWw== +whatwg-url@^5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-5.0.0.tgz#966454e8765462e37644d3626f6742ce8b70965d" + integrity sha1-lmRU6HZUYuN2RNNib2dCzotwll0= dependencies: - lodash.sortby "^4.7.0" - tr46 "^2.0.2" - webidl-conversions "^6.1.0" + tr46 "~0.0.3" + webidl-conversions "^3.0.0" -whatwg-url@^8.4.0, whatwg-url@^8.5.0: +whatwg-url@^8.0.0, whatwg-url@^8.4.0, whatwg-url@^8.5.0: version "8.7.0" resolved "https://registry.npmjs.org/whatwg-url/-/whatwg-url-8.7.0.tgz#656a78e510ff8f3937bc0bcbe9f5c0ac35941b77" integrity sha512-gAojqb/m9Q8a5IV96E3fHJM70AzCkgt4uXYX2O7EmuyOnLrViCQlsEBmF9UQIu3/aeAIp2U17rtbpZWNntQqdg==