psffpp 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.editorconfig ADDED
@@ -0,0 +1,30 @@
1
+ # http://editorconfig.org
2
+
3
+ # A special property that should be specified at the top of the file outside of
4
+ # any sections. Set to true to stop .editor config file search on current file
5
+ root = true
6
+
7
+ [*]
8
+ # Indentation style
9
+ # Possible values - tab, space
10
+ indent_style = space
11
+
12
+ # Indentation size in single-spaced characters
13
+ # Possible values - an integer, tab
14
+ indent_size = 2
15
+
16
+ # Line ending file format
17
+ # Possible values - lf, crlf, cr
18
+ end_of_line = lf
19
+
20
+ # File character encoding
21
+ # Possible values - latin1, utf-8, utf-16be, utf-16le
22
+ charset = utf-8
23
+
24
+ # Denotes whether to trim whitespace at the end of lines
25
+ # Possible values - true, false
26
+ trim_trailing_whitespace = true
27
+
28
+ # Denotes whether file should end with a newline
29
+ # Possible values - true, false
30
+ insert_final_newline = true
package/.eslintrc.json ADDED
@@ -0,0 +1,10 @@
1
+ {
2
+ "extends": "standard",
3
+ "env": {
4
+ "node": true,
5
+ "mocha": true
6
+ },
7
+ "parserOptions": {
8
+ "ecmaVersion": 8
9
+ }
10
+ }
package/.on-save.json ADDED
@@ -0,0 +1,8 @@
1
+ [
2
+ {
3
+ "srcDir": "",
4
+ "destDir": "",
5
+ "files": "**/*.js",
6
+ "command": "npm run lint"
7
+ }
8
+ ]
package/.travis.yml ADDED
@@ -0,0 +1,33 @@
1
+ # This is a node.js v8+ JavaScript project
2
+ language: node_js
3
+ node_js:
4
+ - "10"
5
+
6
+ # Build on Ubuntu Trusty (14.04)
7
+ # https://docs.travis-ci.com/user/reference/trusty/#javascript-and-nodejs-images
8
+ dist: xenial
9
+ sudo: required
10
+
11
+ # Use Docker
12
+ services:
13
+ - docker
14
+
15
+ before_install:
16
+ #- npm install -g mocha
17
+
18
+ # https://github.com/greenkeeperio/greenkeeper-lockfile/issues/156
19
+ #install: case $TRAVIS_BRANCH in greenkeeper*) npm i;; *) npm ci;; esac;
20
+ install:
21
+ - npm install
22
+
23
+ script: "npm run test"
24
+
25
+ # Send coverage data to Coveralls
26
+ after_success:
27
+ - npm run coverage
28
+
29
+ deploy:
30
+ provider: script
31
+ skip_cleanup: true
32
+ script:
33
+ - npx semantic-release
package/LICENSE.md ADDED
@@ -0,0 +1,8 @@
1
+ The MIT License (MIT)
2
+ Copyright (c) 2021 Chris Troutner <chris.troutner@gmail.com>
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
+
6
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7
+
8
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/PEDIGREE.md ADDED
@@ -0,0 +1,3 @@
1
+ # Pedigree
2
+
3
+ This repository was originally forked from [npm-lib-boilerplate](https://github.com/christroutner/npm-lib-boilerplate). This is a boilerplate used to start JavaScript libraries which are intended to be published to npm.
package/README.md ADDED
@@ -0,0 +1,211 @@
1
+ # psffpp
2
+
3
+ This is an npm library for node.js. It implements the [PS010 specification for the PSF File Pinning Protocol](https://github.com/Permissionless-Software-Foundation/specifications/blob/master/ps009-multisig-approval.md). The main consumers of this library of [psf-bch-wallet](https://github.com/Permissionless-Software-Foundation/psf-bch-wallet) and [ipfs-p2wdb-service](https://github.com/Permissionless-Software-Foundation/ipfs-p2wdb-service).
4
+
5
+ ## Instancing Library
6
+ This library depends on [minimal-slp-wallet](https://www.npmjs.com/package/minimal-slp-wallet). An instance of that library is expected to be injected into this this one when instantiated. Here is an example:
7
+
8
+ ```javascript
9
+ const SlpWallet = require('minimal-slp-wallet')
10
+ const MultisigApproval = require('psf-multisig-approval')
11
+
12
+ async function start() {
13
+ // Instance the BCH wallet
14
+ const wallet = new SlpWallet(undefined, {
15
+ interface: 'consumer-api',
16
+ restURL: 'https://free-bch.fullstack.cash'
17
+ })
18
+ await wallet.initialize()
19
+
20
+ // Instance this library
21
+ const ps009 = new MultisigApproval({wallet})
22
+ }
23
+ start()
24
+ ```
25
+
26
+ ## Get NFT Holder Information
27
+ PS009 uses NFTs as 'homing beacons'. It generates a multisignature wallet from the public keys of the NFT holders. Finding the addresses and public keys of the NFT holders is a foundational feature of the protocol. All NFTs are connected by the Group Token ID that generated them.
28
+
29
+ If the holder of the NFT has not made any transactions, then their public key will not be on the blockchain. In that case, the NFT and address will be added to the `keysNotFound` array. Those holders will not be included in the multisignature wallet.
30
+
31
+ ```javascript
32
+ const groupTokenId = '8e8d90ebdb1791d58eba7acd428ff3b1e21c47fb7aba2ba3b5b815aa0fe7d6d5'
33
+
34
+ const result = await ps009.getNftHolderInfo(groupTokenId)
35
+ console.log(result)
36
+
37
+ /*
38
+ {
39
+ keys: [
40
+ {
41
+ addr: 'bitcoincash:qz4zsa22glal5c4jqm748xge657gwuw2d5t9nvg64p',
42
+ pubKey: '021ca211a04a1d489ae77e01c28c97b02e733893890fda00a359ca8956c2e0d259',
43
+ nft: 'e86164aaa06efac1d6453951f67beafe042f0bceb9312845a95355b1e93aa846'
44
+ },
45
+ {
46
+ addr: 'bitcoincash:qpfvh07mdt7yq5czndaz5qq4g9q3m87qpspy7xaxgu',
47
+ pubKey: '0361fd21512b9072e8f6b984d9b04c57e5779867c2ad002999372268770fcb2674',
48
+ nft: 'da7ccbd5e24e468c9e7402489ca9148b5e76e588b73cc4aa4bbf1ca41d5808ab'
49
+ },
50
+ {
51
+ addr: 'bitcoincash:qpsxtzaa7rg677akcc2znpenpsy5jr2ygywmfd45p2',
52
+ pubKey: '03b9bdc40c478ab0536be29c368b26c48a5e8d6867fc34b77c727ab690365aae91',
53
+ nft: '0ec318bede8c2f229db840a24cb63d662ad91e8e6c840e46e6a8ff2d173049ce'
54
+ },
55
+ {
56
+ addr: 'bitcoincash:qqk3aczzggvxnfm7rwm0f9yz20yr00dmpv2f3tasdr',
57
+ pubKey: '033c930d4cff4ba68a70f7a21443e20ad4176173380d21f8c3ce27f7ce947f3246',
58
+ nft: '51624e772adafd7c6a9da38774e4f654282199bd5402e049ee087fc2bd900882'
59
+ },
60
+ {
61
+ addr: 'bitcoincash:qpszha37cjn6n83hpxn7zz5ndaa35vygtcgslxhpuc',
62
+ pubKey: '024be54accec310c2636140336ae548d610ba9b7ce300b3f42494b4a6f2963731f',
63
+ nft: 'e70cc72eeb15c82e96b1f8127d3b138b2fc8ea101fe9c62302ec641c05d4b97d'
64
+ }
65
+ ],
66
+ keysNotFound: []
67
+ }
68
+ */
69
+ ```
70
+
71
+ ## Get an Approval Transaction
72
+ This function will take a BCH address as input. It will search the transaction history for the address, and will return an object about the first `APPROVAL` transaction that it finds. If it can't find one, it will return null.
73
+
74
+ ```javascript
75
+ const address = 'bitcoincash:qrwe6kxhvu47ve6jvgrf2d93w0q38av7s5xm9xfehr'
76
+
77
+ const result = await ps009.getApprovalTx({address})
78
+ console.log(result)
79
+
80
+ /*
81
+ {
82
+ approvalTxid: 'a63f9fbcc901316e6e89f5a8caaad6b2ab268278b29866c6c22088bd3ab93900',
83
+ updateTxid: 'f8ea1fcd4481adfd62c6251c6a4f63f3d5ac3d5fdcc38b350d321d93254df65f',
84
+ approvalTxDetails: {
85
+ txid: 'a63f9fbcc901316e6e89f5a8caaad6b2ab268278b29866c6c22088bd3ab93900',
86
+ vin: [ [Object] ],
87
+ vout: [ [Object], [Object], [Object] ],
88
+ ...
89
+ isValidSlp: false
90
+ },
91
+ opReturn: 'j\x07APPROVE@f8ea1fcd4481adfd62c6251c6a4f63f3d5ac3d5fdcc38b350d321d93254df65f'
92
+ }
93
+ */
94
+ ```
95
+
96
+ ## Get an Update Transaction
97
+
98
+ An *approval* transaction will point to an *update* transaction with its OP_RETURN output. This function is used to retrieve and decode that update transaction. Given a TXID, it will return details from the transaction, including the IPFS CID and timestamp stored in the update transactions OP_RETURN output.
99
+
100
+ ```javascript
101
+ const txid = 'f8ea1fcd4481adfd62c6251c6a4f63f3d5ac3d5fdcc38b350d321d93254df65f'
102
+
103
+ const result = await uut.getUpdateTx({ txid })
104
+ console.log(result)
105
+
106
+ /*
107
+ {
108
+ cid: 'bafybeib5d6s6t3tq4lhwp2ocvz7y2ws4czgkrmhlhv5y5aeyh6bqrmsxxi',
109
+ ts: 1676560247168,
110
+ txid: 'f8ea1fcd4481adfd62c6251c6a4f63f3d5ac3d5fdcc38b350d321d93254df65f',
111
+ txDetails: {
112
+ txid: 'f8ea1fcd4481adfd62c6251c6a4f63f3d5ac3d5fdcc38b350d321d93254df65f',
113
+ hash: 'f8ea1fcd4481adfd62c6251c6a4f63f3d5ac3d5fdcc38b350d321d93254df65f',
114
+ vin: [ [Object] ],
115
+ vout: [ [Object], [Object], [Object], [Object] ],
116
+ ...
117
+ isValidSlp: false
118
+ }
119
+ }
120
+
121
+ */
122
+ ```
123
+
124
+ ## Get IPFS CID Data
125
+
126
+ The update transaction will reference an IPFS CID. That data will need to be retrieved from an IPFS gateway. The default gateway can be overwritten when this library is instantiated.
127
+
128
+ ```javascript
129
+ // Instance this library and overwrite the default IPFS gateway
130
+ const ps009 = new MultisigApproval({
131
+ wallet,
132
+ ipfsGateway: 'https://p2wdb-gateway-678.fullstack.cash'
133
+ })
134
+
135
+ const cid = 'bafybeib5d6s6t3tq4lhwp2ocvz7y2ws4czgkrmhlhv5y5aeyh6bqrmsxxi'
136
+
137
+ const updateData = await ps009.getCidData({cid})
138
+ console.log(updateData)
139
+
140
+ /*
141
+ {
142
+ groupId: '8e8d90ebdb1791d58eba7acd428ff3b1e21c47fb7aba2ba3b5b815aa0fe7d6d5',
143
+ keys: [
144
+ {
145
+ addr: 'bitcoincash:qz4zsa22glal5c4jqm748xge657gwuw2d5t9nvg64p',
146
+ pubKey: '021ca211a04a1d489ae77e01c28c97b02e733893890fda00a359ca8956c2e0d259',
147
+ nft: 'e86164aaa06efac1d6453951f67beafe042f0bceb9312845a95355b1e93aa846'
148
+ },
149
+ {
150
+ addr: 'bitcoincash:qpfvh07mdt7yq5czndaz5qq4g9q3m87qpspy7xaxgu',
151
+ pubKey: '0361fd21512b9072e8f6b984d9b04c57e5779867c2ad002999372268770fcb2674',
152
+ nft: 'da7ccbd5e24e468c9e7402489ca9148b5e76e588b73cc4aa4bbf1ca41d5808ab'
153
+ },
154
+ {
155
+ addr: 'bitcoincash:qpsxtzaa7rg677akcc2znpenpsy5jr2ygywmfd45p2',
156
+ pubKey: '03b9bdc40c478ab0536be29c368b26c48a5e8d6867fc34b77c727ab690365aae91',
157
+ nft: '0ec318bede8c2f229db840a24cb63d662ad91e8e6c840e46e6a8ff2d173049ce'
158
+ },
159
+ {
160
+ addr: 'bitcoincash:qqk3aczzggvxnfm7rwm0f9yz20yr00dmpv2f3tasdr',
161
+ pubKey: '033c930d4cff4ba68a70f7a21443e20ad4176173380d21f8c3ce27f7ce947f3246',
162
+ nft: '51624e772adafd7c6a9da38774e4f654282199bd5402e049ee087fc2bd900882'
163
+ },
164
+ {
165
+ addr: 'bitcoincash:qpszha37cjn6n83hpxn7zz5ndaa35vygtcgslxhpuc',
166
+ pubKey: '024be54accec310c2636140336ae548d610ba9b7ce300b3f42494b4a6f2963731f',
167
+ nft: 'e70cc72eeb15c82e96b1f8127d3b138b2fc8ea101fe9c62302ec641c05d4b97d'
168
+ }
169
+ ],
170
+ walletObj: {
171
+ address: 'bitcoincash:pqntzt6wcp38h8ud68wjnwh437uek76lhvhlwcm4fj',
172
+ scriptHex: 'a91426b12f4ec0627b9f8dd1dd29baf58fb99b7b5fbb87',
173
+ publicKeys: [
174
+ '021ca211a04a1d489ae77e01c28c97b02e733893890fda00a359ca8956c2e0d259',
175
+ '0361fd21512b9072e8f6b984d9b04c57e5779867c2ad002999372268770fcb2674',
176
+ '03b9bdc40c478ab0536be29c368b26c48a5e8d6867fc34b77c727ab690365aae91',
177
+ '033c930d4cff4ba68a70f7a21443e20ad4176173380d21f8c3ce27f7ce947f3246',
178
+ '024be54accec310c2636140336ae548d610ba9b7ce300b3f42494b4a6f2963731f'
179
+ ],
180
+ requiredSigners: 3
181
+ },
182
+ multisigAddr: 'bitcoincash:pqntzt6wcp38h8ud68wjnwh437uek76lhvhlwcm4fj',
183
+ p2wdbWritePrice: 0.08335233
184
+ }
185
+ */
186
+ ```
187
+
188
+ ## Validate an Approval Transaction
189
+ After data about the approval and update transactions have been retrieved, it's important to validate that the approval transaction is valid and has not been faked. This function will return either `true` or `false` depending on the result of testing the transaction validity.
190
+
191
+ ```javascript
192
+ const address = 'bitcoincash:qrwe6kxhvu47ve6jvgrf2d93w0q38av7s5xm9xfehr'
193
+ const approvalObj = await ps009.getApprovalTx({ address })
194
+
195
+ const txid = 'f8ea1fcd4481adfd62c6251c6a4f63f3d5ac3d5fdcc38b350d321d93254df65f'
196
+ const updateObj = await ps009.getUpdateTx({ txid })
197
+
198
+ const cid = 'bafybeib5d6s6t3tq4lhwp2ocvz7y2ws4czgkrmhlhv5y5aeyh6bqrmsxxi'
199
+ const updateData = await ps009.getCidData({ cid })
200
+
201
+ const inObj = { approvalObj, updateObj, updateData }
202
+ const result = await ps009.validateApproval(inObj)
203
+ console.log(result)
204
+
205
+ /*
206
+ true
207
+ */
208
+ ```
209
+
210
+ # License
211
+ [MIT](LICENSE.md)
package/apidoc.json ADDED
@@ -0,0 +1,3 @@
1
+ {
2
+ "sampleUrl": null
3
+ }
@@ -0,0 +1,23 @@
1
+ /*
2
+ An example app for creating a wallet using this library.
3
+ */
4
+
5
+ const BchWallet = require('../index')
6
+
7
+ async function createWallet () {
8
+ try {
9
+ // Instantiate the wallet library.
10
+ const bchWallet = new BchWallet()
11
+
12
+ // Wait for the wallet to be created.
13
+ await bchWallet.walletInfoPromise
14
+
15
+ // Print out the wallet information.
16
+ console.log(
17
+ `Wallet information: ${JSON.stringify(bchWallet.walletInfo, null, 2)}`
18
+ )
19
+ } catch (err) {
20
+ console.error('Error: ', err)
21
+ }
22
+ }
23
+ createWallet()
@@ -0,0 +1,26 @@
1
+ /*
2
+ An example for listing the tokens and token balances of the wallet. a
3
+ */
4
+
5
+ const SlpWallet = require('../index')
6
+
7
+ async function listTokens () {
8
+ try {
9
+ // Replace the values for the constants below to customize for your use.
10
+ const MNEMONIC =
11
+ 'essence appear intact casino neck scatter search post cube fit door margin'
12
+
13
+ // Instantiate the wallet library.
14
+ const slpWallet = new SlpWallet(MNEMONIC)
15
+
16
+ // Wait for the wallet to be created.
17
+ await slpWallet.walletInfoPromise
18
+
19
+ // Get the token summary
20
+ const tokenInfo = await slpWallet.listTokens()
21
+ console.log(`tokenInfo: ${JSON.stringify(tokenInfo, null, 2)}`)
22
+ } catch (err) {
23
+ console.error('Error: ', err)
24
+ }
25
+ }
26
+ listTokens()
@@ -0,0 +1,60 @@
1
+ /*
2
+ An example for sending BCH with this library.
3
+ */
4
+
5
+ const SlpWallet = require('../index')
6
+
7
+ async function sendBch () {
8
+ try {
9
+ // Replace the values for the constants below to customize for your use.
10
+ const MNEMONIC =
11
+ 'essence appear intact casino neck scatter search post cube fit door margin'
12
+ const RECIEVER = ''
13
+ const SATS_TO_SEND = 1000
14
+
15
+ // Instantiate the wallet library.
16
+ const slpWallet = new SlpWallet(MNEMONIC)
17
+
18
+ // Wait for the wallet to be created.
19
+ await slpWallet.walletInfoPromise
20
+
21
+ // Get the balance of the wallet.
22
+ const balance = await slpWallet.getBalance()
23
+ console.log(`balance: ${balance} satoshis`)
24
+
25
+ // Exit if the wallet has no balance.
26
+ if (balance === 0) {
27
+ console.log(
28
+ `The balance of your wallet is zero. Send BCH to ${
29
+ slpWallet.walletInfo.address
30
+ } to run this example.`
31
+ )
32
+ return
33
+ }
34
+
35
+ // Create the outputs array.
36
+ const outputs = []
37
+
38
+ // If reciever is not specified, send the funds back to the wallet.
39
+ if (RECIEVER === '') {
40
+ outputs.push({
41
+ address: slpWallet.walletInfo.address,
42
+ amountSat: SATS_TO_SEND
43
+ })
44
+ //
45
+ // Send the funds to the reciever.
46
+ } else {
47
+ outputs.push({
48
+ address: RECIEVER,
49
+ amountSat: SATS_TO_SEND
50
+ })
51
+ }
52
+
53
+ const txid = await slpWallet.send(outputs)
54
+
55
+ console.log(`Success! BCH sent with TXID: ${txid}`)
56
+ } catch (err) {
57
+ console.error('Error: ', err)
58
+ }
59
+ }
60
+ sendBch()
@@ -0,0 +1,66 @@
1
+ /*
2
+ An example for sending tokens with this library.
3
+ */
4
+
5
+ const SlpWallet = require('../index')
6
+
7
+ async function sendBch () {
8
+ try {
9
+ // Replace the values for the constants below to customize for your use.
10
+ const MNEMONIC =
11
+ 'essence appear intact casino neck scatter search post cube fit door margin'
12
+ const RECIEVER = ''
13
+ const TOKENID =
14
+ 'a4fb5c2da1aa064e25018a43f9165040071d9e984ba190c222a7f59053af84b2'
15
+ const TOKENS_TO_SEND = 1
16
+
17
+ // Instantiate the wallet library.
18
+ const slpWallet = new SlpWallet(MNEMONIC)
19
+
20
+ // Wait for the wallet to be created.
21
+ await slpWallet.walletInfoPromise
22
+
23
+ // console.log('slpWallet.utxos.utxoStore: ', slpWallet.utxos.utxoStore)
24
+
25
+ // Get the balance of the wallet.
26
+ const balance = await slpWallet.getBalance()
27
+ console.log(`balance: ${balance} satoshis`)
28
+
29
+ // Exit if the wallet has no balance.
30
+ if (balance === 0) {
31
+ console.log(
32
+ `The balance of your wallet is zero. Send BCH to ${
33
+ slpWallet.walletInfo.address
34
+ } to run this example.`
35
+ )
36
+ return
37
+ }
38
+
39
+ // Create the outputs array.
40
+ let output = {}
41
+
42
+ // If reciever is not specified, send the funds back to the wallet.
43
+ if (RECIEVER === '') {
44
+ output = {
45
+ address: slpWallet.walletInfo.address,
46
+ tokenId: TOKENID,
47
+ qty: TOKENS_TO_SEND
48
+ }
49
+ //
50
+ // Send the funds to the reciever.
51
+ } else {
52
+ output = {
53
+ address: RECIEVER,
54
+ tokenId: TOKENID,
55
+ qty: TOKENS_TO_SEND
56
+ }
57
+ }
58
+
59
+ const txid = await slpWallet.sendTokens(output)
60
+
61
+ console.log(`Success! Tokens sent with TXID: ${txid}`)
62
+ } catch (err) {
63
+ console.error('Error: ', err)
64
+ }
65
+ }
66
+ sendBch()