liquidity-invoice-generation
Advanced tools
Comparing version 1.0.0 to 1.1.0
40
index.js
const BigNumber = require('bignumber.js') | ||
const JSONbig = require('json-bigint') | ||
const atob = require('atob') | ||
const btoa = require('btoa') | ||
const uuid = require('uuid/v4') | ||
@@ -66,3 +63,3 @@ const web3Utils = require('web3-utils') | ||
contractAddress: receiver.hubAddress, | ||
walletAddresses: [receiver.publicKey] | ||
walletAddresses: [web3Utils.toChecksumAddress(receiver.publicKey)] | ||
} | ||
@@ -75,6 +72,3 @@ ], | ||
return { | ||
invoice: invoice, | ||
nonce: deriveReferenceNonce(invoice) | ||
} | ||
return Object.defineProperty(invoice, 'nonce', { value: deriveReferenceNonce(invoice), enumerable: true }) | ||
} | ||
@@ -88,3 +82,15 @@ | ||
const encodeInvoice = (invoice) => { | ||
return encodeURIComponent(btoa(JSONbig.stringify(invoice))) | ||
const data = [ | ||
invoice.uuid, | ||
invoice.destinations.map(dest => [ | ||
dest.networkId, | ||
dest.contractAddress, | ||
dest.walletAddresses.map(web3Utils.hexToNumberString).join('#') | ||
].join('@')).join('&'), | ||
invoice.amount.toString(), | ||
invoice.currency, | ||
invoice.details, | ||
].join('|') | ||
// return lzstring.compressToEncodedURIComponent(data) | ||
return data | ||
} | ||
@@ -98,3 +104,17 @@ | ||
const decodeInvoice = (encoded) => { | ||
return JSONbig.parse(atob(decodeURIComponent(encoded))) | ||
const data = encoded.split('|') | ||
return { | ||
uuid: data[0], | ||
destinations: data[1].split('&').map(dest => { | ||
const destData = dest.split('@') | ||
return { | ||
networkId: destData[0], | ||
contractAddress: destData[1], | ||
walletAddresses: destData[2].split('#').map(web3Utils.fromUtf8), | ||
} | ||
}), | ||
amount: new BigNumber(data[2]), | ||
currency: data[3], | ||
details: data[4], | ||
} | ||
} | ||
@@ -101,0 +121,0 @@ |
{ | ||
"name": "liquidity-invoice-generation", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Invoice generation system compatible with Liquidity Network", | ||
"main": "index.js", | ||
"dependencies": { | ||
"atob": "^2.1.1", | ||
"bignumber.js": "^7.2.1", | ||
"btoa": "^1.2.1", | ||
"json-bigint": "^0.3.0", | ||
"uuid": "^3.3.2", | ||
@@ -12,0 +9,0 @@ "web3-utils": "^1.0.0-beta.34" |
4685
3
110
- Removedatob@^2.1.1
- Removedbtoa@^1.2.1
- Removedjson-bigint@^0.3.0
- Removedatob@2.1.2(transitive)
- Removedbignumber.js@9.1.2(transitive)
- Removedbtoa@1.2.1(transitive)
- Removedjson-bigint@0.3.1(transitive)