.utils¶
isValidId¶
pruf.utils.isValidId(id)
Returns a boolean confirming or denying whether or not the given id is a valid id.
Parameters¶
id
String|Bytes32
Hash built from individual inputs which is used to identify the asset on the network.
Returns¶
Boolean
True/False
Example usage¶
1//Example pruf-js code
2
3let unhashedId = {
4 type: "bike,
5 make: "mongoose",
6 model: "trail",
7 serial: "12345678"
8}
9let _id = await pruf.utils.generateAssetID(unhashedId)
10
11pruf.utils.isValidId(_id)
12.then(e => {
13 console.log(e)
14 //Expected output: True
15}
ipfsFromB32¶
pruf.utils.ipfsFromB32(bytes32Hex)
Returns a valid ipfs CID from a Bytes32.
Parameters¶
bytes32Hex
String|Bytes32
Hash parsed from a CID to be stored on the blockchain.
Returns¶
CID|String
Used to query ipfs clients for data which matches the CID
Example usage¶
1//Example pruf-js code
2
3let _bytes32Hex = '0x22f7ee355249d57c4e05e8437879bfa360570bc25620d6c758f8e9a9ba8c5156'
4
5pruf.utils.ipfsFromB32(_bytes32Hex)
6.then(e => {
7 console.log(e)
8 //Expected output: 'QmQh9qobTmwHRztiTyi2fckYgpiygSZhDN7yfDymvUfZh7'
9}
ipfsToB32¶
pruf.utils.ipfsToB32(cid)
Returns a Bytes32 pasred from an ipfs CID.
Parameters¶
CID
String|Bs58
Used to query ipfs clients for data which matches the CID
Returns¶
Bytes32|String
Hash parsed from a CID to be stored on the blockchain.
Example usage¶
1//Example pruf-js code
2
3let _cid = 'QmQh9qobTmwHRztiTyi2fckYgpiygSZhDN7yfDymvUfZh7'
4
5pruf.utils.ipfsToB32(_cid)
6.then(e => {
7 console.log(e)
8 //Expected output: '0x22f7ee355249d57c4e05e8437879bfa360570bc25620d6c758f8e9a9ba8c5156'
9}
stringifyStatus¶
pruf.utils.stringifyStatus(status)
Returns the status name associated with a status number.
Parameters¶
statusNum
String|Uint8
The current status number of an asset, acting as a layer of permissions for the network.
Returns¶
String
Status name associated with a status number
Example usage¶
1//Example pruf-js code
2
3let _status = "51"
4
5pruf.utils.stringifyStatus(_status)
6.then(e => {
7 console.log(e)
8 //Expected output: "Transferrable"
9}
convertEscrowTime¶
pruf.utils.convertEscrowTime(rawTime, to)
Converts rawTime(seconds) to desired measurement(minutes, hours, days, weeks) for escrow related functions.
Parameters¶
rawTime
Number
The number of seconds being converted.
to
String
The conversion rate for rawTime (minutes, hours, days, weeks).
Returns¶
String
Converted time measurement
Example usage¶
1//Example pruf-js code
2
3let _rawTime = "180"
4let _to = "minutes"
5
6pruf.utils.convertEscrowTime(_rawTime, _to)
7.then(e => {
8 console.log(e)
9 //Expected output: "3"
10}
tenThousandHashesOf¶
pruf.utils.tenThousandHashesOf(toBeHashed)
Hashes a given value ten thousand times using the current algorithm supported by the network
Parameters¶
toBeHashed
String
String to be hashed.
Returns¶
String|Bytes32
Resulting Bytes32 string of the given toBeHashed value
Example usage¶
1//Example pruf-js code
2
3let _toBeHashed = 'Hello World'
4
5pruf.utils.tenThousandHashesOf(_toBeHashed)
6.then(e => {
7 console.log(e)
8 //Expected output: '0x251a68a00a43256025c9bd8fc98f63b1a46d27b1c1bc872ead767121ca873700'
9}
generateAssetID¶
pruf.utils.generateAssetID({ type, make, model, serial })
Generates an assetId from specific input fields.
Parameters¶
Object
- type
String
Type of asset being made.
- make
String
Make of asset being made.
- model
String
Model of asset being made.
- serial
String
Serial of asset being made.
Returns¶
String
assetId Hash
Example usage¶
1//Example pruf-js code
2
3let _unhashedId = {
4type: "bike,
5manufacturer: "mongoose",
6model: "trail",
7serial: "12345678"
8}
9
10pruf.utils.generateAssetID(_unhashedId)
11.then(e => {
12 console.log(e)
13 //Expected output: "0x6a21cf8dad19b95d6976b80a0ea46f71e5acaeb0d7ce0c952c612cb0e1b39b50"
14}
generateSecureRgt¶
pruf.utils.generateSecureRgt(assetId, { first, middle, last, id, password })
Generates a rightsHash from specific owner input fields and an assetId.
Parameters¶
assetId
String|Bytes32
Hash built from individual inputs which is used to identify the asset on the network.
Object
- first
String
First name of owner of asset being made.
- middle
String
Middle name of owner of asset being made.
- last
String
Last name of owner of asset being made.
- id
String
Id of owner of asset being made.
- password
String
Password set by owner of asset being made.
Returns¶
String
Asset rightsHash
Example usage¶
1//Example pruf-js code
2
3let _assetId = "0x6a21cf8dad19b95d6976b80a0ea46f71e5acaeb0d7ce0c952c612cb0e1b39b50"
4let _unhashedRights = {
5first: "John,
6middle: "Frederik",
7last: "Doe",
8id: "12345678",
9password: "******"
10}
11
12pruf.utils.generateSecureRgt(_assetId, _unhashedRights)
13.then(e => {
14 console.log(e)
15 //Expected output: "0x968a4a295335fa4badbc4746a701d4407a7df7febd489a7de44959358ff5a21d"
16}