Base level functions, classes, interfaces for Ninja
Links: API, Interfaces, Classes, Functions, Types, Variables
Links: API, Interfaces, Classes, Functions, Types, Variables
A client for creating, signing, and delivering Bitcoin transactions
export interface NinjaApi {
dojo: DojoClientApi;
authenticate(identityKey?: string, addIfNew?: boolean): Promise<void>;
sync(): Promise<void>;
setSyncDojosByConfig(syncDojoConfigs: SyncDojoConfigBaseApi[], options?: DojoSyncOptionsApi): Promise<void>;
getSyncDojosByConfig(): Promise<{
dojos: SyncDojoConfigBaseApi[];
options?: DojoSyncOptionsApi;
}>;
getClientChangeKeyPair(): KeyPairApi;
getPaymail(): Promise<string>;
setPaymail(paymail: string): Promise<void>;
getChain(): Promise<Chain>;
getNetwork(format?: "default" | "nonet"): Promise<string>;
findCertificates(certifiers?: string[] | object, types?: Record<string, string[]>): Promise<{
status: "success";
certificates: DojoCertificateApi[];
}>;
saveCertificate(certificate: DojoCertificateApi | object): Promise<void>;
getTotalValue(basket?: string): Promise<{
total: number;
}>;
getTotalOfAmounts(options: DojoGetTotalOfAmountsOptions): Promise<{
total: number;
}>;
getNetOfAmounts(options?: DojoGetTotalOfAmountsOptions): Promise<number>;
getAvatar(): Promise<DojoAvatarApi>;
setAvatar(name: string, photoURL: string): Promise<void>;
getTransactions(options?: DojoGetTransactionsOptions): Promise<NinjaGetTransactionsResultApi>;
getTransactionOutputs(options?: DojoGetTransactionOutputsOptions): Promise<NinjaGetTransactionOutputsResultApi[]>;
getTransactionLabels(options?: DojoGetTransactionLabelsOptions): Promise<{
labels: DojoTxLabelApi[];
total: number;
}>;
getPendingTransactions(referenceNumber?: string): Promise<DojoPendingTxApi[]>;
updateTransactionStatus(params: {
reference: string;
status: DojoTransactionStatusApi;
}): Promise<void>;
updateOutpointStatus(params: {
txid: string;
vout: number;
spendable: boolean;
}): Promise<void>;
processPendingTransactions(onTransactionProcessed?: NinjaTransactionProcessedHandler, onTransactionFailed?: NinjaTransactionFailedHandler): Promise<void>;
processTransaction(params: DojoProcessTransactionParams): Promise<DojoProcessTransactionResultApi>;
getTransactionWithOutputs(params: NinjaGetTransactionWithOutputsParams): Promise<NinjaTransactionWithOutputsResultApi>;
createTransactionWithOutputs(params: NinjaGetTransactionWithOutputsParams): Promise<NinjaTransactionWithOutputsResultApi>;
processTransactionWithOutputs(params: NinjaGetTransactionWithOutputsParams): Promise<NinjaTransactionWithOutputsResultApi>;
signAction(params: NinjaSignActionParams): Promise<NinjaSignActionResultApi>;
abortAction(params: NinjaAbortActionParams): Promise<NinjaAbortActionResultApi>;
createTransaction(params: NinjaCreateTransactionParams): Promise<DojoCreateTransactionResultApi>;
submitDirectTransaction(params: NinjaSubmitDirectTransactionParams): Promise<NinjaSubmitDirectTransactionResultApi>;
deleteCertificate(partial: Partial<DojoCertificateApi>): Promise<number>;
labelTransaction(txid: string | number | Partial<DojoTransactionApi>, label: string): Promise<void>;
unlabelTransaction(txid: string | number | Partial<DojoTransactionApi>, label: string): Promise<void>;
tagOutput(output: {
txid: string;
vout: number;
}, tag: string): Promise<void>;
untagOutput(output: {
txid: string;
vout: number;
}, tag: string): Promise<void>;
unbasketOutput(output: {
txid: string;
vout: number;
}): Promise<void>;
getEnvelopesOfConflictingTransactions(txid: string): Promise<EnvelopeApi[]>;
getHeight(): Promise<number>;
getMerkleRootForHeight(height: number): Promise<string | undefined>;
}
Interface NinjaApi Details
The dojo user wallet database supporting this api.
isAuthenticated must be true.
dojo: DojoClientApi
Abort a transaction with status unsigned
previously started by a call to createAction
with parameters meant to be completed by a call to signAction
.
abortAction(params: NinjaAbortActionParams): Promise<NinjaAbortActionResultApi>
Authenticates with configured dojo, if necessary.
authenticate(identityKey?: string, addIfNew?: boolean): Promise<void>
Argument Details
- identityKey
- Optional. The user's public identity key. Must be authorized to act on behalf of this user.
- addIfNew
- Optional. Create new user records if identityKey is unknown.
Creates a new transaction that must be processed with processTransaction
after you sign it
createTransaction(params: NinjaCreateTransactionParams): Promise<DojoCreateTransactionResultApi>
Returns
The template you need to sign and process
This method is equivalent to getTransactionWithOutputs
with params.autoProcess
false.
This function ignores params.autoProcess
Creates and signs a transaction with specified outputs.
It can be processed later with processTransaction
.
This is a higher-level wrapper around createTransaction
so that you do not need to manually handle signing,
when you are not providing any non-Dojo inputs.
Use this by default, and fall back to createTransaction
if you need more customization.
createTransactionWithOutputs(params: NinjaGetTransactionWithOutputsParams): Promise<NinjaTransactionWithOutputsResultApi>
Soft deletes a certificate.
deleteCertificate(partial: Partial<DojoCertificateApi>): Promise<number>
Argument Details
- partial
- The partial certificate data identifying the certificate to soft delete.
Use this endpoint to retrieve certificates.
findCertificates(certifiers?: string[] | object, types?: Record<string, string[]>): Promise<{
status: "success";
certificates: DojoCertificateApi[];
}>
Returns
A success object with status: "success"
and any found certificates
Argument Details
- obj
- All parameters are given in an object
Returns the name and photo URL of the user
getAvatar(): Promise<DojoAvatarApi>
Returns
The avatar of the user
Returns which BSV network we are using (main or test)
getChain(): Promise<Chain>
Return the private / public keypair used by the Ninja client for change UTXOs
getClientChangeKeyPair(): KeyPairApi
Returns array of Everett Style envelopes for transactions that spend one or
more of the inputs to transaction with txid
, which must exist in Dojo.
This method supports double spend resolution.
getEnvelopesOfConflictingTransactions(txid: string): Promise<EnvelopeApi[]>
Argument Details
- txid
- double hash of raw transaction as hex string
Returns the current chain height of the network
getHeight(): Promise<number>
Returns
The current chain height
A method to verify the validity of a Merkle root for a given block height.
getMerkleRootForHeight(height: number): Promise<string | undefined>
Returns
merkle root for the given height or undefined, if height doesn't have a known merkle root or is invalid.
Returns the net sum of transaction amounts belonging to authenticated user,
incoming minus outgoing,
and optionally matching conditions in options
.
getNetOfAmounts(options?: DojoGetTotalOfAmountsOptions): Promise<number>
Returns which BSV network we are using (mainnet or testnet)
getNetwork(format?: "default" | "nonet"): Promise<string>
Returns
The current BSV network formatted as requested.
Argument Details
- format
- for the returned string. Either with (default) or without (nonet) a 'net' suffix.
Returns the current Paymail handle
getPaymail(): Promise<string>
Returns a set of all transactions that need to be signed and submitted, or canceled
getPendingTransactions(referenceNumber?: string): Promise<DojoPendingTxApi[]>
Gets the currently configured syncDojos and sync options.
If syncDojos are not being managed by setSyncDojosByConfig
the returned configurations may include
a 'dojoType' of ''.
getSyncDojosByConfig(): Promise<{
dojos: SyncDojoConfigBaseApi[];
options?: DojoSyncOptionsApi;
}>
Returns the sum of transaction amounts belonging to authenticated user,
matching the given direction (which must be specified),
and optionally matching remaining conditions in options
.
getTotalOfAmounts(options: DojoGetTotalOfAmountsOptions): Promise<{
total: number;
}>
Returns the total of unspent outputs in satoshis. A non-negative integer.
getTotalValue(basket?: string): Promise<{
total: number;
}>
Argument Details
- basket
- defaults to 'default' if undefined
Returns transaction labels matching options and total matching count available.
getTransactionLabels(options?: DojoGetTransactionLabelsOptions): Promise<{
labels: DojoTxLabelApi[];
total: number;
}>
Argument Details
- options
- limit defaults to 25, offset defaults to 0, order defaults to 'descending'
Returns a set of transaction outputs that Dojo has tracked
getTransactionOutputs(options?: DojoGetTransactionOutputsOptions): Promise<NinjaGetTransactionOutputsResultApi[]>
Creates and signs a transaction with specified outputs and (by default) processes it.
By setting params.autoProcess
to false, it can be processed later with processTransaction
.
If params.autoProcess
is true (the default), processTransaction
is called automatically
and merged results are returned.
This is a higher-level wrapper around createTransaction
so that you do not need to manually handle signing,
when you are not providing any non-Dojo inputs.
Consider using either createTransactionWithOutputs or processTransactionWithOutputs
when params.autoProcess
does not need to change at runtime.
Use this by default, and fall back to createTransaction
if you need more customization.
getTransactionWithOutputs(params: NinjaGetTransactionWithOutputsParams): Promise<NinjaTransactionWithOutputsResultApi>
Returns a set of transactions that match the criteria
getTransactions(options?: DojoGetTransactionsOptions): Promise<NinjaGetTransactionsResultApi>
Argument Details
- options
- limit defaults to 25, offset defaults to 0, addLabels defaults to true, order defaults to 'descending'
Labels a transaction
Validates user is authenticated, txid matches an exsiting user transaction, and label value.
Creates new label if necessary.
Adds label to transaction if not already labeled. Note: previously if transaction was already labeled, an error was thrown.
labelTransaction(txid: string | number | Partial<DojoTransactionApi>, label: string): Promise<void>
Argument Details
- txid
- unique transaction identifier, either transactionId, txid, or a partial pattern.
- label
- the label to be added, will be created if it doesn't already exist
Signs and processes all pending transactions, useful when recovering from an error or crash, or on startup. If a transaction fails to process, marks it as failed.
processPendingTransactions(onTransactionProcessed?: NinjaTransactionProcessedHandler, onTransactionFailed?: NinjaTransactionFailedHandler): Promise<void>
After a transaction is created (with createTransaction
or with getTransactionWithOutputs
),
submit the serialized raw transaction to transaction processors for processing.
processTransaction(params: DojoProcessTransactionParams): Promise<DojoProcessTransactionResultApi>
Returns
DojoProcessTransactionResultApi
with txid and status of 'completed' or 'unknown'
This method is equivalent to getTransactionWithOutputs
with params.autoProcess
true.
This function ignores params.autoProcess
Creates and signs a transaction with specified outputs and processes it.
This is a higher-level wrapper around createTransaction
and processTransaction
so that you do not need to manually handle signing, when you are not providing any non-Dojo inputs.
Use this by default, and fall back to createTransaction
if you need more customization.
processTransactionWithOutputs(params: NinjaGetTransactionWithOutputsParams): Promise<NinjaTransactionWithOutputsResultApi>
Use this endpoint to store an incoming certificate.
saveCertificate(certificate: DojoCertificateApi | object): Promise<void>
Returns
A success object with status: "success"
Argument Details
- obj
- All parameters are given in an object
Sets a new name and photo URL
setAvatar(name: string, photoURL: string): Promise<void>
Argument Details
- name
- A new name
- photoURL
- A new UHRP or HTTPS URL to a photo of the user
Changes the Paymail handle of the user.
NOTE that the old handle will be available for others to use.
NOTE that to prevent span, you may only do this if there is at least one unspent output under Dojo management.
setPaymail(paymail: string): Promise<void>
Sets the syncDojo's to be used by all users by the sync()
function.
Each syncDojo config has the following properties:
'dojoType' one of 'Cloud URL' | 'Sqlite File' | 'MySql Connection' 'dojoIdentityKey' the identity key of the syncDojo. 'dojoName' the name of the syncDojo.
Currently supports three syncDojo configurations, each identified by its dojoType:
'Sqlite File'
The derived SyncDojoConfigSqliteFile
interface adds:
'filename' will be passed to Knex Sqlite3 to configure a locally accessible, single user Sqlite database.
If the database exists, it must already be configured with matching dojoIdentityKey.
If the database does not exist and can be created, it will be configured with the specified dojoIdentityKey.
'MySql Connection'
The derived SyncDojoConfigMySqlConnection
interface adds:
'connection', a stringified MySql connection object, will be passed to Knex MySql to access a network
accessible, possibly shared, MySql database.
The database must exists and must already be configured with matching dojoIdentityKey.
'Cloud URL'
The derived SyncDojoConfigCloudUrl
interface adds:
'url' the service URL of the cloud dojo with which to sync
'clientPrivateKey' should be set to the string value 'true' to enable automatic use of Authrite as the authenticated user.
'useIdentityKey' may be set to true instead of using 'clientPrivateKey' if the cloud dojo does not use Authrite for access control.
The cloud dojo must exists and must already be configured with matching dojoIdentityKey.
setSyncDojosByConfig(syncDojoConfigs: SyncDojoConfigBaseApi[], options?: DojoSyncOptionsApi): Promise<void>
Argument Details
- syncDojoConfigs
- array of syncDojos to be used. May be empty.
- options
- place holder for future synchronization control options.
Throws
ERR_BAD_REQUEST if dojo's syncDojos are managed directly, e.g. DojoExpressClient
ERR_BAD_REQUEST if an attempt to set a <custom>
sync dojo.
Complete a transaction with status unsigned
previously started by a call to createAction
with parameters meant to be completed by a call to signAction
.
signAction(params: NinjaSignActionParams): Promise<NinjaSignActionResultApi>
This endpoint allows a recipient to submit a transactions that was directly given to them by a sender. Saves the inputs and key derivation information, allowing the UTXOs to be redeemed in the future. Sets the transaction to completed and marks the outputs as spendable.
submitDirectTransaction(params: NinjaSubmitDirectTransactionParams): Promise<NinjaSubmitDirectTransactionResultApi>
Sync's the dojo's state for the authenticated user with all of the configured syncDojos
This method should only be called when either a local or remote state change occurs, or may have occurred.
User state changes are propagated across all configured syncDojos.
sync(): Promise<void>
Tags an output
Validates user is authenticated, partial identifies a single output, and tag value.
Creates new tag if necessary.
Adds tag to output if not already tagged.
tagOutput(output: {
txid: string;
vout: number;
}, tag: string): Promise<void>
Argument Details
- partial
- unique output identifier as a partial pattern.
- tag
- the tag to add, will be created if it doesn't already exist
Removes the uniquely identified output's basket assignment.
The output will no longer belong to any basket.
This is typically only useful for outputs that are no longer usefull.
unbasketOutput(output: {
txid: string;
vout: number;
}): Promise<void>
Removes a label from a transaction
Validates user is authenticated, txid matches an exsiting user transaction, and label already exits.
Does nothing if transaction is not labeled.
unlabelTransaction(txid: string | number | Partial<DojoTransactionApi>, label: string): Promise<void>
Argument Details
- txid
- unique transaction identifier, either transactionId, txid, or a partial pattern.
- label
- the label to be removed
Removes a tag from an output
Validates user is authenticated, partial identifies a single output, and tag already exits.
Does nothing if output is not tagged.
untagOutput(output: {
txid: string;
vout: number;
}, tag: string): Promise<void>
Argument Details
- partial
- unique output identifier as a partial pattern.
- tag
- the tag to be removed from the output
Use this endpoint to update the status of one of your outputs, given as the TXID of a transaction and the vout (output index) in that transaction. This is useful for flagging transaction outpoints as spent if they were inadvertantly broadcasted or used without properly submitting them to the Dojo, or to undo the spending of an output if it was never actually spent.
updateOutpointStatus(params: {
txid: string;
vout: number;
spendable: boolean;
}): Promise<void>
Argument Details
- params.txid
- The TXID of the transaction that created the output
- params.vout
- The index of the output in the transaction
- params.spendable
- The true spendability status of this outpoint
Use this endpoint to update the status of a transaction. This is useful for flagging incomplete transactions as aborted or reverting a completed transaction back into a pending status if it never got confirmed. Setting the status to "completed" or "unproven" will make any input UTXOs unavailable for spending, while any other status value will free up the UTXOs for use in other transactions.
updateTransactionStatus(params: {
reference: string;
status: DojoTransactionStatusApi;
}): Promise<void>
Argument Details
- params.reference
- The Dojo reference number for the transaction
- params.status
- The new status of the transaction
Links: API, Interfaces, Classes, Functions, Types, Variables
Input parameters to createTransaction method.
export interface NinjaCreateTransactionParams {
inputs: Record<string, DojoTxInputsApi>;
inputSelection?: DojoTxInputSelectionApi;
outputs: DojoCreateTxOutputApi[];
outputGeneration?: DojoOutputGenerationApi;
fee?: DojoFeeModelApi;
labels: string[];
note?: string;
recipient?: string;
}
Interface NinjaCreateTransactionParams Details
When the fee model is "sat/kb", this is the number of satoshis per kilobyte of block space that the transaction will pay.
fee?: DojoFeeModelApi
If Dojo needs to select more inputs beyond what you provided in the inputs
parameter,
this parameter describes which kinds of inputs can be selected, and from where.
inputSelection?: DojoTxInputSelectionApi
Specify any additional inputs to the transaction (if any) that are not to be provided by the Dojo.
If you do not provide inputs here, or if they are insufficient,
Dojo will select additional inputs for you to sign.
To control this input selection behavior, see the inputSelection
parameter.
This inputs
parameter is an object whose keys are TXIDs of input transactions,
and whose values are their associated SPV envelopes.
inputs: Record<string, DojoTxInputsApi>
The labels to affix to this transaction
labels: string[]
A numan-readable note describing the transaction
note?: string
If Dojo needs to generate additional outputs for the transaction beyond what was specified, this object describes what kind of outputs to generate, and where they should be kept.
The method used to generate outputs. "auto" selects the amount and types of generated outputs based on the selected basket's configuration for how many of each type to keep on hand, then uses Benford's law to distribute the satoshis across them. "single" just uses one output, randomly selected from the available types, that contains all the satoshis.
outputGeneration?: DojoOutputGenerationApi
External outputs that you will include when you create this transaction.
These outputs can contain custom scripts as specified by recipients.
If the inputs to the transaction go beyond what is needed to fund
these outputs (plus the transaction fee),
additional Dojo-managed UTXOs will be generated to collect
the remainder (see the outputGeneration
parameter for more on this).
outputs: DojoCreateTxOutputApi[]
The Paymail handle for the recipient of the transaction
recipient?: string
Links: API, Interfaces, Classes, Functions, Types, Variables
export interface NinjaTransactionFailedApi {
inputs: Record<string, DojoPendingTxInputApi>;
isOutgoing: boolean;
reference: string;
error: CwiError;
}
Links: API, Interfaces, Classes, Functions, Types, Variables
export interface NinjaTransactionProcessedApi {
inputs: Record<string, DojoPendingTxInputApi>;
outputs: DojoPendingTxOutputApi[];
isOutgoing: boolean;
reference: string;
txid: string;
amount: number;
hex: string;
derivationPrefix?: string;
senderIdentityKey?: string;
}
Links: API, Interfaces, Classes, Functions, Types, Variables
export interface NinjaOutputToRedeemApi {
index: number;
unlockingScript: string | number;
spendingDescription?: string;
sequenceNumber?: number;
}
Interface NinjaOutputToRedeemApi Details
Zero based output index within its transaction to spend.
index: number
Sequence number to use when spending
sequenceNumber?: number
Hex scriptcode that unlocks the satoshis or the maximum script length (in bytes) if using signAction
.
When supplying a signed unlock script, it should use SIGHASH_NONE | ANYONECANPAY
(or similar)
so additional Dojo outputs can added if necessary without invalidating the signature.
unlockingScript: string | number
Links: API, Interfaces, Classes, Functions, Types, Variables
export interface NinjaTxInputsApi extends EnvelopeEvidenceApi {
outputsToRedeem: NinjaOutputToRedeemApi[];
}
Links: API, Interfaces, Classes, Functions, Types, Variables
export interface KeyPairApi {
privateKey: string;
publicKey: string;
}
Links: API, Interfaces, Classes, Functions, Types, Variables
export interface NinjaGetTransactionsTxApi extends ListActionsTransaction {
txid: string;
amount: number;
status: TransactionStatusApi;
senderPaymail: string;
recipientPaymail: string;
isOutgoing: boolean;
note: string;
created_at: string;
referenceNumber: string;
labels: string[];
inputs?: NinjaGetTransactionsTxInputApi[];
outputs?: NinjaGetTransactionsTxOutputApi[];
}
Interface NinjaGetTransactionsTxApi Details
The number of satoshis added or removed from Dojo by this transaction
amount: number
The time the transaction was registered with the Dojo
created_at: string
Whether or not the transaction was created with createTransaction
isOutgoing: boolean
A set of all the labels affixed to the transaction
labels: string[]
The human-readable tag for the transaction, provided by the person who initiated it
note: string
The Paymail handle of the person who received the transaction
recipientPaymail: string
The Dojo reference number for the transaction
referenceNumber: string
The Paymail handle of the person who sent the transaction
senderPaymail: string
The current state of the transaction. Common statuses are completed
and unproven
.
status: TransactionStatusApi
The transaction ID
txid: string
Links: API, Interfaces, Classes, Functions, Types, Variables
export interface NinjaGetTransactionsTxInputApi extends ListActionsTransactionInput {
txid: string;
vout: number;
amount: number;
outputScript: string;
type: string;
spendable: boolean;
spendingDescription?: string;
basket?: string;
tags?: string[];
}
Interface NinjaGetTransactionsTxInputApi Details
Number of satoshis in the output
amount: number
Optionally included basket assignment.
basket?: string
Hex representation of output locking script
outputScript: string
Whether this output is free to be spent
spendable: boolean
Spending description for this transaction input
spendingDescription?: string
Optionally included tag assignments.
tags?: string[]
Transaction ID of transaction that created the output
txid: string
The type of output, for example "P2PKH" or "P2RPH"
type: string
Index in the transaction of the output
vout: number
Links: API, Interfaces, Classes, Functions, Types, Variables
export interface NinjaGetTransactionsTxOutputApi extends ListActionsTransactionOutput {
txid: string;
vout: number;
amount: number;
outputScript: string;
type: string;
spendable: boolean;
description?: string;
basket?: string;
tags?: string[];
}
Interface NinjaGetTransactionsTxOutputApi Details
Number of satoshis in the output
amount: number
Optionally included basket assignment.
basket?: string
Output description
description?: string
Hex representation of output locking script
outputScript: string
Whether this output is free to be spent
spendable: boolean
Optionally included tag assignments.
tags?: string[]
Transaction ID of transaction that created the output
txid: string
The type of output, for example "P2PKH" or "P2RPH"
type: string
Index in the transaction of the output
vout: number
Links: API, Interfaces, Classes, Functions, Types, Variables
export interface NinjaGetTransactionsResultApi {
totalTransactions: number;
transactions: NinjaGetTransactionsTxApi[];
}
Interface NinjaGetTransactionsResultApi Details
The number of transactions in the complete set
totalTransactions: number
The specific transactions from the set that were requested, based on limit
and offset
transactions: NinjaGetTransactionsTxApi[]
Links: API, Interfaces, Classes, Functions, Types, Variables
export interface NinjaTransactionWithOutputsResultApi {
signActionRequired?: boolean;
createResult?: DojoCreateTransactionResultApi;
rawTx?: string;
txid?: string;
amount: number;
inputs: Record<string, EnvelopeEvidenceApi>;
note?: string;
referenceNumber: string;
outputMap?: Record<string, number>;
mapiResponses?: MapiResponseApi[];
log?: string;
}
Interface NinjaTransactionWithOutputsResultApi Details
The amount of the transaction
amount: number
if signActionRequired, the dojo createTransaction results to be forwarded to signAction
createResult?: DojoCreateTransactionResultApi
This is the fully-formed inputs
field of this transaction, as per the SPV Envelope specification.
inputs: Record<string, EnvelopeEvidenceApi>
Optional transaction processing history
log?: string
If processed, array of acceptance responses from mapi transaction processors.
Only valid if signActionRequired !== true
mapiResponses?: MapiResponseApi[]
Map of change output derivationSuffix values to transaction vout indices
Only valid if signActionRequired !== true
outputMap?: Record<string, number>
The serialized, signed transaction that is ready for broadcast, or has been broadcast.
Only valid if signActionRequired !== true
rawTx?: string
The reference number that should now be provided back to processTransaction (or
updateTransactionStatus`)
referenceNumber: string
true if at least one input's outputsToRedeem uses numeric max script byte length for unlockingScript
If true, in-process transaction will have status unsigned
. An unsigned
transaction must be completed
by signing all remaining unsigned inputs and calling signAction
. Failure to complete the process in
a timely manner will cause the transaction to transition to failed
.
If false or undefined, completed transaction will have status of sending
or unproven
,
depending on acceptDelayedBroadcast
being true or false.
signActionRequired?: boolean
rawTx hash as hex string
Only valid if signActionRequired !== true
txid?: string
Links: API, Interfaces, Classes, Functions, Types, Variables
export interface NinjaGetPendingTransactionsInstructionsApi {
type: string;
derivationPrefix: string | null;
derivationSuffix: string | null;
paymailHandle: string | null;
senderIdentityKey: string | null;
customInstructions: string | null;
}
Interface NinjaGetPendingTransactionsInstructionsApi Details
max length of 2500
customInstructions: string | null
max length of 32 base64 encoded
derivationPrefix: string | null
max length of 32 base64 encoded
derivationSuffix: string | null
max length of 64
paymailHandle: string | null
max length of 130 hex encoded
senderIdentityKey: string | null
max length of 50 e.g. P2PKH, custom
type: string
Links: API, Interfaces, Classes, Functions, Types, Variables
export interface NinjaGetPendingTransactionsInputApi extends EnvelopeEvidenceApi {
outputsToRedeem: number[];
instructions: Record<number, NinjaGetPendingTransactionsInstructionsApi>;
}
Links: API, Interfaces, Classes, Functions, Types, Variables
export interface NinjaGetPendingTransactionsTxApi {
transactionId: number;
created_at: string;
provenTxId?: number | null;
status: DojoTransactionStatusApi;
isOutgoing: boolean;
amount: number;
senderPaymail: string | undefined | null;
referenceNumber: string;
truncatedExternalInputs: string | null;
rawTransaction: Buffer | null;
inputs?: Record<string, NinjaGetPendingTransactionsInputApi>;
}
Interface NinjaGetPendingTransactionsTxApi Details
The number of satoshis added or removed from Dojo by this transaction
amount: number
The time the transaction was registered with the Dojo
created_at: string
parsed truncatedExternalInputs
inputs?: Record<string, NinjaGetPendingTransactionsInputApi>
Is valid when transaction proof record exists in DojoProvenTxApi table.
provenTxId?: number | null
The Dojo reference number for the transaction
referenceNumber: string
The Paymail handle of the person who sent the transaction
senderPaymail: string | undefined | null
max length of 64 e.g. unprocessed, unsigned
status: DojoTransactionStatusApi
Links: API, Interfaces, Classes, Functions, Types, Variables
export interface TxRedeemableOutputApi {
index: number;
unlockingScriptLength: number;
}
Interface TxRedeemableOutputApi Details
The index of the output to redeem in the transaction
index: number
The byte length of the unlocking script you intend to use to unlock this output
unlockingScriptLength: number
Links: API, Interfaces, Classes, Functions, Types, Variables
export interface TxOutputApi {
satoshis: number;
script: string;
}
Interface TxOutputApi Details
The amount of satoshis that will be in the output
satoshis: number
The hex string representing the output locking script
script: string
Links: API, Interfaces, Classes, Functions, Types, Variables
export interface NinjaGetTransactionOutputsResultApi extends GetTransactionOutputResult {
txid: string;
vout: number;
amount: number;
outputScript: string;
type: string;
spendable: boolean;
envelope?: EnvelopeApi;
customInstructions?: string;
basket?: string;
tags?: string[];
}
Interface NinjaGetTransactionOutputsResultApi Details
Number of satoshis in the output
amount: number
If includeBasket
option is true, name of basket to which this output belongs.
basket?: string
When envelope requested, any custom instructions associated with this output.
customInstructions?: string
When requested and available, output validity support envelope.
envelope?: EnvelopeApi
Hex representation of output locking script
outputScript: string
Whether this output is free to be spent
spendable: boolean
If includeTags
option is true, tags assigned to this output.
tags?: string[]
Transaction ID of transaction that created the output
txid: string
The type of output, for example "P2PKH" or "P2RPH"
type: string
Index in the transaction of the output
vout: number
Links: API, Interfaces, Classes, Functions, Types, Variables
export interface NinjaSubmitDirectTransactionOutputApi extends SubmitDirectTransactionOutput {
vout: number;
satoshis: number;
basket?: string;
derivationPrefix?: string;
derivationSuffix?: string;
customInstructions?: string;
senderIdentityKey?: string;
tags?: string[];
}
Links: API, Interfaces, Classes, Functions, Types, Variables
Transaction input parameter to submitDirectTransaction method.
export interface NinjaSubmitDirectTransactionApi extends SubmitDirectTransaction {
rawTx: string;
txid?: string;
inputs?: Record<string, EnvelopeEvidenceApi>;
mapiResponses?: MapiResponseApi[];
proof?: TscMerkleProofApi;
outputs: NinjaSubmitDirectTransactionOutputApi[];
referenceNumber?: string;
}
Interface NinjaSubmitDirectTransactionApi Details
sparse array of outputs of interest where indices match vout numbers.
outputs: NinjaSubmitDirectTransactionOutputApi[]
Links: API, Interfaces, Classes, Functions, Types, Variables
Input parameters to submitDirectTransaction method.
export interface NinjaSubmitDirectTransactionParams {
protocol?: string;
transaction: NinjaSubmitDirectTransactionApi;
senderIdentityKey: string;
note: string;
labels?: string[];
derivationPrefix?: string;
amount?: number;
}
Interface NinjaSubmitDirectTransactionParams Details
A derivation prefix used for all outputs. If provided, derivation prefixes on all outputs are optional.
derivationPrefix?: string
Labels to assign to transaction.
labels?: string[]
Human-readable description for the transaction
note: string
Specify the transaction submission payment protocol to use. Currently, the only supported protocol is that with BRFC ID "3241645161d8"
protocol?: string
Provide the identity key for the person who sent the transaction
senderIdentityKey: string
The transaction envelope to submit, including key derivation information.
transaction.outputs is an array of outputs, each containing:
vout
,
satoshis
,
derivationSuffix
,
and (optionally), derivationPrefix
.
If a global derivationPrefix
is used (recommended),
output-specific derivation prefixes should be omitted.
transaction: NinjaSubmitDirectTransactionApi
Links: API, Interfaces, Classes, Functions, Types, Variables
export interface NinjaSubmitDirectTransactionResultApi extends SubmitDirectTransactionResult {
transactionId: number;
referenceNumber: string;
}
Links: API, Interfaces, Classes, Functions, Types, Variables
export interface NinjaSignCreatedTransactionParams {
inputs: Record<string, NinjaTxInputsApi>;
createResult: DojoCreateTransactionResultApi;
}
Interface NinjaSignCreatedTransactionParams Details
Input scripts to spend as part of this transaction.
This is an object whose keys are TXIDs and whose values are Everett-style
transaction envelopes that contain an additional field called outputsToRedeem
.
This is an array of objects, each containing index
and unlockingScript
properties.
The index
property is the output number in the transaction you are spending,
and unlockingScript
is the hex scriptcode that unlocks the satoshis.
Note that you should create any signatures with SIGHASH_NONE | ANYONECANPAY
or similar
so that the additional Dojo outputs can be added afterward without invalidating your signature.
inputs: Record<string, NinjaTxInputsApi>
Links: API, Interfaces, Classes, Functions, Types, Variables
Input parameters to getTransactionWithOutputs method.
export interface NinjaGetTransactionWithOutputsParams {
outputs: DojoCreateTxOutputApi[];
labels?: string[];
inputs?: Record<string, NinjaTxInputsApi>;
note?: string;
lockTime?: number;
version?: number;
recipient?: string;
autoProcess?: boolean;
feePerKb?: number;
feeModel?: DojoFeeModelApi;
acceptDelayedBroadcast?: boolean;
log?: string;
}
Interface NinjaGetTransactionWithOutputsParams Details
Set to true for normal, high performance operation and offline operation if running locally.
Always validates submittedTransaction
and remaining inputs.
If true, creates a self-signed MapiResponse for the transaction
and queues it for repeated broadcast attempts and proof validation.
The status
of the transaction will be set to unproven
.
If not true, attempts one broadcast and fails the transaction if it is not accepted by at least one external transaction processor. If it is accepted, status is set to `unproven'. The transaction may still fail at a later time if a merkle proof is not confirmed.
The transaction status will be set to completed
or failed
depending on the success or failure of broadcast attempts
and Chaintracks validation of a merkle proof.
When status is set to unproven
or completed
:
- Inputs are confirmed to be spendable false, spentBy this transaction.
- Outputs are set to spendable true unless already spent (spentBy is non-null).
If the transaction fails, status is set to failed
:
- Inputs are returned to spendable true, spentBy null
- Outputs are set to spendable false
- If spentBy is non-null, failure propagates to that transaction.
acceptDelayedBroadcast?: boolean
Whether the transaction should be processed automatically
with processTransaction. Note that this will return mapiResponses
and note
instead of referenceNumber
default true
autoProcess?: boolean
Optional. The fee model used by this transaction.
If both feeModel and feePerKb are specified, feeModel takes precendence
feeModel?: DojoFeeModelApi
Optional. The number of satoshis to pay per KB of block space used by this transaction.
If both feeModel and feePerKb are specified, feeModel takes precendence
feePerKb?: number
Input scripts to spend as part of this transaction.
This is an object whose keys are TXIDs and whose values are Everett-style
transaction envelopes that contain an additional field called outputsToRedeem
.
This is an array of objects, each containing index
and unlockingScript
properties.
The index
property is the output number in the transaction you are spending,
and unlockingScript
is the hex scriptcode that unlocks the satoshis or the maximum script length for signActionRequired.
Note that you should create any signatures with SIGHASH_NONE | ANYONECANPAY
or similar
so that the additional Dojo outputs can be added afterward without invalidating your signature.
inputs?: Record<string, NinjaTxInputsApi>
A set of label strings to affix to the transaction
labels?: string[]
Optional. Default is zero. When the transaction can be processed into a block:
= 500,000,000 values are interpreted as minimum required unix time stamps in seconds < 500,000,000 values are interpreted as minimum required block height
lockTime?: number
Optional transaction processing log
log?: string
A note about the transaction
note?: string
A set of outputs to include, each with script
and satoshis
.
outputs: DojoCreateTxOutputApi[]
Paymail recipient for transaction
recipient?: string
Optional. Transaction version number, default is current standard transaction version value.
version?: number
Links: API, Interfaces, Classes, Functions, Types, Variables
export interface NinjaCompleteCreateTransactionWithOutputsParams {
inputs?: Record<string, NinjaTxInputsApi>;
note?: string;
createResult: DojoCreateTransactionResultApi;
}
Interface NinjaCompleteCreateTransactionWithOutputsParams Details
Input scripts to spend as part of this transaction.
This is an object whose keys are TXIDs and whose values are Everett-style
transaction envelopes that contain an additional field called outputsToRedeem
.
This is an array of objects, each containing index
and unlockingScript
properties.
The index
property is the output number in the transaction you are spending,
and unlockingScript
is the hex scriptcode that unlocks the satoshis.
Note that you should create any signatures with SIGHASH_NONE | ANYONECANPAY
or similar
so that the additional Dojo outputs can be added afterward without invalidating your signature.
inputs?: Record<string, NinjaTxInputsApi>
Links: API, Interfaces, Classes, Functions, Types, Variables
export interface NinjaSignActionParams extends NinjaSignCreatedTransactionParams {
inputs: Record<string, NinjaTxInputsApi>;
createResult: DojoCreateTransactionResultApi;
acceptDelayedBroadcast?: boolean;
}
Interface NinjaSignActionParams Details
Must match original value passed to createAction
.
acceptDelayedBroadcast?: boolean
The dojo createTransaction results returned from createAction.
createResult: DojoCreateTransactionResultApi
Input scripts to spend as part of this transaction.
This is an object whose keys are TXIDs and whose values are Everett-style
transaction envelopes that contain an additional field called outputsToRedeem
.
This is an array of objects, each containing index
and unlockingScript
properties.
The index
property is the output number in the transaction you are spending,
and unlockingScript
is the hex scriptcode that unlocks the satoshis.
Note that you should create any signatures with SIGHASH_NONE | ANYONECANPAY
or similar
so that the additional Dojo outputs can be added afterward without invalidating your signature.
inputs: Record<string, NinjaTxInputsApi>
Links: API, Interfaces, Classes, Functions, Types, Variables
export interface NinjaSignActionResultApi extends NinjaTransactionWithOutputsResultApi {
rawTx?: string;
txid?: string;
amount: number;
inputs: Record<string, EnvelopeEvidenceApi>;
note?: string;
referenceNumber: string;
outputMap?: Record<string, number>;
mapiResponses?: MapiResponseApi[];
log?: string;
}
Interface NinjaSignActionResultApi Details
The amount of the transaction
amount: number
This is the fully-formed inputs
field of this transaction, as per the SPV Envelope specification.
inputs: Record<string, EnvelopeEvidenceApi>
Optional transaction processing history
log?: string
If processed, array of acceptance responses from mapi transaction processors.
Only valid if signActionRequired !== true
mapiResponses?: MapiResponseApi[]
Map of change output derivationSuffix values to transaction vout indices
Only valid if signActionRequired !== true
outputMap?: Record<string, number>
The serialized, signed transaction that is ready for broadcast, or has been broadcast.
Only valid if signActionRequired !== true
rawTx?: string
The reference number that should now be provided back to processTransaction (or
updateTransactionStatus`)
referenceNumber: string
rawTx hash as hex string
Only valid if signActionRequired !== true
txid?: string
Links: API, Interfaces, Classes, Functions, Types, Variables
export interface NinjaAbortActionParams {
referenceNumber: string;
log: string | undefined;
}
Interface NinjaAbortActionParams Details
Optional operational and performance logging prior data.
log: string | undefined
unique transaction identifier previously returned by createAction when at least one unlockingScript was specified by max script byte length.
The status of the transaction identified by referenceNumber
must be unsigned
.
referenceNumber: string
Links: API, Interfaces, Classes, Functions, Types, Variables
export interface NinjaAbortActionResultApi {
referenceNumber: string;
log: string | undefined;
}
Interface NinjaAbortActionResultApi Details
operational and performance logging if enabled.
log: string | undefined
The unique transaction identifier that was processed.
referenceNumber: string
Links: API, Interfaces, Classes, Functions, Types, Variables
Starting point for cwi-core's typescript api.
Supports design and testing.
export interface CwiCoreApi {
createAction(params: CreateActionParams): Promise<CreateActionResult>;
}
Links: API, Interfaces, Classes, Functions, Types, Variables
export interface CreateActionParams {
description: string;
inputs: Record<string, NinjaTxInputsApi>;
outputs: DojoCreateTxOutputApi[];
lockTime?: number;
version?: number;
labels?: string[];
originator?: string;
acceptDelayedBroadcast?: boolean;
log?: string;
}
Interface CreateActionParams Details
true if local validation and self-signed mapi response is sufficient.
Upon return, transaction will have sending
status. Watchman will proceed to send the transaction asynchronously.
false if a valid mapi response from the bitcoin transaction processing network is required.
Upon return, transaction will have unproven
status. Watchman will proceed to prove transaction.
default true
acceptDelayedBroadcast?: boolean
Human readable string giving the purpose of this transaction. Value will be encrypted prior to leaving this device. Encrypted length limit is 500 characters.
description: string
each input's outputsToRedeem:
- satoshis must be greater than zero, must match output's value.
- spendingDescription length limit is 50, values are encrypted before leaving this device
- unlockingScript is max byte length for
signActionRequired
mode, otherwise hex string.
inputs: Record<string, NinjaTxInputsApi>
transaction labels to apply to this transaction default []
labels?: string[]
Optional. Default is zero. When the transaction can be processed into a block:
= 500,000,000 values are interpreted as minimum required unix time stamps in seconds < 500,000,000 values are interpreted as minimum required block height
lockTime?: number
Optional operational and performance logging prior data.
log?: string
Reserved Admin originators 'projectbabbage.com' 'staging-satoshiframe.babbage.systems' 'satoshiframe.babbage.systems'
originator?: string
each output:
- description length limit is 50, values are encrypted before leaving this device
outputs: DojoCreateTxOutputApi[]
Optional. Transaction version number, default is current standard transaction version value.
version?: number
Links: API, Interfaces, Classes, Functions, Types, Variables
export interface CreateActionResult {
signActionRequired?: boolean;
createResult?: DojoCreateTransactionResultApi;
txid?: string;
rawTx?: string;
inputs: Record<string, EnvelopeEvidenceApi>;
mapiResponses?: MapiResponseApi[];
log?: string;
}
Interface CreateActionResult Details
if signActionRequired, the dojo createTransaction results to be forwarded to signAction
createResult?: DojoCreateTransactionResultApi
This is the fully-formed inputs
field of this transaction, as per the SPV Envelope specification.
inputs: Record<string, EnvelopeEvidenceApi>
operational and performance logging if enabled.
log?: string
If not signActionRequired
, at least one valid mapi response.
may be a self-signed response if acceptDelayedBroadcast
is true.
If signActionRequired
, empty array.
mapiResponses?: MapiResponseApi[]
if not signActionRequired, fully signed transaction as LE hex string
if signActionRequired:
- All length specified unlocking scripts are zero bytes
- All SABPPP template unlocking scripts have zero byte signatures
- All custom provided unlocking scripts fully copied.
rawTx?: string
true if at least one input's outputsToRedeem uses numeric max script byte length for unlockingScript
If true, in-process transaction will have status unsigned
. An unsigned
transaction must be completed
by signing all remaining unsigned inputs and calling signAction
. Failure to complete the process in
a timely manner will cause the transaction to transition to failed
.
If false or undefined, completed transaction will have status of sending
or unproven
,
depending on acceptDelayedBroadcast
being true or false.
signActionRequired?: boolean
if not signActionRequired, signed transaction hash (double SHA256 BE hex string)
txid?: string
Links: API, Interfaces, Classes, Functions, Types, Variables
export interface SignActionParams {
inputs: Record<string, NinjaTxInputsApi>;
createResult?: NinjaTransactionWithOutputsResultApi;
originator?: string;
acceptDelayedBroadcast?: boolean;
log?: string;
}
Interface SignActionParams Details
true if local validation and self-signed mapi response is sufficient.
Upon return, transaction will have sending
status. Watchman will proceed to send the transaction asynchronously.
false if a valid mapi response from the bitcoin transaction processing network is required.
Upon return, transaction will have unproven
status. Watchman will proceed to prove transaction.
Must match CreateActionParams value.
default true
acceptDelayedBroadcast?: boolean
the dojo createTransaction results returned from createAction to be forwarded to signAction
createResult?: NinjaTransactionWithOutputsResultApi
each input's outputsToRedeem:
- satoshis must be greater than zero, must match output's value.
- spendingDescription length limit is 50, values are encrypted before leaving this device
- unlockingScript must all be hex string.
Must match CreateActionParams with the exception of fully resolved unlockingScript values.
inputs: Record<string, NinjaTxInputsApi>
Optional operational and performance logging prior data.
log?: string
Reserved Admin originators 'projectbabbage.com' 'staging-satoshiframe.babbage.systems' 'satoshiframe.babbage.systems'
originator?: string
Links: API, Interfaces, Classes, Functions, Types, Variables
export interface ProcessIncomingTransactionInputApi {
}
Links: API, Interfaces, Classes, Functions, Types, Variables
export interface ProcessIncomingTransactionOutputApi {
vout?: number;
satoshis?: number;
amount?: number;
senderIdentityKey?: string;
derivationSuffix?: string;
derivationPrefix?: string;
paymailHandle?: string;
}
Links: API, Interfaces, Classes, Functions, Types, Variables
export interface ProcessIncomingTransactionApi {
inputs?: Record<string, ProcessIncomingTransactionInputApi>;
outputs: ProcessIncomingTransactionOutputApi[];
referenceNumber?: string;
rawTransaction?: string;
rawTx?: string;
derivationPrefix?: string;
}
Links: API, Interfaces, Classes, Functions, Types, Variables
export interface ProcessIncomingTransactionResultApi {
txid: string;
amount: number;
derivationPrefix?: string;
senderIdentityKey?: string;
}
Links: API, Interfaces, Classes, Functions, Types, Variables
export interface DojoTxBuilderInputApi {
txid: string;
vout: number;
satoshis: number;
scriptLength: number;
script?: string;
}
Links: API, Interfaces, Classes, Functions, Types, Variables
export interface DojoTxBuilderOutputApi {
satoshis: number;
script: string;
vout: number;
index: number;
change: boolean;
}
Links: API, Interfaces, Classes, Functions, Types, Variables
export interface DojoTxBuilderBaseOptions {
}
Links: API, Interfaces, Classes, Functions, Types, Variables
export interface NinjaTxBuilderOptions extends DojoTxBuilderBaseOptions {
}
Links: API, Interfaces, Classes, Functions, Types, Variables
export interface DojoExpressClientOptions {
authrite?: AuthriteClient;
identityKey?: string;
}
Links: API, Interfaces, Classes, Functions, Types, Variables
export interface DojoTxBuilderOptions extends DojoTxBuilderBaseOptions {
}
Links: API, Interfaces, Classes, Functions, Types, Variables
export interface NinjaV1Params {
privateKey?: string;
config?: {
dojoURL: string;
};
taalApiKeys?: {
test: string;
main: string;
};
}
Links: API, Interfaces, Classes, Functions, Types, Variables
DojoExpressClient |
DojoTxBuilder |
DojoTxBuilderBase |
ERR_NINJA_INVALID_UNLOCK |
ERR_NINJA_MISSING_UNLOCK |
Ninja |
NinjaBase |
NinjaTxBuilder |
NinjaV2 |
Links: API, Interfaces, Classes, Functions, Types, Variables
export class DojoTxBuilderBase {
constructor(public dojo: DojoClientApi, public baseOptions?: DojoTxBuilderBaseOptions)
inputs: DojoTxBuilderInputApi[];
outputs: DojoTxBuilderOutputApi[];
outputsChange: DojoTxBuilderOutputApi[];
funding(): number
spending(): number
change(): number
amount(): number
feeForSize(bytes: number): number
feeRequired(): number
feeExcess(): number
addOutputs(outputs: Array<DojoCreateTxOutputApi | DojoCreatingTxOutputApi | DojoTxBuilderOutputApi>): void
addChangeOutputs(outputs: Array<DojoCreateTxOutputApi | DojoCreatingTxOutputApi | DojoTxBuilderOutputApi>): void
addInputs(inputs: Record<string, DojoCreatingTxInputsApi>): void
addInputsToFundOutputs(inputs: DojoTxBuilderInputApi[]): void
addChangeOutputsToRecoverExcessFee(getChangeOutput: () => DojoTxBuilderOutputApi | undefined): void
validateOutput(o: DojoCreateTxOutputApi): void
validate(noThrow = false): {
ok: boolean;
error: CwiError | undefined;
}
}
Class DojoTxBuilderBase Details
inputs that will fund the transaction
inputs: DojoTxBuilderInputApi[]
outputs with pre-determined, non-adjustable amounts that will be created by the transaction
outputs: DojoTxBuilderOutputApi[]
change outputs generated to recapture excess funding owned by authenticated user. adjustable amounts.
outputsChange: DojoTxBuilderOutputApi[]
Add change outputs to transaction outputsChange
.
All change outputs are added.
addChangeOutputs(outputs: Array<DojoCreateTxOutputApi | DojoCreatingTxOutputApi | DojoTxBuilderOutputApi>): void
Argument Details
- outputs
- to add to transaction
outputsChange
- to add to transaction
Repeatedly calls getChangeOutput
and adds the new returned change output
while feeExcess
is positive and returned output is not undefined.
If getChangeOutput
returns an output that would overspend (feeExcess < 0)
it is not added and the function returns.
addChangeOutputsToRecoverExcessFee(getChangeOutput: () => DojoTxBuilderOutputApi | undefined): void
Argument Details
- getChangeOutput
- a function that returns a single new change output or undefined if done.
Add inputs to transaction inputs
.
All inputs are added.
addInputs(inputs: Record<string, DojoCreatingTxInputsApi>): void
Argument Details
- inputs
- to add to transaction
inputs
- to add to transaction
Add inputs sequentially to transaction inputs
while feeExcess
is negative.
addInputsToFundOutputs(inputs: DojoTxBuilderInputApi[]): void
Argument Details
- inputs
- to add to transaction
inputs
, removes inputs used from array
- to add to transaction
Add outputs to transaction outputs
.
All outputs are added.
addOutputs(outputs: Array<DojoCreateTxOutputApi | DojoCreatingTxOutputApi | DojoTxBuilderOutputApi>): void
Argument Details
- outputs
- to add to transaction
outputs
- to add to transaction
The amount of this transaction as currently configured.
change
less funding
Normally negative. The is the change in total value of authenticated user's unspent outputs.
amount(): number
The current total value in satoshis of the amounts for all outputsChange
change(): number
Must return the current excess fee for the transaction as currently configured.
The base class defines this as funding() - spending() - change() - requiredFee()
Because adding an input, or output, increments the counts, which are varints, compute the excess fee being paid for the transaction as a whole based on current choices:
- inputs
- outputs
- changeOutputs
The goal is an excess fee of zero.
A positive value is okay if the cost of an additional change output is greater.
A negative value means the transaction is under funded, or over spends, and may be rejected.
feeExcess(): number
Must return the fee required by miners for a transaction of a certain size.
feeForSize(bytes: number): number
Argument Details
- bytes
- size in bytes
Must return the fee required by miners for the transaction as currently configured.
The base class implementation computes the transaction size in bytes and applies
the fee rate established by the abstract feeForSize
function.
feeRequired(): number
The current total value in satoshis of the selected inputs,
funding(): number
The current total value in satoshis of the amounts for all outputs
spending(): number
validate current transaction configuration
if ok
is true, a valid transaction can be created
if ok
is false, error
is not undefined and has details one issue.
validate(noThrow = false): {
ok: boolean;
error: CwiError | undefined;
}
Links: API, Interfaces, Classes, Functions, Types, Variables
Unlocking script for vin ${vin} (${txid}.${vout}) of new transaction is invalid.
export class ERR_NINJA_INVALID_UNLOCK extends CwiError {
constructor(public vin: number, public txid: string, public vout: number, public signedRawTx: string, public e?: CwiError)
}
Links: API, Interfaces, Classes, Functions, Types, Variables
Unlocking script for vin ${vin} of new transaction is invalid.
export class ERR_NINJA_MISSING_UNLOCK extends CwiError {
constructor(vin: number)
}
Links: API, Interfaces, Classes, Functions, Types, Variables
NinjaTxBuilder is intended to complement DojoTxBuilder, implementing the signing functions that only Ninja can do with access to private keys.
Ultimately most of the generically useful code that supports building and signing actual bitcoin transactions should be collected here.
This is a work in progress...
export class NinjaTxBuilder extends DojoTxBuilderBase {
constructor(public ninja: NinjaApi, public options?: NinjaTxBuilderOptions)
static buildJsTxFromPendingTx(ninja: NinjaBase, ptx: DojoPendingTxApi): {
tx: bsvJs.Transaction;
outputMap: Record<string, number>;
amount: number;
}
static buildJsTxFromCreateTransactionResult(ninja: NinjaApi, inputs: Record<string, NinjaTxInputsApi>, createResult: DojoCreateTransactionResultApi): {
tx: bsvJs.Transaction;
outputMap: Record<string, number>;
amount: number;
log?: string;
}
static buildJsTx(ninja: NinjaApi, ninjaInputs: Record<string, NinjaTxInputsApi>, dojoInputs: Record<string, DojoCreatingTxInputsApi>, dojoOutputs: DojoCreatingTxOutputApi[], derivationPrefix: string, version: number, lockTime: number, paymailHandle?: string, log?: string): {
tx: bsvJs.Transaction;
outputMap: Record<string, number>;
amount: number;
log?: string;
}
}
Class NinjaTxBuilder Details
static buildJsTx(ninja: NinjaApi, ninjaInputs: Record<string, NinjaTxInputsApi>, dojoInputs: Record<string, DojoCreatingTxInputsApi>, dojoOutputs: DojoCreatingTxOutputApi[], derivationPrefix: string, version: number, lockTime: number, paymailHandle?: string, log?: string): {
tx: bsvJs.Transaction;
outputMap: Record<string, number>;
amount: number;
log?: string;
}
Returns
new signed bitcoin transaction, output map, an impact amount on authority's balance
Argument Details
- ninja
- The authority constructing this new transaction
- ninjaInputs
- External inputs to be added not known to ninja's dojo.
- dojoInputs
- Inputs to be added that are known to ninja's dojo.
- dojoOutputs
- All new outputs to be created
Links: API, Interfaces, Classes, Functions, Types, Variables
Connects to a DojoExpress to implement DojoApi
export class DojoExpressClient implements DojoClientApi {
static createDojoExpressClientOptions(): DojoExpressClientOptions
authrite?: AuthriteClient;
options: DojoExpressClientOptions;
get userId(): number
get identityKey(): string
get isAuthenticated(): boolean
syncDojoConfig?: SyncDojoConfigBaseApi;
constructor(public chain: Chain, public serviceUrl: string, options?: DojoExpressClientOptions)
isDojoExpressClient(): boolean
async destroy(): Promise<void>
async getChain(): Promise<Chain>
async stats(): Promise<DojoStatsApi>
async getDojoIdentity(): Promise<DojoIdentityApi>
async authenticate(identityKey?: string, addIfNew?: boolean): Promise<void>
getUser(): DojoClientUserApi
async verifyAuthenticated(): Promise<void>
async getSyncDojoConfig(): Promise<SyncDojoConfigBaseApi>
setSyncDojos(dojos: DojoSyncApi[], syncOptions?: DojoSyncOptionsApi | undefined): void
getSyncDojos(): {
dojos: DojoSyncApi[];
options: DojoSyncOptionsApi;
}
async setSyncDojosByConfig(syncDojoConfigs: SyncDojoConfigBaseApi[], options?: DojoSyncOptionsApi | undefined): Promise<void>
async getSyncDojosByConfig(): Promise<{
dojos: SyncDojoConfigBaseApi[];
options?: DojoSyncOptionsApi | undefined;
}>
async sync(): Promise<void>
async syncIdentify(params: DojoSyncIdentifyParams): Promise<DojoSyncIdentifyResultApi>
async syncUpdate(params: DojoSyncUpdateParams): Promise<DojoSyncUpdateResultApi>
async syncMerge(params: DojoSyncMergeParams): Promise<DojoSyncMergeResultApi>
async getCurrentPaymails(): Promise<string[]>
async getAvatar(): Promise<DojoAvatarApi>
async setAvatar(avatar: DojoAvatarApi): Promise<void>
async saveCertificate(certificate: DojoCertificateApi): Promise<number>
async findCertificates(certifiers?: string[], types?: Record<string, string[]>): Promise<DojoCertificateApi[]>
async getTotalOfUnspentOutputs(basket?: string): Promise<number | undefined>
async updateOutpointStatus(txid: string, vout: number, spendable: boolean): Promise<void>
async getTotalOfAmounts(direction: "incoming" | "outgoing", options?: DojoGetTotalOfAmountsOptions): Promise<number>
async getNetOfAmounts(options?: DojoGetTotalOfAmountsOptions): Promise<number>
async updateTransactionStatus(reference: string, status: DojoTransactionStatusApi): Promise<void>
async getTransactions(options?: DojoGetTransactionsOptions): Promise<DojoGetTransactionsResultApi>
async getPendingTransactions(referenceNumber?: string): Promise<DojoPendingTxApi[]>
async getEnvelopeForTransaction(txid: string): Promise<EnvelopeApi | undefined>
async getEnvelopesOfConflictingTransactions(txid: string): Promise<EnvelopeApi[]>
async getTransactionOutputs(options?: DojoGetTransactionOutputsOptions): Promise<DojoGetTransactionOutputsResultApi>
async getTransactionLabels(options?: DojoGetTransactionLabelsOptions): Promise<DojoGetTransactionLabelsResultApi>
async createTransaction(params: DojoCreateTransactionParams): Promise<DojoCreateTransactionResultApi>
async processTransaction(params: DojoProcessTransactionParams): Promise<DojoProcessTransactionResultApi>
async submitDirectTransaction(params: DojoSubmitDirectTransactionParams): Promise<DojoSubmitDirectTransactionResultApi>
async copyState(): Promise<DojoUserStateApi>
async getJsonOrUndefined<T>(path: string): Promise<T | undefined>
async getJson<T>(path: string): Promise<T>
handleError<T>(s: FetchStatus<T>, path: string): void
async postJsonOrUndefined<T, R>(path: string, params: T, noAuth?: boolean): Promise<R | undefined>
async postJson<T, R>(path: string, params: T, noAuth?: boolean): Promise<R>
async postJsonVoid<T>(path: string, params: T, noAuth?: boolean): Promise<void>
async softDeleteCertificate(partial: Partial<DojoCertificateApi>): Promise<number>
async softDeleteOutputTag(partial: Partial<DojoOutputTagApi>): Promise<number>
async softDeleteTxLabel(partial: Partial<DojoTxLabelApi>): Promise<number>
async softDeleteOutputBasket(partial: Partial<DojoOutputBasketApi>): Promise<number>
async labelTransaction(txid: string | number | Partial<DojoTransactionApi>, label: string): Promise<void>
async unlabelTransaction(txid: string | number | Partial<DojoTransactionApi>, label: string): Promise<void>
async tagOutput(partial: Partial<DojoOutputApi>, tag: string): Promise<void>
async untagOutput(partial: Partial<DojoOutputApi>, tag: string): Promise<void>
async unbasketOutput(partial: Partial<DojoOutputApi>): Promise<void>
async getHeight(): Promise<number>
async getMerkleRootForHeight(height: number): Promise<string | undefined>
}
Class DojoExpressClient Details
The authrite options setting may be left undefined if it will be created by NinjaBase.
constructor(public chain: Chain, public serviceUrl: string, options?: DojoExpressClientOptions)
Only vaild if this dojo was created as a syncDojo by setSyncDojosByConfig
syncDojoConfig?: SyncDojoConfigBaseApi
Links: API, Interfaces, Classes, Functions, Types, Variables
export class NinjaBase implements NinjaApi {
chain?: Chain;
userId?: number;
_keyPair: KeyPairApi | undefined;
_isDojoAuthenticated: boolean;
constructor(public dojo: DojoClientApi, clientPrivateKey?: string, public authrite?: AuthriteClient)
getClientChangeKeyPair(): KeyPairApi
async authenticate(identityKey?: string, addIfNew?: boolean): Promise<void>
async verifyDojoAuthenticated()
async sync(): Promise<void>
async setSyncDojosByConfig(syncDojoConfigs: SyncDojoConfigBaseApi[], options?: DojoSyncOptionsApi | undefined): Promise<void>
async getSyncDojosByConfig(): Promise<{
dojos: SyncDojoConfigBaseApi[];
options?: DojoSyncOptionsApi | undefined;
}>
async getPaymail(): Promise<string>
async setPaymail(paymail: string): Promise<void>
async getChain(): Promise<Chain>
async getNetwork(format?: "default" | "nonet"): Promise<string>
async findCertificates(certifiers?: string[] | object, types?: Record<string, string[]>): Promise<{
status: "success";
certificates: DojoCertificateApi[];
}>
async saveCertificate(certificate: DojoCertificateApi | object): Promise<void>
async getTotalValue(basket?: string): Promise<{
total: number;
}>
async getTotalOfAmounts(options: DojoGetTotalOfAmountsOptions): Promise<{
total: number;
}>
async getNetOfAmounts(options?: DojoGetTotalOfAmountsOptions | undefined): Promise<number>
async getAvatar(): Promise<DojoAvatarApi>
async setAvatar(name: string, photoURL: string): Promise<void>
async updateTransactionStatus(params: {
reference: string;
status: DojoTransactionStatusApi;
}): Promise<void>
async updateOutpointStatus(params: {
txid: string;
vout: number;
spendable: boolean;
}): Promise<void>
async getTransactions(options?: DojoGetTransactionsOptions): Promise<NinjaGetTransactionsResultApi>
async getPendingTransactions(referenceNumber?: string): Promise<DojoPendingTxApi[]>
async processPendingTransactions(onTransactionProcessed?: NinjaTransactionProcessedHandler, onTransactionFailed?: NinjaTransactionFailedHandler): Promise<void>
async getTransactionOutputs(options?: DojoGetTransactionOutputsOptions): Promise<NinjaGetTransactionOutputsResultApi[]>
async getTransactionLabels(options?: DojoGetTransactionLabelsOptions): Promise<{
labels: DojoTxLabelApi[];
total: number;
}>
async processTransaction(params: DojoProcessTransactionParams): Promise<DojoProcessTransactionResultApi>
async getTransactionWithOutputs(params: NinjaGetTransactionWithOutputsParams): Promise<NinjaTransactionWithOutputsResultApi>
async createTransactionWithOutputs(params: NinjaGetTransactionWithOutputsParams): Promise<NinjaTransactionWithOutputsResultApi>
async processTransactionWithOutputs(params: NinjaGetTransactionWithOutputsParams): Promise<NinjaTransactionWithOutputsResultApi>
async signAction(params: NinjaSignActionParams): Promise<NinjaSignActionResultApi>
async abortAction(params: NinjaAbortActionParams): Promise<NinjaAbortActionResultApi>
async createTransaction(params: NinjaCreateTransactionParams): Promise<DojoCreateTransactionResultApi>
async deleteCertificate(partial: Partial<DojoCertificateApi>): Promise<number>
async labelTransaction(txid: string | number | Partial<DojoTransactionApi>, label: string): Promise<void>
async unlabelTransaction(txid: string | number | Partial<DojoTransactionApi>, label: string): Promise<void>
async tagOutput(output: {
txid: string;
vout: number;
}, tag: string): Promise<void>
async untagOutput(output: {
txid: string;
vout: number;
}, tag: string): Promise<void>
async unbasketOutput(output: {
txid: string;
vout: number;
}): Promise<void>
async submitDirectTransaction(params: NinjaSubmitDirectTransactionParams): Promise<NinjaSubmitDirectTransactionResultApi>
async getEnvelopesOfConflictingTransactions(txid: string): Promise<EnvelopeApi[]>
async getHeight(): Promise<number>
async getMerkleRootForHeight(height: number): Promise<string | undefined>
}
Links: API, Interfaces, Classes, Functions, Types, Variables
export class DojoTxBuilder extends DojoTxBuilderBase {
constructor(dojo: DojoClientApi, public options?: DojoTxBuilderOptions)
}
Links: API, Interfaces, Classes, Functions, Types, Variables
"Drop-in-replacement" for the original (v1) Ninja
export class Ninja extends NinjaBase {
constructor(dojo: NinjaV1Params | DojoClientApi, clientPrivateKey?: string, authrite?: AuthriteClient)
}
Links: API, Interfaces, Classes, Functions, Types, Variables
A ninja that also creates a default DojoClientExpress syncDojo configured to sync an existing user's state from a dojoURL parameter (either https://staging-dojo.babbage.systems or https://dojo.babbage.systems by default)
export class NinjaV2 extends NinjaBase {
constructor(dojo: DojoClientApi, clientPrivateKey: string, chain: Chain)
}
Links: API, Interfaces, Classes, Functions, Types, Variables
Links: API, Interfaces, Classes, Functions, Types, Variables
Combine inputs per protocol 3241645161d8 to generate an 'invoice' string used for cryptographic key generation.
export function invoice3241645161d8(prefix: string, suffix: string, paymail?: string): string
Function invoice3241645161d8 Details
Argument Details
- prefix
- Typically a random string unique to a single transaction.
- suffix
- Typically a random string unique to a single output in that transaction.
- paymail
- An optional paymail handle
Links: API, Interfaces, Classes, Functions, Types, Variables
Verifies protocol '3241645161d8' output scripts with derivedSuffix based addresses. Computes transaction 'amount'.
export async function processIncomingTransaction(ninja: NinjaBase, incomingTransaction: ProcessIncomingTransactionApi, protocol?: string, updateStatus?: boolean): Promise<ProcessIncomingTransactionResultApi>
Function processIncomingTransaction Details
Returns
Void on error if onTransactionFailed handler is provided.
Links: API, Interfaces, Classes, Functions, Types, Variables
export async function processPendingTransactions(ninja: NinjaBase, onTransactionProcessed?: NinjaTransactionProcessedHandler, onTransactionFailed?: NinjaTransactionFailedHandler, onOutgoingTransaction?: NinjaOutgoingTransactionHandler): Promise<void>
Links: API, Interfaces, Classes, Functions, Types, Variables
Constructs a
export async function buildBsvTxFromCreateTransactionResult(ninjaInputs: Record<string, NinjaTxInputsApi>, createResult: DojoCreateTransactionResultApi, changeKeys: KeyPairApi): Promise<{
tx: Transaction;
outputMap: Record<string, number>;
amount: number;
log?: string;
}>
Function buildBsvTxFromCreateTransactionResult Details
Argument Details
- ninjaInputs
- Ninja inputs as passed to createAction
- createResult
- Create transaction results returned by createAction when signActionRequires is true.
- changeKeys
- Dummy keys can be used to create a transaction with which to generate Ninja input lockingScripts.
Links: API, Interfaces, Classes, Functions, Types, Variables
export async function signCreatedTransaction(ninja: NinjaBase, params: NinjaSignCreatedTransactionParams): Promise<NinjaTransactionWithOutputsResultApi>
Links: API, Interfaces, Classes, Functions, Types, Variables
export function unpackFromCreateTransactionResult(ninjaInputs: Record<string, NinjaTxInputsApi>, createResult: DojoCreateTransactionResultApi): {
amount: number;
referenceNumber: string;
inputs: Record<string, EnvelopeEvidenceApi>;
}
Links: API, Interfaces, Classes, Functions, Types, Variables
export async function createTransactionWithOutputs(ninja: NinjaBase, params: NinjaGetTransactionWithOutputsParams): Promise<NinjaTransactionWithOutputsResultApi>
Links: API, Interfaces, Classes, Functions, Types, Variables
export function getUnlockingScriptLength(script: string | number): number
Links: API, Interfaces, Classes, Functions, Types, Variables
export function needsSignAction(inputs: Record<string, NinjaTxInputsApi>)
Function needsSignAction Details
Returns
true if at least one unlockingScript is specified only as a maximum length number.
Links: API, Interfaces, Classes, Functions, Types, Variables
Convert NinjaTxInputsApi to DojoTxInputsApi to protect unlocking scripts.
export function convertToDojoTxInputsApi(inputs: Record<string, NinjaTxInputsApi>): Record<string, DojoTxInputsApi>
Links: API, Interfaces, Classes, Functions, Types, Variables
export async function processTransactionWithOutputs(ninja: NinjaBase, params: NinjaGetTransactionWithOutputsParams): Promise<NinjaTransactionWithOutputsResultApi>
Links: API, Interfaces, Classes, Functions, Types, Variables
export async function getTransactionWithOutputs(ninja: NinjaBase, params: NinjaGetTransactionWithOutputsParams): Promise<NinjaTransactionWithOutputsResultApi>
Links: API, Interfaces, Classes, Functions, Types, Variables
export async function submitDirectTransaction(ninja: NinjaBase, params: NinjaSubmitDirectTransactionParams): Promise<NinjaSubmitDirectTransactionResultApi>
Links: API, Interfaces, Classes, Functions, Types, Variables
export async function signAction(ninja: NinjaBase, params: NinjaSignActionParams): Promise<NinjaSignActionResultApi>
Links: API, Interfaces, Classes, Functions, Types, Variables
export async function abortAction(ninja: NinjaBase, params: NinjaAbortActionParams): Promise<NinjaAbortActionResultApi>
Links: API, Interfaces, Classes, Functions, Types, Variables
export async function makeUnlockTestRawTxBabbageBsv(params: {
sourceTXID: string;
sourceOutputIndex: number;
lockingScript: string;
satoshis: number;
derivationPrefix: string;
derivationSuffix: string;
privateKey: string;
publicKey: string;
}): Promise<string>
Links: API, Interfaces, Classes, Functions, Types, Variables
NinjaOutgoingTransactionHandler |
NinjaTransactionFailedHandler |
NinjaTransactionProcessedHandler |
Links: API, Interfaces, Classes, Functions, Types, Variables
export type NinjaTransactionFailedHandler = (args: NinjaTransactionFailedApi) => Promise<void>
Links: API, Interfaces, Classes, Functions, Types, Variables
export type NinjaTransactionProcessedHandler = (args: NinjaTransactionProcessedApi) => Promise<void>
Links: API, Interfaces, Classes, Functions, Types, Variables
export type NinjaOutgoingTransactionHandler = (tx: DojoPendingTxApi) => Promise<boolean>
Links: API, Interfaces, Classes, Functions, Types, Variables
invoice3241645161d8Protocol = "2-3241645161d8"
Links: API, Interfaces, Classes, Functions, Types, Variables
The license for the code in this repository is the Open BSV License.