psffpp 1.1.11 → 1.1.12

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/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  PSFFPP = [Permissionless Software Foundation](https://psfoundation.info) [File Pinning Protocol](https://psffpp.com).
4
4
 
5
5
  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 is:
6
- - [p2wdb-image-upload-backend](https://github.com/Permissionless-Software-Foundation/p2wdb-image-upload-backend) uses it generate Pin Claims for file uploads as demonstrated at [upload.psfoundation.info](https://upload.psfoundation.info).
6
+
7
7
  - [ipfs-file-pin-service](https://github.com/Permissionless-Software-Foundation/ipfs-file-pin-service) uses it to verify Pin Claims before pinning the files.
8
8
  - [psf-bch-wallet](https://github.com/Permissionless-Software-Foundation/psf-bch-wallet) is a command-line UI that uses this library to add files to the network.
9
9
 
@@ -0,0 +1,44 @@
1
+ /* >
2
+ This example shows how to get the current write price set by the PSF Minting Council.
3
+ */
4
+
5
+ import SlpWallet from 'minimal-slp-wallet'
6
+ import PSFFPP from '../index.js'
7
+
8
+ async function start () {
9
+ try {
10
+ let now = new Date()
11
+ console.log('Start time: ', now.toLocaleString())
12
+
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 psffpp = new PSFFPP({ wallet })
22
+
23
+ now = new Date()
24
+ console.log(`1st write price lookup started at ${now.toLocaleString()}`)
25
+
26
+ // Get the current write price
27
+ const writePrice = await psffpp.getMcWritePrice()
28
+ console.log('1st writePrice: ', writePrice)
29
+
30
+ now = new Date()
31
+ console.log(`2nd write price lookup started at ${now.toLocaleString()}`)
32
+
33
+ // Get the current write price
34
+ const writePrice2 = await psffpp.getMcWritePrice()
35
+ console.log('2nd writePrice: ', writePrice2)
36
+
37
+ now = new Date()
38
+ console.log(`Finished at ${now.toLocaleString()}`)
39
+ } catch (err) {
40
+ console.error(err)
41
+ }
42
+ }
43
+
44
+ start()
package/index.js CHANGED
@@ -95,13 +95,13 @@ class PSFFPP {
95
95
  })
96
96
 
97
97
  if (approvalIsValid) {
98
- console.log('Approval TXID validated.')
98
+ console.log('Approval TX validated.')
99
99
 
100
100
  // Return the write price from the update data.
101
101
  writePrice = updateData.p2wdbWritePrice
102
102
  } else {
103
103
  // Approval transaction failed validation.
104
- console.log(`Approval TXID was found to be invalid: ${approvalTxid}`)
104
+ console.log(`Approval TX was found to be invalid: ${approvalTxid}`)
105
105
 
106
106
  // Add this invalid TXID to the filter array so that it is skipped.
107
107
  this.filterTxids.push(approvalTxid)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "psffpp",
3
- "version": "1.1.11",
3
+ "version": "1.1.12",
4
4
  "description": "PS010 PSF File Pinning Protocol",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -34,7 +34,7 @@
34
34
  "repository": "Permissionless-Software-Foundation/psffpp",
35
35
  "dependencies": {
36
36
  "axios": "1.3.5",
37
- "psf-multisig-approval": "2.0.8"
37
+ "psf-multisig-approval": "2.0.10"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@psf/bch-js": "6.8.0",
@@ -1,23 +0,0 @@
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()
@@ -1,26 +0,0 @@
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()
@@ -1,60 +0,0 @@
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()
@@ -1,66 +0,0 @@
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()
@@ -1,117 +0,0 @@
1
- /*
2
- Integration tests for the main library.
3
- */
4
-
5
- // Global npm libraries
6
- const SlpWallet = require('minimal-slp-wallet')
7
- const assert = require('chai').assert
8
-
9
- // Local libraries
10
- const MultisigApproval = require('../../index')
11
-
12
- describe('#psf-multisig-approval', () => {
13
- let uut
14
-
15
- before(async () => {
16
- const wallet = new SlpWallet(undefined, {
17
- interface: 'consumer-api',
18
- // restURL: 'https://bch-consumer-anacortes-wa-usa.fullstackcash.nl'
19
- restURL: 'https://free-bch.fullstack.cash'
20
- })
21
- await wallet.walletInfoPromise
22
-
23
- uut = new MultisigApproval({ wallet })
24
- })
25
-
26
- describe('#getNftHolderInfo', () => {
27
- it('should get address and pubkeys for Minting Council NFT holders', async () => {
28
- const result = await uut.getNftHolderInfo()
29
- // console.log('result: ', result)
30
-
31
- // Assert expected properties exist
32
- assert.property(result, 'keys')
33
- assert.property(result, 'keysNotFound')
34
-
35
- // Assert that each property is an array.
36
- assert.isArray(result.keys)
37
- assert.isArray(result.keysNotFound)
38
- })
39
- })
40
-
41
- describe('#createMultisigAddress', () => {
42
- it('should generate a multisig address from token holder info', async () => {
43
- const tokenHolderInfo = await uut.getNftHolderInfo()
44
-
45
- const keys = tokenHolderInfo.keys
46
-
47
- const result = await uut.createMultisigAddress({ keys })
48
- // console.log('result: ', result)
49
-
50
- assert.property(result, 'address')
51
- assert.property(result, 'scriptHex')
52
- assert.property(result, 'publicKeys')
53
- assert.property(result, 'requiredSigners')
54
- })
55
- })
56
-
57
- describe('#getApprovalTx', () => {
58
- it('should retrieve the latest APPROVAL transaction from an address', async () => {
59
- const address = 'bitcoincash:qrwe6kxhvu47ve6jvgrf2d93w0q38av7s5xm9xfehr'
60
-
61
- const result = await uut.getApprovalTx({ address })
62
- // const result = await uut.getApprovalTx({ address, filterTxids: ['a63f9fbcc901316e6e89f5a8caaad6b2ab268278b29866c6c22088bd3ab93900'] })
63
- // console.log('result: ', result)
64
-
65
- assert.equal(result.updateTxid.length, 64)
66
- })
67
- })
68
-
69
- describe('#getUpdateTx', () => {
70
- it('should retrieve an update transaction', async () => {
71
- const txid = 'f8ea1fcd4481adfd62c6251c6a4f63f3d5ac3d5fdcc38b350d321d93254df65f'
72
-
73
- const result = await uut.getUpdateTx({ txid })
74
- // console.log('result: ', result)
75
-
76
- // Assert returned object has expected properties
77
- assert.property(result, 'cid')
78
- assert.property(result, 'ts')
79
- assert.property(result, 'txid')
80
- assert.property(result, 'txDetails')
81
- })
82
- })
83
-
84
- describe('#getCidData', () => {
85
- it('should get JSON data from an IPFS gateway', async () => {
86
- const cid = 'bafybeib5d6s6t3tq4lhwp2ocvz7y2ws4czgkrmhlhv5y5aeyh6bqrmsxxi'
87
- const result = await uut.getCidData({ cid })
88
- // console.log('result: ', result)
89
-
90
- // Assert expected properties exist
91
- assert.property(result, 'groupId')
92
- assert.property(result, 'keys')
93
- assert.property(result, 'walletObj')
94
- assert.property(result, 'multisigAddr')
95
- assert.property(result, 'p2wdbWritePrice')
96
- })
97
- })
98
-
99
- describe('#validateApproval', () => {
100
- it('should validate a valid approval transaction', async () => {
101
- const address = 'bitcoincash:qrwe6kxhvu47ve6jvgrf2d93w0q38av7s5xm9xfehr'
102
- const approvalObj = await uut.getApprovalTx({ address })
103
-
104
- const txid = 'f8ea1fcd4481adfd62c6251c6a4f63f3d5ac3d5fdcc38b350d321d93254df65f'
105
- const updateObj = await uut.getUpdateTx({ txid })
106
-
107
- const cid = 'bafybeib5d6s6t3tq4lhwp2ocvz7y2ws4czgkrmhlhv5y5aeyh6bqrmsxxi'
108
- const updateData = await uut.getCidData({ cid })
109
-
110
- const inObj = { approvalObj, updateObj, updateData }
111
- const result = await uut.validateApproval(inObj)
112
- // console.log('result: ', result)
113
-
114
- assert.equal(result, true)
115
- })
116
- })
117
- })