HiĀ ! ?
I'm doing a partial release along the way so we can all benefit from the recent developments.
cosmic-lib now works properly in server-side node environment. The HTML nodes could not be made available easily, but you can convert/sign/send transactions and use all other features from the library.
I added format handlers that call a callback each time a format gets modified. Stellar Authenticator uses it to update on-the-fly the XDR after it gets signed. You can define them for a particular cosmic Link object or class-wide like:
CosmicLink.addFormatHandler('xdr', event => {
if (event.error) console.log('Error: ' + event.error.message)
else console.log(event.value)
})
Now you can also setup the default web page or the network for cosmic links globally:
CosmicLink.page = 'https://mysite.org'
CosmicLink.network = 'test'
I reworked the HTML nodes so that they are generated only on-demand. The main node is now called cosmicLink.htmlNode
as it's more meaningful, and it will display automatically in the HTML element whose id is CL_htmlNode
if it exist on the current web page.
I implemented some multi-signature support and a way to get source account easily
const signers = await cosmicLink.getSigners()
if (await cosmicLink.hasSigner(publicKey) ...
if (await cosmicLink.hasSigned(publicKey) ...
const account = await cosmicLink.getSourceAccount()
XDR/transaction & XDR queries can now accept the options stripSequence
and stripSignatures
and the sequence number / signatures are now kept by default.
The debug page have been updated and information is now easier to read: https://cosmic.link/cosmic-lib/debug.html
If you were using cosmicLink.sign()
without await
or .then
, you should now use them as signing is now asynchronous because of the check performed on the account signers object which may not be available immediately, else you may encounter odd behaviors.
My next goal is the implementation of aliases for known addresses and the support of multi-operation transactions with proper multisignature handling; which's quite a challenge if you ask me ?
I leave you with the updated cheat sheet ~ have a good week-end !
// --- Constructor ---
// new CosmicLink(uri, "[userNetwork]", "[userAddress]")
// new CosmicLink(query, "[userNetwork]", "[userAddress]")
// new CosmicLink(transaction, "[userNetwork]", "[userAddress]", {...options})
// new CosmicLink(xdr, "[userNetwork]", "[userAddress]", {...options})
//
// --- Options for transaction & xdr ---
// stripSource = true < Strip out source account
// stripSequence = true < Strip out sequence number
// stripSignatures = true < Strip out signatures
// network = ... < Specify a network for this transaction (kept in URI after conversion)
//
// --- Edit ---
// CosmicLink.parse(any-format, {...options})
// *CosmicLink.setField(field, value)
// *CosmicLink.addOperation({...params})
// *CosmicLink.changeOperation(index, {...params})
// *CosmicLink.removeOperation(index)
//
// --- Formats (get) ---
// CosmicLink.getUri() < Return a promise of the URI string
// CosmicLink.getQuery() < Return a promise of the query string
// CosmicLink.getJson() < Return stringified JSON of the object
// CosmicLink.getTdesc() < Return a promise of the transaction descriptor
// CosmicLink.getTransaction() < Return a promise of the transaction
// CosmicLink.getXdr() < Return a promise of the transaction's XDR
//
// --- Handlers ---
// CosmicLink.addFormatHandler(format, callback)
// CosmicLink.removeFormatHandler(format, callback)
// callback will receive event = { cosmicLink: ..., value: ..., error: ... }
//
// --- Datas --- <<< Update everything on the go >>>
// CosmicLink.user < User address
// *CosmicLink.aliases < Local aliases for public keys
// CosmicLink.network < Test/Public network
// CosmicLink.server < The horizon server to use
// CosmicLink.status < Status of the CosmicLink (valid or specific error)
// CosmicLink.errors < An array of errors (or undefined if no error)
// CosmicLink.page < The base URI, without the query
//
// --- Datas (asynchronous)
// CosmicLink.getSource() < Transaction source
// CosmicLink.getSourceAccount() < Transaction source account object
// CosmicLink.getSigners() < Array of legit signers
//
// --- Tests ---
// CosmicLink.hasSigner(publicKey) < Test if `publicKey` is a signer for CosmicLink
// CosmicLink.hasSigned(publicKey) < Test if `publicKey` signature is available
//
// --- Actions ---
// CosmicLink.selectNetwork() < Select CosmicLink network for Stellar SDK
// CosmicLink.sign(seed) < Sign the transaction
// CosmicLink.send([server]) < Send the transaction to the network
//
// --- Events ---
// CosmicLink.onClick.type < For onClick events on the HTML description
//
// --- HTML Nodes ---
// CosmicLink.htmlNode < HTML element for CosmicLink
// CosmicLink.transactionNode < HTML description of the transaction
// CosmicLink.signersNode < HTML element for the signers list
// CosmicLink.statusNode < HTML element for the transaction status & errors