1
0
mirror of https://github.com/bigchaindb/js-bigchaindb-driver.git synced 2024-06-15 17:13:18 +02:00

Compare commits

...

25 Commits

Author SHA1 Message Date
getlarge
17d3a02cb3
Release 4.3.0 2022-02-17 06:09:10 +01:00
getlarge
f9a4675726
Merge pull request #312 from bigchaindb/fet-improve-requests
feat: improve requests
2022-02-17 06:03:53 +01:00
getlarge
7a12ee7eb9
ci: extends wait delay 2022-02-16 08:17:44 +01:00
getlarge
eee8da4b78
fix: use abort-controller pkg for node <15 2022-02-16 08:17:30 +01:00
getlarge
2f3b2dbca1
ci: run BCDB node in background 2022-02-16 08:05:51 +01:00
getlarge
334a3f4d2d
Merge branch 'master' into fet-improve-requests 2022-02-16 07:59:56 +01:00
getlarge
1864f6fbb4
ci: update watched branch 2022-02-16 07:57:31 +01:00
getlarge
2ffbe99a2b
ci: create GH workflow 2022-02-16 07:56:28 +01:00
getlarge
ae13da59b4
ci: create GH action workflow 2022-02-16 07:38:57 +01:00
getlarge
30c15b962b
feat: export extra types 2022-02-15 14:13:13 +01:00
getlarge
1ba488b28f
fix: improve transaction typedefs 2022-02-15 14:13:04 +01:00
getlarge
fbc3d79d98
feat: update connection typedefs 2022-02-15 14:12:27 +01:00
getlarge
46599f5446
feat: add limit query for transaction search requests 2022-02-15 14:11:30 +01:00
getlarge
8c0c72622d
feat: ensure timeout and request are properly cleared 2022-02-15 14:10:49 +01:00
getlarge
c5fe1346b9
chore: update dependencies 2022-02-15 14:06:19 +01:00
getlarge
dc353ee5bc
chore: update lint rules 2022-02-15 08:07:38 +01:00
getlarge
38819a5934
fix: improve promises handling 2022-02-15 08:06:31 +01:00
getlarge
34289b0640
chore: update wepback config
declare Buffer as webpack plugin
2022-02-15 08:06:05 +01:00
getlarge
1f95bec2be
chore: update dev dependencies 2022-02-15 08:04:36 +01:00
getlarge
7c1e8be400
Release 4.2.2 2021-03-11 13:07:46 +01:00
getlarge
6aeece49cb
fix: improve typedefs
Signed-off-by: getlarge <ed@getlarge.eu>
2021-03-11 13:05:14 +01:00
getlarge
71a231a50a
fix: add delegateSignatureAsync method
Signed-off-by: getlarge <ed@getlarge.eu>
2021-03-11 13:04:17 +01:00
getlarge
76c877c649
Release 4.2.1 2021-03-10 16:34:41 +01:00
getlarge
f020a35ea2
fix: improve imports
Signed-off-by: getlarge <ed@getlarge.eu>
2021-03-10 16:31:43 +01:00
getlarge
9b395c14a6
fix: add missing types in package
Signed-off-by: getlarge <ed@getlarge.eu>
2021-03-10 16:15:20 +01:00
24 changed files with 481 additions and 260 deletions

View File

@ -193,7 +193,7 @@ module.exports = {
], ],
}, },
], ],
'import/no-extraneous-dependencies': ['error', { 'devDependencies': true }],
/** /**
* ES6-specific Issues * ES6-specific Issues
* (http://eslint.org/docs/rules/#ecmascript-6) * (http://eslint.org/docs/rules/#ecmascript-6)

68
.github/workflows/ci.yml vendored Normal file
View File

@ -0,0 +1,68 @@
name: CI
on:
push:
branches:
- master
paths-ignore:
- README.md
- API.md
- docs/*.rst
pull_request:
branches:
- master
types:
- ready_for_review
- opened
- reopened
- synchronize
paths-ignore:
- README.md
- API.md
- docs/*.rst
jobs:
test:
runs-on: ubuntu-latest
if: github.event_name == 'release' || github.event_name == 'push' || !github.event.pull_request.draft
timeout-minutes: 10
steps:
- name: Checkout the commit
uses: actions/checkout@v2
- name: Set up Node
uses: actions/setup-node@v2
with:
node-version: 14
- name: Cache dependencies
id: cache
uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Run BigChainDB node
run: |
echo Building and starting up docker containers
docker-compose -f ./docker-compose.yml up -d
- name: Install dependencies
env:
HUSKY_SKIP_INSTALL: 'true'
run: npm install
- name: Lint
run: npm run lint
- name: Build
run: npm run build
# ensure BCDB node is up and running
- run: sleep 20
- name: Test
run: npm run test

224
API.md
View File

@ -48,39 +48,41 @@
- [Parameters][44] - [Parameters][44]
- [delegateSignTransaction][45] - [delegateSignTransaction][45]
- [Parameters][46] - [Parameters][46]
- [ccJsonLoad][47] - [delegateSignTransactionAsync][47]
- [Parameters][48] - [Parameters][48]
- [ccJsonify][49] - [ccJsonLoad][49]
- [Parameters][50] - [Parameters][50]
- [ccJsonify][51]
- [Parameters][52]
## Ed25519Keypair ## Ed25519Keypair
[src/Ed25519Keypair.js:16-21][51] [src/Ed25519Keypair.js:16-21][53]
Type: [Object][52] Type: [Object][54]
### Parameters ### Parameters
- `seed` **[Buffer][53]?** A seed that will be used as a key derivation function - `seed` **[Buffer][55]?** A seed that will be used as a key derivation function
### Properties ### Properties
- `publicKey` **[string][54]** - `publicKey` **[string][56]**
- `privateKey` **[string][54]** - `privateKey` **[string][56]**
## Connection ## Connection
[src/connection.js:21-201][55] [src/connection.js:21-199][57]
### Parameters ### Parameters
- `nodes` - `nodes`
- `headers` **[Object][52]** Common headers for every request (optional, default `{}`) - `headers` **[Object][54]** Common headers for every request (optional, default `{}`)
- `timeout` **float** Optional timeout in secs (optional, default `DEFAULT_TIMEOUT`) - `timeout` **float** Optional timeout in secs (optional, default `DEFAULT_TIMEOUT`)
### getBlock ### getBlock
[src/connection.js:79-85][56] [src/connection.js:79-85][58]
#### Parameters #### Parameters
@ -88,7 +90,7 @@ Type: [Object][52]
### getTransaction ### getTransaction
[src/connection.js:90-96][57] [src/connection.js:90-96][59]
#### Parameters #### Parameters
@ -96,7 +98,7 @@ Type: [Object][52]
### listBlocks ### listBlocks
[src/connection.js:102-108][58] [src/connection.js:102-108][60]
#### Parameters #### Parameters
@ -105,7 +107,7 @@ Type: [Object][52]
### listOutputs ### listOutputs
[src/connection.js:114-126][59] [src/connection.js:114-126][61]
#### Parameters #### Parameters
@ -114,7 +116,7 @@ Type: [Object][52]
### listTransactions ### listTransactions
[src/connection.js:132-139][60] [src/connection.js:132-139][62]
#### Parameters #### Parameters
@ -123,7 +125,7 @@ Type: [Object][52]
### postTransaction ### postTransaction
[src/connection.js:144-146][61] [src/connection.js:144-146][63]
#### Parameters #### Parameters
@ -131,7 +133,7 @@ Type: [Object][52]
### postTransactionSync ### postTransactionSync
[src/connection.js:151-156][62] [src/connection.js:151-156][64]
#### Parameters #### Parameters
@ -139,7 +141,7 @@ Type: [Object][52]
### postTransactionAsync ### postTransactionAsync
[src/connection.js:162-167][63] [src/connection.js:161-166][65]
#### Parameters #### Parameters
@ -147,7 +149,7 @@ Type: [Object][52]
### postTransactionCommit ### postTransactionCommit
[src/connection.js:173-178][64] [src/connection.js:171-176][66]
#### Parameters #### Parameters
@ -155,7 +157,7 @@ Type: [Object][52]
### searchAssets ### searchAssets
[src/connection.js:183-189][65] [src/connection.js:181-187][67]
#### Parameters #### Parameters
@ -163,7 +165,7 @@ Type: [Object][52]
### searchMetadata ### searchMetadata
[src/connection.js:194-200][66] [src/connection.js:192-198][68]
#### Parameters #### Parameters
@ -171,65 +173,65 @@ Type: [Object][52]
## Transaction ## Transaction
[src/transaction.js:16-280][67] [src/transaction.js:16-288][69]
Construct Transactions Construct Transactions
### serializeTransactionIntoCanonicalString ### serializeTransactionIntoCanonicalString
[src/transaction.js:22-29][68] [src/transaction.js:22-29][70]
Canonically serializes a transaction into a string by sorting the keys Canonically serializes a transaction into a string by sorting the keys
#### Parameters #### Parameters
- `transaction` - `transaction`
- `null` **[Object][52]** (transaction) - `null` **[Object][54]** (transaction)
Returns **[string][54]** a canonically serialized Transaction Returns **[string][56]** a canonically serialized Transaction
### makeCreateTransaction ### makeCreateTransaction
[src/transaction.js:80-87][69] [src/transaction.js:80-87][71]
Generate a `CREATE` transaction holding the `asset`, `metadata`, and `outputs`, to be signed by Generate a `CREATE` transaction holding the `asset`, `metadata`, and `outputs`, to be signed by
the `issuers`. the `issuers`.
#### Parameters #### Parameters
- `asset` **[Object][52]** Created asset's data - `asset` **[Object][54]** Created asset's data
- `metadata` **[Object][52]** Metadata for the Transaction - `metadata` **[Object][54]** Metadata for the Transaction
- `outputs` **[Array][70]&lt;[Object][52]>** Array of Output objects to add to the Transaction. - `outputs` **[Array][72]&lt;[Object][54]>** Array of Output objects to add to the Transaction.
Think of these as the recipients of the asset after the transaction. Think of these as the recipients of the asset after the transaction.
For `CREATE` Transactions, this should usually just be a list of For `CREATE` Transactions, this should usually just be a list of
Outputs wrapping Ed25519 Conditions generated from the issuers' public Outputs wrapping Ed25519 Conditions generated from the issuers' public
keys (so that the issuers are the recipients of the created asset). keys (so that the issuers are the recipients of the created asset).
- `issuers` **...[Array][70]&lt;[string][54]>** Public key of one or more issuers to the asset being created by this - `issuers` **...[Array][72]&lt;[string][56]>** Public key of one or more issuers to the asset being created by this
Transaction. Transaction.
Note: Each of the private keys corresponding to the given public Note: Each of the private keys corresponding to the given public
keys MUST be used later (and in the same order) when signing the keys MUST be used later (and in the same order) when signing the
Transaction (`signTransaction()`). Transaction (`signTransaction()`).
Returns **[Object][52]** Unsigned transaction -- make sure to call signTransaction() on it before Returns **[Object][54]** Unsigned transaction -- make sure to call signTransaction() on it before
sending it off! sending it off!
### makeEd25519Condition ### makeEd25519Condition
[src/transaction.js:96-107][71] [src/transaction.js:96-101][73]
Create an Ed25519 Cryptocondition from an Ed25519 public key Create an Ed25519 Cryptocondition from an Ed25519 public key
to put into an Output of a Transaction to put into an Output of a Transaction
#### Parameters #### Parameters
- `publicKey` **[string][54]** base58 encoded Ed25519 public key for the recipient of the Transaction - `publicKey` **[string][56]** base58 encoded Ed25519 public key for the recipient of the Transaction
- `json` **[boolean][72]** If true returns a json object otherwise a crypto-condition type (optional, default `true`) - `json` **[boolean][74]** If true returns a json object otherwise a crypto-condition type (optional, default `true`)
Returns **[Object][52]** Ed25519 Condition (that will need to wrapped in an Output) Returns **[Object][54]** Ed25519 Condition (that will need to wrapped in an Output)
### makeOutput ### makeOutput
[src/transaction.js:117-137][73] [src/transaction.js:111-131][75]
Create an Output from a Condition. Create an Output from a Condition.
Note: Assumes the given Condition was generated from a Note: Assumes the given Condition was generated from a
@ -237,41 +239,41 @@ single public key (e.g. a Ed25519 Condition)
#### Parameters #### Parameters
- `condition` **[Object][52]** Condition (e.g. a Ed25519 Condition from `makeEd25519Condition()`) - `condition` **[Object][54]** Condition (e.g. a Ed25519 Condition from `makeEd25519Condition()`)
- `amount` **[string][54]** Amount of the output (optional, default `'1'`) - `amount` **[string][56]** Amount of the output (optional, default `'1'`)
Returns **[Object][52]** An Output usable in a Transaction Returns **[Object][54]** An Output usable in a Transaction
### makeSha256Condition ### makeSha256Condition
[src/transaction.js:145-153][74] [src/transaction.js:139-143][76]
Create a Preimage-Sha256 Cryptocondition from a secret to put into an Output of a Transaction Create a Preimage-Sha256 Cryptocondition from a secret to put into an Output of a Transaction
#### Parameters #### Parameters
- `preimage` **[string][54]** Preimage to be hashed and wrapped in a crypto-condition - `preimage` **[string][56]** Preimage to be hashed and wrapped in a crypto-condition
- `json` **[boolean][72]** If true returns a json object otherwise a crypto-condition type (optional, default `true`) - `json` **[boolean][74]** If true returns a json object otherwise a crypto-condition type (optional, default `true`)
Returns **[Object][52]** Preimage-Sha256 Condition (that will need to wrapped in an Output) Returns **[Object][54]** Preimage-Sha256 Condition (that will need to wrapped in an Output)
### makeThresholdCondition ### makeThresholdCondition
[src/transaction.js:162-176][75] [src/transaction.js:152-162][77]
Create an Sha256 Threshold Cryptocondition from threshold to put into an Output of a Transaction Create an Sha256 Threshold Cryptocondition from threshold to put into an Output of a Transaction
#### Parameters #### Parameters
- `threshold` **[number][76]** - `threshold` **[number][78]**
- `subconditions` **[Array][70]** (optional, default `[]`) - `subconditions` **[Array][72]** (optional, default `[]`)
- `json` **[boolean][72]** If true returns a json object otherwise a crypto-condition type (optional, default `true`) - `json` **[boolean][74]** If true returns a json object otherwise a crypto-condition type (optional, default `true`)
Returns **[Object][52]** Sha256 Threshold Condition (that will need to wrapped in an Output) Returns **[Object][54]** Sha256 Threshold Condition (that will need to wrapped in an Output)
### makeTransferTransaction ### makeTransferTransaction
[src/transaction.js:199-220][77] [src/transaction.js:185-206][79]
Generate a `TRANSFER` transaction holding the `asset`, `metadata`, and `outputs`, that fulfills Generate a `TRANSFER` transaction holding the `asset`, `metadata`, and `outputs`, that fulfills
the `fulfilledOutputs` of `unspentTransaction`. the `fulfilledOutputs` of `unspentTransaction`.
@ -279,26 +281,26 @@ the `fulfilledOutputs` of `unspentTransaction`.
#### Parameters #### Parameters
- `unspentOutputs` - `unspentOutputs`
- `outputs` **[Array][70]&lt;[Object][52]>** Array of Output objects to add to the Transaction. - `outputs` **[Array][72]&lt;[Object][54]>** Array of Output objects to add to the Transaction.
Think of these as the recipients of the asset after the transaction. Think of these as the recipients of the asset after the transaction.
For `TRANSFER` Transactions, this should usually just be a list of For `TRANSFER` Transactions, this should usually just be a list of
Outputs wrapping Ed25519 Conditions generated from the public keys of Outputs wrapping Ed25519 Conditions generated from the public keys of
the recipients. the recipients.
- `metadata` **[Object][52]** Metadata for the Transaction - `metadata` **[Object][54]** Metadata for the Transaction
- `unspentTransaction` **[Object][52]** Previous Transaction you have control over (i.e. can fulfill - `unspentTransaction` **[Object][54]** Previous Transaction you have control over (i.e. can fulfill
its Output Condition) its Output Condition)
- `OutputIndices` **...[number][76]** Indices of the Outputs in `unspentTransaction` that this - `OutputIndices` **...[number][78]** Indices of the Outputs in `unspentTransaction` that this
Transaction fulfills. Transaction fulfills.
Note that listed public keys listed must be used (and in Note that listed public keys listed must be used (and in
the same order) to sign the Transaction the same order) to sign the Transaction
(`signTransaction()`). (`signTransaction()`).
Returns **[Object][52]** Unsigned transaction -- make sure to call signTransaction() on it before Returns **[Object][54]** Unsigned transaction -- make sure to call signTransaction() on it before
sending it off! sending it off!
### signTransaction ### signTransaction
[src/transaction.js:233-257][78] [src/transaction.js:219-243][80]
Sign the given `transaction` with the given `privateKey`s, returning a new copy of `transaction` Sign the given `transaction` with the given `privateKey`s, returning a new copy of `transaction`
that's been signed. that's been signed.
@ -307,42 +309,56 @@ an exercise for the user.
#### Parameters #### Parameters
- `transaction` **[Object][52]** Transaction to sign. `transaction` is not modified. - `transaction` **[Object][54]** Transaction to sign. `transaction` is not modified.
- `privateKeys` **...[string][54]** Private keys associated with the issuers of the `transaction`. - `privateKeys` **...[string][56]** Private keys associated with the issuers of the `transaction`.
Looped through to iteratively sign any Input Fulfillments found in Looped through to iteratively sign any Input Fulfillments found in
the `transaction`. the `transaction`.
Returns **[Object][52]** The signed version of `transaction`. Returns **[Object][54]** The signed version of `transaction`.
### delegateSignTransaction ### delegateSignTransaction
[src/transaction.js:266-279][79] [src/transaction.js:252-265][81]
Delegate signing of the given `transaction` returning a new copy of `transaction` Delegate signing of the given `transaction` returning a new copy of `transaction`
that's been signed. that's been signed.
#### Parameters #### Parameters
- `transaction` **[Object][52]** Transaction to sign. `transaction` is not modified. - `transaction` **[Object][54]** Transaction to sign. `transaction` is not modified.
- `signFn` **[Function][80]** Function signing the transaction, expected to return the fulfillment. - `signFn` **[Function][82]** Function signing the transaction, expected to return the fulfillment.
Returns **[Object][52]** The signed version of `transaction`. Returns **[Object][54]** The signed version of `transaction`.
### delegateSignTransactionAsync
[src/transaction.js:274-287][83]
Delegate signing of the given `transaction` returning a new copy of `transaction`
that's been signed.
#### Parameters
- `transaction` **[Object][54]** Transaction to sign. `transaction` is not modified.
- `signFn` **[Function][82]** Function signing the transaction, expected to resolve the fulfillment.
Returns **[Promise][84]&lt;[Object][54]>** The signed version of `transaction`.
## ccJsonLoad ## ccJsonLoad
[src/utils/ccJsonLoad.js:14-44][81] [src/utils/ccJsonLoad.js:13-44][85]
Loads a crypto-condition class (Fulfillment or Condition) from a BigchainDB JSON object Loads a crypto-condition class (Fulfillment or Condition) from a BigchainDB JSON object
### Parameters ### Parameters
- `conditionJson` **[Object][52]** - `conditionJson` **[Object][54]**
Returns **cc.Condition** Ed25519 Condition (that will need to wrapped in an Output) Returns **cc.Condition** Ed25519 Condition (that will need to wrapped in an Output)
## ccJsonify ## ccJsonify
[src/utils/ccJsonify.js:12-65][82] [src/utils/ccJsonify.js:12-65][86]
Serializes a crypto-condition class (Condition or Fulfillment) into a BigchainDB-compatible JSON Serializes a crypto-condition class (Condition or Fulfillment) into a BigchainDB-compatible JSON
@ -350,7 +366,7 @@ Serializes a crypto-condition class (Condition or Fulfillment) into a BigchainDB
- `fulfillment` **cc.Fulfillment** base58 encoded Ed25519 public key for recipient of the Transaction - `fulfillment` **cc.Fulfillment** base58 encoded Ed25519 public key for recipient of the Transaction
Returns **[Object][52]** Ed25519 Condition (that will need to wrapped in an Output) Returns **[Object][54]** Ed25519 Condition (that will need to wrapped in an Output)
[1]: #ed25519keypair [1]: #ed25519keypair
@ -444,74 +460,82 @@ Returns **[Object][52]** Ed25519 Condition (that will need to wrapped in an Outp
[46]: #parameters-21 [46]: #parameters-21
[47]: #ccjsonload [47]: #delegatesigntransactionasync
[48]: #parameters-22 [48]: #parameters-22
[49]: #ccjsonify [49]: #ccjsonload
[50]: #parameters-23 [50]: #parameters-23
[51]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/3c76d3bb21e8cac17c3ca69cb9bf31b7fbc115ae/src/Ed25519Keypair.js#L16-L21 "Source code on GitHub" [51]: #ccjsonify
[52]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object [52]: #parameters-24
[53]: https://nodejs.org/api/buffer.html [53]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/76c877c649801f0a26351d03237e0b59c18bd3ef/src/Ed25519Keypair.js#L16-L21 "Source code on GitHub"
[54]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String [54]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
[55]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/3c76d3bb21e8cac17c3ca69cb9bf31b7fbc115ae/src/connection.js#L21-L201 "Source code on GitHub" [55]: https://nodejs.org/api/buffer.html
[56]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/3c76d3bb21e8cac17c3ca69cb9bf31b7fbc115ae/src/connection.js#L79-L85 "Source code on GitHub" [56]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
[57]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/3c76d3bb21e8cac17c3ca69cb9bf31b7fbc115ae/src/connection.js#L90-L96 "Source code on GitHub" [57]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/76c877c649801f0a26351d03237e0b59c18bd3ef/src/connection.js#L21-L199 "Source code on GitHub"
[58]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/3c76d3bb21e8cac17c3ca69cb9bf31b7fbc115ae/src/connection.js#L102-L108 "Source code on GitHub" [58]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/76c877c649801f0a26351d03237e0b59c18bd3ef/src/connection.js#L79-L85 "Source code on GitHub"
[59]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/3c76d3bb21e8cac17c3ca69cb9bf31b7fbc115ae/src/connection.js#L114-L126 "Source code on GitHub" [59]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/76c877c649801f0a26351d03237e0b59c18bd3ef/src/connection.js#L90-L96 "Source code on GitHub"
[60]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/3c76d3bb21e8cac17c3ca69cb9bf31b7fbc115ae/src/connection.js#L132-L139 "Source code on GitHub" [60]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/76c877c649801f0a26351d03237e0b59c18bd3ef/src/connection.js#L102-L108 "Source code on GitHub"
[61]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/3c76d3bb21e8cac17c3ca69cb9bf31b7fbc115ae/src/connection.js#L144-L146 "Source code on GitHub" [61]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/76c877c649801f0a26351d03237e0b59c18bd3ef/src/connection.js#L114-L126 "Source code on GitHub"
[62]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/3c76d3bb21e8cac17c3ca69cb9bf31b7fbc115ae/src/connection.js#L151-L156 "Source code on GitHub" [62]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/76c877c649801f0a26351d03237e0b59c18bd3ef/src/connection.js#L132-L139 "Source code on GitHub"
[63]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/3c76d3bb21e8cac17c3ca69cb9bf31b7fbc115ae/src/connection.js#L162-L167 "Source code on GitHub" [63]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/76c877c649801f0a26351d03237e0b59c18bd3ef/src/connection.js#L144-L146 "Source code on GitHub"
[64]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/3c76d3bb21e8cac17c3ca69cb9bf31b7fbc115ae/src/connection.js#L173-L178 "Source code on GitHub" [64]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/76c877c649801f0a26351d03237e0b59c18bd3ef/src/connection.js#L151-L156 "Source code on GitHub"
[65]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/3c76d3bb21e8cac17c3ca69cb9bf31b7fbc115ae/src/connection.js#L183-L189 "Source code on GitHub" [65]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/76c877c649801f0a26351d03237e0b59c18bd3ef/src/connection.js#L161-L166 "Source code on GitHub"
[66]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/3c76d3bb21e8cac17c3ca69cb9bf31b7fbc115ae/src/connection.js#L194-L200 "Source code on GitHub" [66]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/76c877c649801f0a26351d03237e0b59c18bd3ef/src/connection.js#L171-L176 "Source code on GitHub"
[67]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/3c76d3bb21e8cac17c3ca69cb9bf31b7fbc115ae/src/transaction.js#L16-L280 "Source code on GitHub" [67]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/76c877c649801f0a26351d03237e0b59c18bd3ef/src/connection.js#L181-L187 "Source code on GitHub"
[68]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/3c76d3bb21e8cac17c3ca69cb9bf31b7fbc115ae/src/transaction.js#L22-L29 "Source code on GitHub" [68]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/76c877c649801f0a26351d03237e0b59c18bd3ef/src/connection.js#L192-L198 "Source code on GitHub"
[69]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/3c76d3bb21e8cac17c3ca69cb9bf31b7fbc115ae/src/transaction.js#L80-L87 "Source code on GitHub" [69]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/76c877c649801f0a26351d03237e0b59c18bd3ef/src/transaction.js#L16-L288 "Source code on GitHub"
[70]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array [70]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/76c877c649801f0a26351d03237e0b59c18bd3ef/src/transaction.js#L22-L29 "Source code on GitHub"
[71]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/3c76d3bb21e8cac17c3ca69cb9bf31b7fbc115ae/src/transaction.js#L96-L107 "Source code on GitHub" [71]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/76c877c649801f0a26351d03237e0b59c18bd3ef/src/transaction.js#L80-L87 "Source code on GitHub"
[72]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean [72]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
[73]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/3c76d3bb21e8cac17c3ca69cb9bf31b7fbc115ae/src/transaction.js#L117-L137 "Source code on GitHub" [73]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/76c877c649801f0a26351d03237e0b59c18bd3ef/src/transaction.js#L96-L101 "Source code on GitHub"
[74]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/3c76d3bb21e8cac17c3ca69cb9bf31b7fbc115ae/src/transaction.js#L145-L153 "Source code on GitHub" [74]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
[75]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/3c76d3bb21e8cac17c3ca69cb9bf31b7fbc115ae/src/transaction.js#L162-L176 "Source code on GitHub" [75]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/76c877c649801f0a26351d03237e0b59c18bd3ef/src/transaction.js#L111-L131 "Source code on GitHub"
[76]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number [76]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/76c877c649801f0a26351d03237e0b59c18bd3ef/src/transaction.js#L139-L143 "Source code on GitHub"
[77]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/3c76d3bb21e8cac17c3ca69cb9bf31b7fbc115ae/src/transaction.js#L199-L220 "Source code on GitHub" [77]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/76c877c649801f0a26351d03237e0b59c18bd3ef/src/transaction.js#L152-L162 "Source code on GitHub"
[78]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/3c76d3bb21e8cac17c3ca69cb9bf31b7fbc115ae/src/transaction.js#L233-L257 "Source code on GitHub" [78]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
[79]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/3c76d3bb21e8cac17c3ca69cb9bf31b7fbc115ae/src/transaction.js#L266-L279 "Source code on GitHub" [79]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/76c877c649801f0a26351d03237e0b59c18bd3ef/src/transaction.js#L185-L206 "Source code on GitHub"
[80]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function [80]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/76c877c649801f0a26351d03237e0b59c18bd3ef/src/transaction.js#L219-L243 "Source code on GitHub"
[81]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/3c76d3bb21e8cac17c3ca69cb9bf31b7fbc115ae/src/utils/ccJsonLoad.js#L14-L44 "Source code on GitHub" [81]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/76c877c649801f0a26351d03237e0b59c18bd3ef/src/transaction.js#L252-L265 "Source code on GitHub"
[82]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/3c76d3bb21e8cac17c3ca69cb9bf31b7fbc115ae/src/utils/ccJsonify.js#L12-L65 "Source code on GitHub" [82]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function
[83]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/76c877c649801f0a26351d03237e0b59c18bd3ef/src/transaction.js#L274-L287 "Source code on GitHub"
[84]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise
[85]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/76c877c649801f0a26351d03237e0b59c18bd3ef/src/utils/ccJsonLoad.js#L13-L44 "Source code on GitHub"
[86]: https://github.com/bigchaindb/js-bigchaindb-driver/blob/76c877c649801f0a26351d03237e0b59c18bd3ef/src/utils/ccJsonify.js#L12-L65 "Source code on GitHub"

View File

@ -124,7 +124,7 @@ conn.postTransactionCommit(txSigned)
<meta charset="utf-8"> <meta charset="utf-8">
<title>BigchainDB boilerplate</title> <title>BigchainDB boilerplate</title>
<!-- Adjust version to your needs --> <!-- Adjust version to your needs -->
<script src="https://unpkg.com/bigchaindb-driver@4.0.0/dist/browser/bigchaindb-driver.window.min.js"></script> <script src="https://unpkg.com/bigchaindb-driver@4.2.0/dist/browser/bigchaindb-driver.window.min.js"></script>
<script> <script>
// BigchainDB server instance (e.g. https://example.com/api/v1/) // BigchainDB server instance (e.g. https://example.com/api/v1/)

View File

@ -1,6 +1,6 @@
{ {
"name": "bigchaindb-driver", "name": "bigchaindb-driver",
"version": "4.2.0", "version": "4.3.0",
"description": "Node.js driver for BigchainDB", "description": "Node.js driver for BigchainDB",
"homepage": "https://www.bigchaindb.com/", "homepage": "https://www.bigchaindb.com/",
"bugs": "https://github.com/bigchaindb/js-bigchaindb-driver/issues", "bugs": "https://github.com/bigchaindb/js-bigchaindb-driver/issues",
@ -11,7 +11,8 @@
"license": "Apache-2.0", "license": "Apache-2.0",
"author": "BigchainDB", "author": "BigchainDB",
"files": [ "files": [
"dist" "dist",
"types"
], ],
"main": "./dist/node/index.js", "main": "./dist/node/index.js",
"browser": "./dist/browser/bigchaindb-driver.cjs2.min.js", "browser": "./dist/browser/bigchaindb-driver.cjs2.min.js",
@ -19,6 +20,7 @@
"sideEffects": false, "sideEffects": false,
"scripts": { "scripts": {
"lint": "eslint .", "lint": "eslint .",
"lint:fix": "eslint . --fix",
"build": "npm run clean && npm run build:cjs && npm run build:dist", "build": "npm run clean && npm run build:cjs && npm run build:dist",
"build:bundle": "webpack", "build:bundle": "webpack",
"build:cjs": "cross-env BABEL_ENV=cjs babel ./src -d dist/node", "build:cjs": "cross-env BABEL_ENV=cjs babel ./src -d dist/node",
@ -35,55 +37,54 @@
"doc": "documentation build src/index.js -f md -o API.md -g --markdown-toc" "doc": "documentation build src/index.js -f md -o API.md -g --markdown-toc"
}, },
"devDependencies": { "devDependencies": {
"@ava/babel": "^1.0.1", "@ava/babel": "^2.0.0",
"@babel/cli": "^7.13.0", "@babel/cli": "^7.17.0",
"@babel/core": "^7.13.8", "@babel/core": "^7.17.2",
"@babel/eslint-parser": "^7.13.8", "@babel/eslint-parser": "^7.17.0",
"@babel/plugin-proposal-export-default-from": "^7.12.13", "@babel/plugin-proposal-export-default-from": "^7.16.7",
"@babel/plugin-proposal-object-rest-spread": "^7.13.8", "@babel/plugin-proposal-object-rest-spread": "^7.16.7",
"@babel/plugin-syntax-async-generators": "^7.8.4", "@babel/plugin-syntax-async-generators": "^7.8.4",
"@babel/plugin-transform-async-to-generator": "^7.13.0", "@babel/plugin-transform-async-to-generator": "^7.16.8",
"@babel/plugin-transform-object-assign": "^7.12.13", "@babel/plugin-transform-object-assign": "^7.16.7",
"@babel/plugin-transform-regenerator": "^7.12.13", "@babel/plugin-transform-regenerator": "^7.16.7",
"@babel/plugin-transform-runtime": "^7.13.9", "@babel/plugin-transform-runtime": "^7.17.0",
"@babel/preset-env": "^7.13.9", "@babel/preset-env": "^7.16.11",
"@babel/register": "^7.13.8", "@babel/register": "^7.17.0",
"ava": "^3.15.0", "ava": "^3.15.0",
"babel-loader": "^8.2.2", "babel-loader": "^8.2.2",
"buffer": "^6.0.3",
"codecov": "^3.8.1", "codecov": "^3.8.1",
"cross-env": "^7.0.3", "cross-env": "^7.0.3",
"documentation": "^13.1.1", "documentation": "^13.2.5",
"eslint": "^7.21.0", "eslint": "^8.9.0",
"eslint-config-airbnb-base": "^14.2.1", "eslint-config-airbnb-base": "^15.0.0",
"eslint-plugin-import": "^2.22.1", "eslint-plugin-import": "^2.25.4",
"husky": "^5.1.3", "husky": "^7.0.4",
"lint-staged": "^10.5.4", "lint-staged": "^12.3.4",
"nyc": "^15.1.0", "nyc": "^15.1.0",
"release-it": "^14.4.1", "release-it": "^14.12.4",
"rewire": "^4.0.1", "rewire": "^6.0.0",
"rimraf": "^3.0.2", "rimraf": "^3.0.2",
"sinon": "^7.3.2", "sinon": "^13.0.1",
"terser-webpack-plugin": "^4.2.3", "terser-webpack-plugin": "^5.3.1",
"webpack": "^4.46.0", "webpack": "^5.68.0",
"webpack-cli": "^4.5.0", "webpack-cli": "^4.9.2",
"webpack-concat-plugin": "^3.0.0", "webpack-merge": "^5.8.0",
"webpack-merge": "^5.7.3", "webpack-sources": "^3.2.3"
"webpack-sources": "^2.2.0"
}, },
"dependencies": { "dependencies": {
"@babel/runtime-corejs3": "^7.13.9", "@babel/runtime-corejs3": "^7.17.2",
"browser-resolve": "^1.11.3", "abort-controller": "^3.0.0",
"bs58": "^4.0.1", "bs58": "^4.0.1",
"buffer": "^6.0.3",
"clone": "^2.1.2", "clone": "^2.1.2",
"core-js": "^3.9.1", "core-js": "^3.21.0",
"crypto-conditions": "^2.1.1", "crypto-conditions": "2.2.1",
"decamelize": "^5.0.0", "decamelize": "^5.0.0",
"es6-promise": "^4.2.8", "es6-promise": "^4.2.8",
"fetch-ponyfill": "^7.1.0", "fetch-ponyfill": "^7.1.0",
"js-sha3": "^0.8.0", "js-sha3": "^0.8.0",
"json-stable-stringify": "^1.0.1", "json-stable-stringify": "^1.0.1",
"query-string": "^6.14.1", "query-string": "^7.1.1",
"sprintf-js": "^1.1.2", "sprintf-js": "^1.1.2",
"tweetnacl": "^1.0.3" "tweetnacl": "^1.0.3"
}, },

View File

@ -2,6 +2,8 @@
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0) // SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
// Code is Apache-2.0 and docs are CC-BY-4.0 // Code is Apache-2.0 and docs are CC-BY-4.0
// TODO: remove abort-controller when using Node >=15
import AbortController from 'abort-controller'
import { Promise } from 'es6-promise' import { Promise } from 'es6-promise'
import fetchPonyfill from 'fetch-ponyfill' import fetchPonyfill from 'fetch-ponyfill'
import { vsprintf } from 'sprintf-js' import { vsprintf } from 'sprintf-js'
@ -9,14 +11,14 @@ import { vsprintf } from 'sprintf-js'
import formatText from './format_text' import formatText from './format_text'
import stringifyAsQueryParam from './stringify_as_query_param' import stringifyAsQueryParam from './stringify_as_query_param'
const fetch = fetchPonyfill(Promise) const fetch = fetchPonyfill({ Promise })
export function ResponseError(message, status, requestURI) { export function ResponseError(message, status, requestURI) {
this.name = 'ResponseError' this.name = 'ResponseError'
this.message = message this.message = message
this.status = status this.status = status
this.requestURI = requestURI this.requestURI = requestURI
this.stack = (new Error()).stack this.stack = new Error().stack
} }
ResponseError.prototype = new Error() ResponseError.prototype = new Error()
@ -26,17 +28,27 @@ ResponseError.prototype = new Error()
* Timeout function following https://github.com/github/fetch/issues/175#issuecomment-284787564 * Timeout function following https://github.com/github/fetch/issues/175#issuecomment-284787564
* @param {integer} obj Source object * @param {integer} obj Source object
* @param {Promise} filter Array of key names to select or function to invoke per iteration * @param {Promise} filter Array of key names to select or function to invoke per iteration
* @param {AbortController} controller AbortController instance bound to fetch
* @return {Object} TimeoutError if the time was consumed, otherwise the Promise will be resolved * @return {Object} TimeoutError if the time was consumed, otherwise the Promise will be resolved
*/ */
function timeout(ms, promise) { function timeout(ms, promise, controller) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
setTimeout(() => { const nodeTimeout = setTimeout(() => {
controller.abort()
const errorObject = { const errorObject = {
message: 'TimeoutError' message: 'TimeoutError',
} }
reject(new Error(errorObject)) reject(new Error(errorObject))
}, ms) }, ms)
promise.then(resolve, reject) promise
.then((res) => {
clearTimeout(nodeTimeout)
resolve(res)
})
.catch((err) => {
clearTimeout(nodeTimeout)
reject(err)
})
}) })
} }
@ -88,25 +100,30 @@ function handleResponse(res) {
* @return {Promise} If requestTimeout the timeout function will be called. Otherwise resolve the * @return {Promise} If requestTimeout the timeout function will be called. Otherwise resolve the
* Promise with the handleResponse function * Promise with the handleResponse function
*/ */
export default function baseRequest(url, { export default function baseRequest(
jsonBody, url,
query, {
urlTemplateSpec, jsonBody, query, urlTemplateSpec, ...fetchConfig
...fetchConfig } = {},
} = {}, requestTimeout) { requestTimeout = 0
) {
let expandedUrl = url let expandedUrl = url
if (urlTemplateSpec != null) { if (urlTemplateSpec != null) {
if (Array.isArray(urlTemplateSpec) && urlTemplateSpec.length) { if (Array.isArray(urlTemplateSpec) && urlTemplateSpec.length) {
// Use vsprintf for the array call signature // Use vsprintf for the array call signature
expandedUrl = vsprintf(url, urlTemplateSpec) expandedUrl = vsprintf(url, urlTemplateSpec)
} else if (urlTemplateSpec && } else if (
urlTemplateSpec &&
typeof urlTemplateSpec === 'object' && typeof urlTemplateSpec === 'object' &&
Object.keys(urlTemplateSpec).length) { Object.keys(urlTemplateSpec).length
) {
expandedUrl = formatText(url, urlTemplateSpec) expandedUrl = formatText(url, urlTemplateSpec)
} else if (process.env.NODE_ENV !== 'production') { } else if (process.env.NODE_ENV !== 'production') {
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
console.warn('Supplied urlTemplateSpec was not an array or object. Ignoring...') console.warn(
'Supplied urlTemplateSpec was not an array or object. Ignoring...'
)
} }
} }
@ -124,11 +141,17 @@ export default function baseRequest(url, {
if (jsonBody != null) { if (jsonBody != null) {
fetchConfig.body = JSON.stringify(jsonBody) fetchConfig.body = JSON.stringify(jsonBody)
} }
if (requestTimeout) { if (requestTimeout) {
return timeout(requestTimeout, fetch.fetch(expandedUrl, fetchConfig)) const controller = new AbortController()
const { signal } = controller
return timeout(
requestTimeout,
fetch.fetch(expandedUrl, { ...fetchConfig, signal }),
controller
)
.then(handleResponse) .then(handleResponse)
} else { } else {
return fetch.fetch(expandedUrl, fetchConfig) return fetch.fetch(expandedUrl, fetchConfig).then(handleResponse)
.then(handleResponse)
} }
} }

View File

@ -178,10 +178,11 @@ export default class Connection {
/** /**
* @param search * @param search
*/ */
searchAssets(search) { searchAssets(search, limit = 10) {
return this._req(Connection.getApiUrls('assets'), { return this._req(Connection.getApiUrls('assets'), {
query: { query: {
search search,
limit
} }
}) })
} }
@ -189,10 +190,11 @@ export default class Connection {
/** /**
* @param search * @param search
*/ */
searchMetadata(search) { searchMetadata(search, limit = 10) {
return this._req(Connection.getApiUrls('metadata'), { return this._req(Connection.getApiUrls('metadata'), {
query: { query: {
search search,
limit
} }
}) })
} }

View File

@ -70,7 +70,7 @@ export default class Request {
const requestTimeout = timeout ? timeout - backoffTimedelta : timeout const requestTimeout = timeout ? timeout - backoffTimedelta : timeout
return baseRequest(apiUrl, requestConfig, requestTimeout) return baseRequest(apiUrl, requestConfig, requestTimeout)
.then(async (res) => { .then((res) => {
this.connectionError = null this.connectionError = null
return res.json() return res.json()
}) })
@ -111,6 +111,8 @@ export default class Request {
} }
static sleep(ms) { static sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms)) return new Promise(resolve => {
setTimeout(resolve, ms)
})
} }
} }

View File

@ -2,11 +2,13 @@
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0) // SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
// Code is Apache-2.0 and docs are CC-BY-4.0 // Code is Apache-2.0 and docs are CC-BY-4.0
import sha3 from 'js-sha3' /* eslint-disable camelcase */
import { sha3_256 } from 'js-sha3'
export default function sha256Hash(data) { export default function sha256Hash(data) {
return sha3.sha3_256 return sha3_256
.create() .create()
.update(data) .update(data)
.hex() .hex()
} }
/* eslint-enable camelcase */

View File

@ -2,11 +2,10 @@
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0) // SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
// Code is Apache-2.0 and docs are CC-BY-4.0 // Code is Apache-2.0 and docs are CC-BY-4.0
import { Buffer } from 'buffer'
import stableStringify from 'json-stable-stringify' import stableStringify from 'json-stable-stringify'
import clone from 'clone' import clone from 'clone'
import base58 from 'bs58' import base58 from 'bs58'
import cc from 'crypto-conditions' import { Ed25519Sha256, PreimageSha256, ThresholdSha256 } from 'crypto-conditions'
import ccJsonify from './utils/ccJsonify' import ccJsonify from './utils/ccJsonify'
import sha256Hash from './sha256Hash' import sha256Hash from './sha256Hash'
@ -38,13 +37,13 @@ export default class Transaction {
static makeTransactionTemplate() { static makeTransactionTemplate() {
const txTemplate = { const txTemplate = {
'id': null, id: null,
'operation': null, operation: null,
'outputs': [], outputs: [],
'inputs': [], inputs: [],
'metadata': null, metadata: null,
'asset': null, asset: null,
'version': '2.0', version: '2.0',
} }
return txTemplate return txTemplate
} }
@ -79,7 +78,7 @@ export default class Transaction {
*/ */
static makeCreateTransaction(asset, metadata, outputs, ...issuers) { static makeCreateTransaction(asset, metadata, outputs, ...issuers) {
const assetDefinition = { const assetDefinition = {
'data': asset || null, data: asset || null,
} }
const inputs = issuers.map((issuer) => Transaction.makeInputTemplate([issuer])) const inputs = issuers.map((issuer) => Transaction.makeInputTemplate([issuer]))
@ -95,15 +94,9 @@ export default class Transaction {
*/ */
static makeEd25519Condition(publicKey, json = true) { static makeEd25519Condition(publicKey, json = true) {
const publicKeyBuffer = base58.decode(publicKey) const publicKeyBuffer = base58.decode(publicKey)
const ed25519Fulfillment = new Ed25519Sha256()
const ed25519Fulfillment = new cc.Ed25519Sha256()
ed25519Fulfillment.setPublicKey(publicKeyBuffer) ed25519Fulfillment.setPublicKey(publicKeyBuffer)
return json ? ccJsonify(ed25519Fulfillment) : ed25519Fulfillment
if (json) {
return ccJsonify(ed25519Fulfillment)
}
return ed25519Fulfillment
} }
/** /**
@ -131,8 +124,8 @@ export default class Transaction {
getPublicKeys(condition.details) getPublicKeys(condition.details)
return { return {
condition, condition,
'amount': amount, amount,
'public_keys': publicKeys, public_keys: publicKeys,
} }
} }
@ -143,13 +136,9 @@ export default class Transaction {
* @returns {Object} Preimage-Sha256 Condition (that will need to wrapped in an Output) * @returns {Object} Preimage-Sha256 Condition (that will need to wrapped in an Output)
*/ */
static makeSha256Condition(preimage, json = true) { static makeSha256Condition(preimage, json = true) {
const sha256Fulfillment = new cc.PreimageSha256() const sha256Fulfillment = new PreimageSha256()
sha256Fulfillment.setPreimage(Buffer.from(preimage)) sha256Fulfillment.setPreimage(Buffer.from(preimage))
return json ? ccJsonify(sha256Fulfillment) : sha256Fulfillment
if (json) {
return ccJsonify(sha256Fulfillment)
}
return sha256Fulfillment
} }
/** /**
@ -160,20 +149,15 @@ export default class Transaction {
* @returns {Object} Sha256 Threshold Condition (that will need to wrapped in an Output) * @returns {Object} Sha256 Threshold Condition (that will need to wrapped in an Output)
*/ */
static makeThresholdCondition(threshold, subconditions = [], json = true) { static makeThresholdCondition(threshold, subconditions = [], json = true) {
const thresholdCondition = new cc.ThresholdSha256() const thresholdCondition = new ThresholdSha256()
thresholdCondition.setThreshold(threshold) thresholdCondition.setThreshold(threshold)
subconditions.forEach((subcondition) => { subconditions.forEach((subcondition) => {
// TODO: add support for Condition // TODO: add support for Condition
thresholdCondition.addSubfulfillment(subcondition) thresholdCondition.addSubfulfillment(subcondition)
// ? Should be thresholdCondition.addSubcondition(subcondition) // ? Should be thresholdCondition.addSubcondition(subcondition)
}) })
if (json) { return json ? ccJsonify(thresholdCondition) : thresholdCondition
return ccJsonify(thresholdCondition)
}
return thresholdCondition
} }
/** /**
@ -206,15 +190,15 @@ export default class Transaction {
const { tx, outputIndex } = { tx: unspentOutput.tx, outputIndex: unspentOutput.output_index } const { tx, outputIndex } = { tx: unspentOutput.tx, outputIndex: unspentOutput.output_index }
const fulfilledOutput = tx.outputs[outputIndex] const fulfilledOutput = tx.outputs[outputIndex]
const transactionLink = { const transactionLink = {
'output_index': outputIndex, output_index: outputIndex,
'transaction_id': tx.id, transaction_id: tx.id,
} }
return Transaction.makeInputTemplate(fulfilledOutput.public_keys, transactionLink) return Transaction.makeInputTemplate(fulfilledOutput.public_keys, transactionLink)
}) })
const assetLink = { const assetLink = {
'id': unspentOutputs[0].tx.operation === 'CREATE' ? unspentOutputs[0].tx.id id: unspentOutputs[0].tx.operation === 'CREATE' ? unspentOutputs[0].tx.id
: unspentOutputs[0].tx.asset.id : unspentOutputs[0].tx.asset.id
} }
return Transaction.makeTransaction('TRANSFER', assetLink, metadata, outputs, inputs) return Transaction.makeTransaction('TRANSFER', assetLink, metadata, outputs, inputs)
@ -244,7 +228,7 @@ export default class Transaction {
.concat(input.fulfills.transaction_id) .concat(input.fulfills.transaction_id)
.concat(input.fulfills.output_index) : serializedTransaction .concat(input.fulfills.output_index) : serializedTransaction
const transactionHash = sha256Hash(transactionUniqueFulfillment) const transactionHash = sha256Hash(transactionUniqueFulfillment)
const ed25519Fulfillment = new cc.Ed25519Sha256() const ed25519Fulfillment = new Ed25519Sha256()
ed25519Fulfillment.sign(Buffer.from(transactionHash, 'hex'), privateKeyBuffer) ed25519Fulfillment.sign(Buffer.from(transactionHash, 'hex'), privateKeyBuffer)
const fulfillmentUri = ed25519Fulfillment.serializeUri() const fulfillmentUri = ed25519Fulfillment.serializeUri()
@ -278,4 +262,26 @@ export default class Transaction {
signedTx.id = sha256Hash(serializedSignedTransaction) signedTx.id = sha256Hash(serializedSignedTransaction)
return signedTx return signedTx
} }
/**
* Delegate signing of the given `transaction` returning a new copy of `transaction`
* that's been signed.
* @param {Object} transaction Transaction to sign. `transaction` is not modified.
* @param {Function} signFn Function signing the transaction, expected to resolve the fulfillment.
* @returns {Promise<Object>} The signed version of `transaction`.
*/
static async delegateSignTransactionAsync(transaction, signFn) {
const signedTx = clone(transaction)
const serializedTransaction =
Transaction.serializeTransactionIntoCanonicalString(transaction)
await Promise.all(signedTx.inputs.map(async (input, index) => {
const fulfillmentUri = await signFn(serializedTransaction, input, index)
input.fulfillment = fulfillmentUri
}))
const serializedSignedTransaction = Transaction.serializeTransactionIntoCanonicalString(signedTx)
signedTx.id = sha256Hash(serializedSignedTransaction)
return signedTx
}
} }

View File

@ -225,7 +225,7 @@ test('Get asset for text', t => {
conn.searchAssets(search) conn.searchAssets(search)
t.truthy(conn._req.calledWith( t.truthy(conn._req.calledWith(
expectedPath, expectedPath,
{ query: { search } } { query: { search, limit: 10 } }
)) ))
}) })
@ -239,6 +239,6 @@ test('Get metadata for text', t => {
conn.searchMetadata(search) conn.searchMetadata(search)
t.truthy(conn._req.calledWith( t.truthy(conn._req.calledWith(
expectedPath, expectedPath,
{ query: { search } } { query: { search, limit: 10 } }
)) ))
}) })

View File

@ -92,7 +92,8 @@ test('Fulfillment correctly formed', t => {
const msgHash = sha256Hash(msgUniqueFulfillment) const msgHash = sha256Hash(msgUniqueFulfillment)
t.truthy(validateFulfillment( t.truthy(validateFulfillment(
txSigned.inputs[0].fulfillment, txCreate.outputs[0].condition.uri, txSigned.inputs[0].fulfillment,
txCreate.outputs[0].condition.uri,
Buffer.from(msgHash, 'hex') Buffer.from(msgHash, 'hex')
)) ))
}) })
@ -115,6 +116,24 @@ test('Delegated signature is correct', t => {
t.deepEqual(signCreateTransaction, delegatedSignCreateTransaction) t.deepEqual(signCreateTransaction, delegatedSignCreateTransaction)
}) })
test('Delegated async signature is correct', async t => {
const alice = new Ed25519Keypair()
const txCreate = Transaction.makeCreateTransaction(
{},
{},
[Transaction.makeOutput(Transaction.makeEd25519Condition(alice.publicKey))],
alice.publicKey
)
const signCreateTransaction = Transaction.signTransaction(txCreate, alice.privateKey)
const delegatedSignCreateTransaction = await Transaction.delegateSignTransactionAsync(
txCreate,
delegatedSignTransaction(alice)
)
t.deepEqual(signCreateTransaction, delegatedSignCreateTransaction)
})
test('CryptoConditions JSON load', t => { test('CryptoConditions JSON load', t => {
const publicKey = '4zvwRjXUKGfvwnParsHAS3HuSVzV5cA4McphgmoCtajS' const publicKey = '4zvwRjXUKGfvwnParsHAS3HuSVzV5cA4McphgmoCtajS'
const cond = ccJsonLoad({ const cond = ccJsonLoad({

View File

@ -26,6 +26,6 @@ declare function handleResponse(res: Response): Response;
export default function baseRequest( export default function baseRequest(
url: string, url: string,
config: RequestConfig = {}, config: RequestConfig,
requestTimeout?: number requestTimeout?: number
): Promise<Response>; ): Promise<Response>;

45
types/connection.d.ts vendored
View File

@ -12,7 +12,6 @@ import type {
TransactionCommon, TransactionCommon,
} from './transaction'; } from './transaction';
declare const HEADER_BLACKLIST = ['content-type'];
declare const DEFAULT_NODE = 'http://localhost:9984/api/v1/'; declare const DEFAULT_NODE = 'http://localhost:9984/api/v1/';
declare const DEFAULT_TIMEOUT = 20000; // The default value is 20 seconds declare const DEFAULT_TIMEOUT = 20000; // The default value is 20 seconds
@ -20,6 +19,16 @@ export interface InputNode {
endpoint: string; endpoint: string;
} }
export type AssetResult = {
id: string;
data: Record<string, any>;
};
export type MetadataResult = {
id: string;
metadata: Record<string, any>;
};
export enum Endpoints { export enum Endpoints {
blocks = 'blocks', blocks = 'blocks',
blocksDetail = 'blocksDetail', blocksDetail = 'blocksDetail',
@ -77,8 +86,8 @@ export interface EndpointsResponse<
[Endpoints.transactionsDetail]: O extends TransactionOperations.CREATE [Endpoints.transactionsDetail]: O extends TransactionOperations.CREATE
? CreateTransaction<A, M> ? CreateTransaction<A, M>
: TransferTransaction<M>; : TransferTransaction<M>;
[Endpoints.assets]: { id: string; data: Record<string, any> }[]; [Endpoints.assets]: AssetResult[];
[Endpoints.metadata]: { id: string; metadata: Record<string, any> }[]; [Endpoints.metadata]: MetadataResult[];
} }
export default class Connection { export default class Connection {
@ -88,7 +97,7 @@ export default class Connection {
constructor( constructor(
nodes: string | InputNode | (string | InputNode)[], nodes: string | InputNode | (string | InputNode)[],
headers: Record<string, string | string[]> = {}, headers?: Record<string, string | string[]>,
timeout?: number timeout?: number
); );
@ -97,11 +106,11 @@ export default class Connection {
headers: Record<string, string | string[]> headers: Record<string, string | string[]>
): Node; ): Node;
static getApiUrls<E = Endpoint>(endpoint: E): EndpointsUrl[E]; static getApiUrls<E extends keyof EndpointsUrl>(endpoint: E): EndpointsUrl[E];
private _req<E = Endpoint, O = Record<string, any>>( private _req<E extends keyof EndpointsUrl, O = Record<string, any>>(
path: EndpointsUrl[E], path: EndpointsUrl[E],
options: RequestConfig = {} options: RequestConfig
): Promise<O>; ): Promise<O>;
getBlock( getBlock(
@ -112,7 +121,9 @@ export default class Connection {
transactionId: string transactionId: string
): Promise<EndpointsResponse<O>[Endpoints.transactionsDetail]>; ): Promise<EndpointsResponse<O>[Endpoints.transactionsDetail]>;
listBlocks(transactionId: string): Promise<EndpointsResponse[Endpoints.blocks]>; listBlocks(
transactionId: string
): Promise<EndpointsResponse[Endpoints.blocks]>;
listOutputs( listOutputs(
publicKey: string, publicKey: string,
@ -125,7 +136,7 @@ export default class Connection {
): Promise<EndpointsResponse<typeof operation>[Endpoints.transactions]>; ): Promise<EndpointsResponse<typeof operation>[Endpoints.transactions]>;
postTransaction< postTransaction<
O = TransactionOperations.CREATE, O extends TransactionOperations = TransactionOperations.CREATE,
A = Record<string, any>, A = Record<string, any>,
M = Record<string, any> M = Record<string, any>
>( >(
@ -133,7 +144,7 @@ export default class Connection {
): Promise<EndpointsResponse<O, A, M>[Endpoints.transactionsCommit]>; ): Promise<EndpointsResponse<O, A, M>[Endpoints.transactionsCommit]>;
postTransactionSync< postTransactionSync<
O = TransactionOperations.CREATE, O extends TransactionOperations = TransactionOperations.CREATE,
A = Record<string, any>, A = Record<string, any>,
M = Record<string, any> M = Record<string, any>
>( >(
@ -141,7 +152,7 @@ export default class Connection {
): Promise<EndpointsResponse<O, A, M>[Endpoints.transactionsSync]>; ): Promise<EndpointsResponse<O, A, M>[Endpoints.transactionsSync]>;
postTransactionAsync< postTransactionAsync<
O = TransactionOperations.CREATE, O extends TransactionOperations = TransactionOperations.CREATE,
A = Record<string, any>, A = Record<string, any>,
M = Record<string, any> M = Record<string, any>
>( >(
@ -149,14 +160,20 @@ export default class Connection {
): Promise<EndpointsResponse<O, A, M>[Endpoints.transactionsAsync]>; ): Promise<EndpointsResponse<O, A, M>[Endpoints.transactionsAsync]>;
postTransactionCommit< postTransactionCommit<
O = TransactionOperations.CREATE, O extends TransactionOperations = TransactionOperations.CREATE,
A = Record<string, any>, A = Record<string, any>,
M = Record<string, any> M = Record<string, any>
>( >(
transaction: TransactionCommon<O> transaction: TransactionCommon<O>
): Promise<EndpointsResponse<O, A, M>[Endpoints.transactionsCommit]>; ): Promise<EndpointsResponse<O, A, M>[Endpoints.transactionsCommit]>;
searchAssets(search: string): Promise<EndpointsResponse[Endpoints.assets]>; searchAssets(
search: string,
limit?: number
): Promise<EndpointsResponse[Endpoints.assets]>;
searchMetadata(search: string): Promise<EndpointsResponse[Endpoints.metadata]>; searchMetadata(
search: string,
limit?: number
): Promise<EndpointsResponse[Endpoints.metadata]>;
} }

40
types/index.d.ts vendored
View File

@ -2,10 +2,38 @@
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0) // SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
// Code is Apache-2.0 and docs are CC-BY-4.0 // Code is Apache-2.0 and docs are CC-BY-4.0
import Ed25519Keypair from './Ed25519Keypair' import Ed25519Keypair from './Ed25519Keypair';
import Connection from './connection' import Connection, {
import Transaction from './transaction' Endpoints,
import ccJsonLoad from './utils/ccJsonLoad' EndpointsResponse,
import ccJsonify from './utils/ccJsonify' EndpointsUrl,
} from './connection';
import Transaction, {
CreateTransaction,
TransactionCommon,
TransactionCommonSigned,
TransactionInput,
TransactionOutput,
TransferTransaction,
TransactionUnspentOutput,
TransactionOperations,
} from './transaction';
import ccJsonLoad from './utils/ccJsonLoad';
import ccJsonify from './utils/ccJsonify';
export { ccJsonLoad, ccJsonify, Connection, Ed25519Keypair, Transaction } export { ccJsonLoad, ccJsonify, Connection, Ed25519Keypair, Transaction };
// Extras
export {
Endpoints,
EndpointsResponse,
EndpointsUrl,
CreateTransaction,
TransactionCommon,
TransactionCommonSigned,
TransactionInput,
TransactionOutput,
TransferTransaction,
TransactionUnspentOutput,
TransactionOperations,
};

4
types/request.d.ts vendored
View File

@ -17,9 +17,9 @@ export default class Request {
constructor(node: Node); constructor(node: Node);
async request<O = Record<string, any>>( request<O = Record<string, any>>(
urlPath: string, urlPath: string,
config: RequestConfig = {}, config?: RequestConfig,
timeout?: number, timeout?: number,
maxBackoffTime?: number maxBackoffTime?: number
): Promise<O>; ): Promise<O>;

6
types/sanitize.d.ts vendored
View File

@ -6,8 +6,8 @@ declare type FilterFn = (val: any, key?: string) => void;
declare function filterFromObject<I = Record<string, any>>( declare function filterFromObject<I = Record<string, any>>(
obj: I, obj: I,
filter: Array | FilterFn, filter: Array<any> | FilterFn,
conf: { isInclusion?: boolean } = {} conf: { isInclusion?: boolean }
): Partial<I>; ): Partial<I>;
declare function applyFilterOnObject<I = Record<string, any>>( declare function applyFilterOnObject<I = Record<string, any>>(
@ -17,7 +17,7 @@ declare function applyFilterOnObject<I = Record<string, any>>(
declare function selectFromObject<I = Record<string, any>>( declare function selectFromObject<I = Record<string, any>>(
obj: I, obj: I,
filter: Array | FilterFn filter: Array<any> | FilterFn
): Partial<I>; ): Partial<I>;
export default function sanitize<I = Record<string, any>>( export default function sanitize<I = Record<string, any>>(

View File

@ -33,9 +33,9 @@ export enum TransactionOperations {
} }
export interface TransactionCommon< export interface TransactionCommon<
O = TransactionOperations, O extends TransactionOperations = TransactionOperations.CREATE,
A = Record<string, unknown>, A extends Record<string, any> = Record<string, unknown>,
M = Record<string, unknown> M extends Record<string, any> = Record<string, unknown>
> { > {
id?: string; id?: string;
inputs: TransactionInput[]; inputs: TransactionInput[];
@ -47,16 +47,16 @@ export interface TransactionCommon<
} }
export interface TransactionCommonSigned< export interface TransactionCommonSigned<
O = TransactionOperations, O extends TransactionOperations = TransactionOperations.CREATE,
A = Record<string, unknown>, A extends Record<string, any> = Record<string, unknown>,
M = Record<string, unknown> M extends Record<string, any> = Record<string, unknown>
> extends Omit<TransactionCommon<O, A, M>, 'id'> { > extends Omit<TransactionCommon<O, A, M>, 'id'> {
id: string; id: string;
} }
export type TransactionAssetMap< export type TransactionAssetMap<
Operation, Operation,
A = Record<string, unknown> A extends Record<string, any>
> = Operation extends TransactionOperations.CREATE > = Operation extends TransactionOperations.CREATE
? { ? {
data: A; data: A;
@ -66,18 +66,19 @@ export type TransactionAssetMap<
}; };
export interface CreateTransaction< export interface CreateTransaction<
A = Record<string, unknown>, A extends Record<string, any> = Record<string, unknown>,
M = Record<string, unknown> M extends Record<string, any> = Record<string, unknown>
> extends TransactionCommon<TransactionOperations.CREATE, A, M> { > extends TransactionCommon<TransactionOperations.CREATE, A, M> {
id: string; id: string;
asset: TransactionAssetMap<TransactionOperations.CREATE, A>; asset: TransactionAssetMap<TransactionOperations.CREATE, A>;
operation: TransactionOperations.CREATE; operation: TransactionOperations.CREATE;
} }
export interface TransferTransaction<M = Record<string, unknown>> export interface TransferTransaction<
extends TransactionCommon<TransactionOperations.TRANSFER, any, M> { M extends Record<string, any> = Record<string, unknown>
> extends TransactionCommon<TransactionOperations.TRANSFER, any, M> {
id: string; id: string;
asset: TransactionAssetMap<TransactionOperations.TRANSFER>; asset: TransactionAssetMap<TransactionOperations.TRANSFER, { id: string }>;
operation: TransactionOperations.TRANSFER; operation: TransactionOperations.TRANSFER;
} }
@ -96,13 +97,23 @@ interface TxTemplate {
version: '2.0'; version: '2.0';
} }
declare function DelegateSignFunction( export type DelegateSignFunction = (
serializedTransaction: string, serializedTransaction: string,
input: TransactionInput, input: TransactionInput,
index?: number index?: number
): string; ) => string;
export type DelegateSignFunctionAsync = (
serializedTransaction: string,
input: TransactionInput,
index?: number
) => Promise<string>;
export default class Transaction { export default class Transaction {
static serializeTransactionIntoCanonicalString<
O extends TransactionOperations = TransactionOperations
>(transaction: TransactionCommon<O>): string;
static serializeTransactionIntoCanonicalString( static serializeTransactionIntoCanonicalString(
transaction: CreateTransaction | TransferTransaction transaction: CreateTransaction | TransferTransaction
): string; ): string;
@ -118,7 +129,7 @@ export default class Transaction {
static makeEd25519Condition( static makeEd25519Condition(
publicKey: string, publicKey: string,
json: boolean = true json?: boolean
): Ed25519Sha256 | Ed25519Sha256JSONCondition; ): Ed25519Sha256 | Ed25519Sha256JSONCondition;
static makeSha256Condition(preimage: string): PreimageSha256JSONCondition; static makeSha256Condition(preimage: string): PreimageSha256JSONCondition;
@ -132,7 +143,7 @@ export default class Transaction {
static makeSha256Condition( static makeSha256Condition(
preimage: string, preimage: string,
json: boolean = true json?: boolean
): PreimageSha256 | PreimageSha256JSONCondition; ): PreimageSha256 | PreimageSha256JSONCondition;
static makeThresholdCondition( static makeThresholdCondition(
@ -155,7 +166,7 @@ export default class Transaction {
static makeThresholdCondition( static makeThresholdCondition(
threshold: number, threshold: number,
subconditions: (string | Fulfillment)[], subconditions: (string | Fulfillment)[],
json: boolean = true json?: boolean
): ThresholdSha256 | ThresholdSha256JSONCondition; ): ThresholdSha256 | ThresholdSha256JSONCondition;
static makeInputTemplate( static makeInputTemplate(
@ -169,13 +180,13 @@ export default class Transaction {
| PreimageSha256JSONCondition | PreimageSha256JSONCondition
| ThresholdSha256JSONCondition | ThresholdSha256JSONCondition
| Ed25519Sha256JSONCondition, | Ed25519Sha256JSONCondition,
amount: string = '1' amount?: string
): TransactionOutput; ): TransactionOutput;
static makeTransactionTemplate(): TxTemplate; static makeTransactionTemplate(): TxTemplate;
static makeTransaction< static makeTransaction<
O extends keyof TransactionOperations, O extends TransactionOperations,
A = Record<string, any>, A = Record<string, any>,
M = Record<string, any> M = Record<string, any>
>( >(
@ -202,13 +213,24 @@ export default class Transaction {
metadata: M metadata: M
): TransferTransaction<M>; ): TransferTransaction<M>;
static signTransaction<O = TransactionOperations.CREATE>( static signTransaction<
O extends TransactionOperations = TransactionOperations.CREATE
>(
transaction: TransactionCommon<O>, transaction: TransactionCommon<O>,
...privateKeys: string[] ...privateKeys: string[]
): TransactionCommonSigned<O>; ): TransactionCommonSigned<O>;
static delegateSignTransaction<O = TransactionOperations.CREATE>( static delegateSignTransaction<
O extends TransactionOperations = TransactionOperations.CREATE
>(
transaction: TransactionCommon<O>, transaction: TransactionCommon<O>,
signFn: DelegateSignFunction signFn: DelegateSignFunction
): TransactionCommonSigned<O>; ): TransactionCommonSigned<O>;
static delegateSignTransactionAsync<
O extends TransactionOperations = TransactionOperations.CREATE
>(
transaction: TransactionCommon<O>,
signFn: DelegateSignFunctionAsync
): Promise<TransactionCommonSigned<O>>;
} }

View File

@ -14,7 +14,7 @@ export default class Transport {
pickConnection(): Request; pickConnection(): Request;
async forwardRequest<O = Record<string, any>>( forwardRequest<O = Record<string, any>>(
path: string, path: string,
config: RequestConfig config: RequestConfig
): Promise<O>; ): Promise<O>;

View File

@ -8,7 +8,7 @@ import type {
PreimageSha256, PreimageSha256,
ThresholdSha256, ThresholdSha256,
} from 'crypto-conditions'; } from 'crypto-conditions';
import type { TypeId } from 'crypto-conditions/types/types'; import type { TypeId, TypeName } from 'crypto-conditions/types/types';
interface BaseJSONCondition { interface BaseJSONCondition {
details: { details: {

View File

@ -6,7 +6,8 @@
'use strict' 'use strict'
const { paths } = require('./webpack.parts.js') const { ProvidePlugin } = require('webpack')
const { paths } = require('./webpack.parts')
module.exports = { module.exports = {
entry: paths.entry, entry: paths.entry,
@ -24,10 +25,18 @@ module.exports = {
}, },
optimization: { optimization: {
minimize: true, minimize: true,
noEmitOnErrors: true emitOnErrors: false
}, },
resolve: { resolve: {
extensions: ['.js'], extensions: ['.js'],
modules: ['node_modules'], modules: ['node_modules'],
fallback: {
buffer: require.resolve('buffer/'),
}
}, },
plugins: [
new ProvidePlugin({
Buffer: ['buffer', 'Buffer']
})
]
} }

View File

@ -8,9 +8,9 @@
const PRODUCTION = process.env.NODE_ENV === 'production' const PRODUCTION = process.env.NODE_ENV === 'production'
const common = require('./webpack.common.js') const common = require('./webpack.common')
const { outputs } = require('./webpack.parts.js') const { outputs } = require('./webpack.parts')
// '[libraryTarget]': [file extension] // '[libraryTarget]': [file extension]
const OUTPUT_MAPPING = { const OUTPUT_MAPPING = {

View File

@ -14,11 +14,9 @@ module.exports = {
minimizer: [ minimizer: [
new TerserPlugin({ new TerserPlugin({
test: /vendor/, test: /vendor/,
sourceMap: false
}), }),
new TerserPlugin({ new TerserPlugin({
test: /^((?!(vendor)).)*.js$/, test: /^((?!(vendor)).)*.js$/,
sourceMap: false
}) })
], ],
splitChunks: { splitChunks: {

View File

@ -9,8 +9,8 @@
const path = require('path') const path = require('path')
const { merge } = require('webpack-merge') const { merge } = require('webpack-merge')
const development = require('./webpack.development.js') const development = require('./webpack.development')
const production = require('./webpack.production.js') const production = require('./webpack.production')
const AddVendorsPlugin = require('./plugins/add-vendors-plugin') const AddVendorsPlugin = require('./plugins/add-vendors-plugin')