kadena.js
Kadena.js is a collection of libraries that will allow you to interact with the
local,development,testnetormainnetKadena chainweb. It will provide helper function
Running Tests
Unit testing
To run the unit tests:
$ npm test$ npm testTo run single unit tests:
$ npm test --single=[nameOfFile] where [nameOfFile] can be a regex$ npm test --single=[nameOfFile] where [nameOfFile] can be a regexintegration tests
Pactserver
To run integration tests against a pact server the following command can be used:
$ npm test:integration:pactserver$ npm test:integration:pactserverdevnet
To run integration tests against devnet it requires starting devnet and exposing the pact endpoints at http://localhost:8080 . For more details, see instructions at the Devnet Github repository .
The following command can be used:
$ npm test:integration:devnet$ npm test:integration:devnetTODO make Pact server port configurable
TODO
- make ready to go public
 - npm registry
 - release cycles
 
Function Migration Progress
- DONE: 16
 - PENDING: 5
 - TODO: 35
 
crypto:
- DONE 
binToHex - DONE 
hexToBin - DONE 
base64UrlEncode - DONE 
base64UrlDecode - DONE 
base64UrlEncodeArr - DONE 
base64UrlDecodeArr - DONE 
strToUint8Array - DONE 
uint8ArrayToStr - DONE 
hash - DONE 
hashBin - DONE 
genKeyPair - DONE 
restoreKeyPairFromSecretKey - DONE 
sign - DONE 
signHash - DONE 
verifySig - DONE 
toTweetNaclSecretKey 
api:
- PENDING 
createSendRequest:- Omitted, it just wrapped a list of Commands into the expected format for the
/sendendpoint.ISendRequestBodytype created instead. 
 - Omitted, it just wrapped a list of Commands into the expected format for the
 - DONE 
prepareContCommand:- Puts together and signs a continuation payload 
Command. 
 - Puts together and signs a continuation payload 
 - DONE 
prepareExecCommand:- Puts together and signs an exec payload 
Command. 
 - Puts together and signs an exec payload 
 - PENDING 
createCommand:- Puts together a 
Commandtype from a list of signatures and a stringified payload. Also checks that the signatures are for correct hash. - Pending for renaming, formally mkSingleCmd.
 
 - Puts together a 
 - DONE 
createContCommand:- A wrapper for a 
mkPublicSendandprepareContCmdcall. Could potentially be omitted. 
 - A wrapper for a 
 - DONE 
createExecCommand:- A wrapper for a 
mkPublicSendandprepareExecCmdcall. Could potentially be omitted. 
 - A wrapper for a 
 - PENDING 
createLocalCommand:- Wrapper for 
prepareExecCmd. The request type forlocalendpoint is just a singleCommand. Could be omitted, but the naming here does provides extra clarity. 
 - Wrapper for 
 - DONE 
createPollRequest:- Prepares a 
/pollendpoint request type (i.e. a list of request keys) from a{cmds: [Command]}type (i.e. the type of the/sendendpoint). Ignore naming/docs that imply theCommandshould have an exec payload. 
 - Prepares a 
 - DONE 
createListenRequest:- Prepares a 
/listenendpoint request type. Similar tocreatePollRequest, but only uses the first request key. 
 - Prepares a 
 - DONE 
attachSignature:- API Helper function that attaches signed or unsigned signature from a keypair and stringified payload.
 
 - DONE 
pullAndCheckHashs:- API Helper function maps through signatures and make sure that the signatures are signing the same hash and pulls the hash.
 
 - DONE 
pullSignature:- API Helper function that pulls signature only object from signature with
hash object 
{hash, pubKey, sig} 
 - API Helper function that pulls signature only object from signature with
hash object 
 - DONE 
pullSigner:- API Helper function that pulls public key and capability list if it exists.
 
 
lang:
- PENDING 
mkExp - PENDING 
mkMeta - PENDING 
mkCap:- Returns a 
SigningCap, which contains a regular Pact capability and some added fields consumed by chainweaver. 
 - Returns a 
 
fetch:
- PENDING 
send - TODO 
local - TODO 
poll - TODO 
listen - TODO 
spv 
wallet:
- TODO 
sign:- Sends an enriched 
Commandpayload to the signing API of the Chainweaver wallet. 
 - Sends an enriched 
 - TODO 
sendSigned:- Very similar to 
fetch.sendfunction, but expects a singleCommandinstead of a list of them. Could be omitted. 
 - Very similar to 
 - DONE 
createCap- Returns a 
SigningCap, which contains a regular Pact capability and some added fields consumed by chainweaver. 
 - Returns a 
 
cut:
- TODO 
current:- Queries a chainweb node's 
/cutendpoint. Uses retry. 
 - Queries a chainweb node's 
 
event:
- TODO 
range:- Calls the 
blocksfunction, which eventually callsbranchPagefunction. 
 - Calls the 
 - TODO 
recent:- Similar to 
event.range, but callsrecentBlocksinstead. 
 - Similar to 
 - TODO 
stream - TODO 
height:- Similar to 
rangebut filters for a specific block height. 
 - Similar to 
 - TODO blockHash:
- Queries 
blockByBlockHashand filters for the events produced by that block. 
 - Queries 
 
SigData:
- 
DONE
mkCap:- Similar to pact-lang's 
mkCapfunction, but this one creates a regular Pact capability. 
 - Similar to pact-lang's 
 - 
TODO
mkMeta:- Identical to pact-lang's 
mkMeta. Can be omitted. 
 - Identical to pact-lang's 
 - 
TODO
mkSignerCList:- Returns the capability and signer's public key in the format expected in the
signersfield ofSigBuilder. 
 - Returns the capability and signer's public key in the format expected in the
 - 
TODO
mkSignerGas:- Calls 
mkSignerCListwith gas capability. 
 - Calls 
 - 
TODO
mkSignerUnrestricted:- Similar to 
mkSignerCListbut without caps (hence an unrestricted signer). 
 - Similar to 
 - 
TODO
mkExecPayload:- Prepares an exec payload for the 
cmdfield of theSigDatatype. 
 - Prepares an exec payload for the 
 - 
TODO
mkContPayload:- Prepares a continuation payload for the 
cmdfield of theSigDatatype. 
 - Prepares a continuation payload for the 
 - 
TODO
mkSigData - 
util:
- TODO 
gasCap: Gas capability. - TODO 
addGasCap:- Adds a gas capbility to a list of capabilities. Uses 
gasCap. 
 - Adds a gas capbility to a list of capabilities. Uses 
 - TODO 
mergeSigners:- Combines multiple signer arrays created by the 
mkSigner*functions. Used bySigBuilder. 
 - Combines multiple signer arrays created by the 
 - TODO 
autoCreationTime:- Gets the system's local time in the format expected by 
creation-timefields in transactions. 
 - Gets the system's local time in the format expected by 
 - TODO 
autoNonce:- Stringifies the current date as an easy way to set a default nonce.
 
 - TODO 
pubKeysFromSigners:- Gets public key from signers created by 
mkSigner*functions. 
 - Gets public key from signers created by 
 
 - TODO 
 - 
ex:
- TODO 
execCmdExample1:- Creates an example exec transaction that can be sent to the wallet for signing. Could be omitted.
 
 - TODO 
contCmdExample1:- Creates an example continuation transaction that can be sent to the wallet for signing. Could be omitted.
 
 
 - TODO 
 - 
debug
- DONE 
toggleDebug: Omitted. 
 - DONE 
 
Enhacements
(1) Auto detection of network versions
Problem:
(A) When querying a chainweb node, the server expects the endpoint to have a specific format. For example:
http://localhost:8080/chainweb/0.0/development/chain/1/pact
In the above, 0.0 represents the node API Version and could change later on.
Also, development represents the version of Chainweb that the node is running.
Other possible values are testnet04 and mainnet01. Both of these pieces of
information is returned by querying the /info endpoint. For example:
http://localhost:8080/info
(B) The Chainweb node version (i.e. development) is a required field in a
transaction's payload. An error is thrown if the network specified in the
transaction payload does not match the network version specified in the endpoint
prefix (i.e. ../0.0/development/chain..).
It is an error prone user experience to have users pass along a node's version information along with the hostname, especially if this information is easily autodected.
Proposal:
Doug outlines an approach in KadenaPorcelain  where network (i.e.
pact-server, Chainweb mainnet, Chainweb testnet) and other version specific data
(i.e. Chainweb's 0.0 version) is autodetected. This is done by querying the
/info endpoint for Chainweb nodes and the /version endpoint for pact-server.
This network and version information is then passed to functions that construct transactions and functions that call the different Pact API endpoints.