ninja-base
v0.3.83
Published
Base level functions, classes, interfaces for Ninja
Downloads
1,484
Readme
ninja-base
Base level functions, classes, interfaces for Ninja
API
Links: API, Interfaces, Classes, Functions, Types, Variables
Interfaces
| | | | | --- | --- | --- | | CwiCoreApi | NinjaGetTransactionOutputsResultApi | NinjaTransactionFailedApi | | DojoExpressClientOptions | NinjaGetTransactionWithOutputsParams | NinjaTransactionProcessedApi | | KeyPairApi | NinjaGetTransactionsResultApi | NinjaTransactionWithOutputsResultApi | | NinjaAbortActionParams | NinjaGetTransactionsTxApi | NinjaTxInputsApi | | NinjaAbortActionResultApi | NinjaGetTransactionsTxInputApi | NinjaV1Params | | NinjaApi | NinjaGetTransactionsTxOutputApi | PendingDojoInput | | NinjaCompleteCreateTransactionWithOutputsParams | NinjaOutputToRedeemApi | PendingSignAction | | NinjaCreateActionConfirmResult | NinjaSignActionParams | ProcessIncomingTransactionApi | | NinjaCreateActionParams | NinjaSignActionResultApi | ProcessIncomingTransactionInputApi | | NinjaCreateActionResult | NinjaSignCreatedTransactionParams | ProcessIncomingTransactionOutputApi | | NinjaCreateTransactionParams | NinjaSubmitDirectTransactionApi | ProcessIncomingTransactionResultApi | | NinjaGetPendingTransactionsInputApi | NinjaSubmitDirectTransactionOutputApi | SignActionParams | | NinjaGetPendingTransactionsInstructionsApi | NinjaSubmitDirectTransactionParams | TxOutputApi | | NinjaGetPendingTransactionsTxApi | NinjaSubmitDirectTransactionResultApi | TxRedeemableOutputApi |
Links: API, Interfaces, Classes, Functions, Types, Variables
Interface: CwiCoreApi
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
Interface: DojoExpressClientOptions
export interface DojoExpressClientOptions {
authrite?: AuthriteClient;
identityKey?: string;
}
Links: API, Interfaces, Classes, Functions, Types, Variables
Interface: KeyPairApi
export interface KeyPairApi {
privateKey: string;
publicKey: string;
}
Links: API, Interfaces, Classes, Functions, Types, Variables
Interface: NinjaAbortActionParams
export interface NinjaAbortActionParams {
referenceNumber: string;
log: string | undefined;
}
Property log
Optional operational and performance logging prior data.
log: string | undefined
Property referenceNumber
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
Interface: NinjaAbortActionResultApi
export interface NinjaAbortActionResultApi {
referenceNumber: string;
log: string | undefined;
}
Property log
operational and performance logging if enabled.
log: string | undefined
Property referenceNumber
The unique transaction identifier that was processed.
referenceNumber: string
Links: API, Interfaces, Classes, Functions, Types, Variables
Interface: NinjaApi
A client for creating, signing, and delivering Bitcoin transactions
export interface NinjaApi {
dojo: DojoClientApi;
authenticate(identityKey?: string, addIfNew?: boolean): Promise<void>;
isAuthenticated(): boolean;
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;
}>;
getEnvelopeForTransaction(txid: string): Promise<EnvelopeApi | undefined>;
getPendingTransactions(referenceNumber?: string): Promise<DojoPendingTxApi[]>;
updateTransactionStatus(params: {
reference: string;
status: DojoTransactionStatusApi;
}): Promise<void>;
updateOutpointStatus(params: {
txid: string;
vout: number;
spendable: boolean;
}): Promise<void>;
createAction(params: NinjaCreateActionParams): Promise<NinjaCreateActionResult>;
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>;
getHeaderForHeight(height: number): Promise<number[] | undefined>;
getInfo(params: GetInfoParams): Promise<GetInfoResult>;
listActions(vargs: sdk.ValidListActionsArgs, originator?: sdk.OriginatorDomainNameStringUnder250Bytes): Promise<sdk.ListActionsResult>;
listOutputs(vargs: sdk.ValidListOutputsArgs, originator?: sdk.OriginatorDomainNameStringUnder250Bytes): Promise<sdk.ListOutputsResult>;
createActionSdk(vargs: sdk.ValidCreateActionArgs, originator?: sdk.OriginatorDomainNameStringUnder250Bytes): Promise<sdk.CreateActionResult>;
signActionSdk(vargs: sdk.ValidSignActionArgs, originator?: sdk.OriginatorDomainNameStringUnder250Bytes): Promise<sdk.SignActionResult>;
abortActionSdk(vargs: sdk.ValidAbortActionArgs, originator?: sdk.OriginatorDomainNameStringUnder250Bytes): Promise<sdk.AbortActionResult>;
internalizeActionSdk(vargs: sdk.ValidInternalizeActionArgs, originator?: sdk.OriginatorDomainNameStringUnder250Bytes): Promise<sdk.InternalizeActionResult>;
relinquishOutputSdk(vargs: sdk.ValidRelinquishOutputArgs, originator?: sdk.OriginatorDomainNameStringUnder250Bytes): Promise<sdk.RelinquishOutputResult>;
acquireCertificateSdk(vargs: sdk.AcquireCertificateArgs, originator?: sdk.OriginatorDomainNameStringUnder250Bytes): Promise<sdk.AcquireCertificateResult>;
listCertificatesSdk(vargs: sdk.ValidListCertificatesArgs, originator?: sdk.OriginatorDomainNameStringUnder250Bytes): Promise<sdk.ListCertificatesResult>;
}
See also: KeyPairApi, NinjaAbortActionParams, NinjaAbortActionResultApi, NinjaCreateActionParams, NinjaCreateActionResult, NinjaCreateTransactionParams, NinjaGetTransactionOutputsResultApi, NinjaGetTransactionWithOutputsParams, NinjaGetTransactionsResultApi, NinjaSignActionParams, NinjaSignActionResultApi, NinjaSubmitDirectTransactionParams, NinjaSubmitDirectTransactionResultApi, NinjaTransactionFailedHandler, NinjaTransactionProcessedHandler, NinjaTransactionWithOutputsResultApi, abortAction, createActionSdk, createTransactionWithOutputs, getTransactionWithOutputs, internalizeActionSdk, processPendingTransactions, processTransactionWithOutputs, relinquishOutputSdk, signAction, signActionSdk, submitDirectTransaction
Property dojo
The dojo user wallet database supporting this api.
isAuthenticated must be true.
dojo: DojoClientApi
Method abortAction
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>
See also: NinjaAbortActionParams, NinjaAbortActionResultApi
Method authenticate
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.
Method createAction
Create and process a new transaction with automatic funding.
Specific required inputs and new outputs can be specified.
An optional confirmation processing step can be provided prior to signing and processing the new transaction. This is typically used to confirm total spending.
createAction(params: NinjaCreateActionParams): Promise<NinjaCreateActionResult>
See also: NinjaCreateActionParams, NinjaCreateActionResult
Method createTransaction
Creates a new transaction that must be processed with processTransaction
after you sign it
createTransaction(params: NinjaCreateTransactionParams): Promise<DojoCreateTransactionResultApi>
See also: NinjaCreateTransactionParams
Returns
The template you need to sign and process
Method createTransactionWithOutputs
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>
See also: NinjaGetTransactionWithOutputsParams, NinjaTransactionWithOutputsResultApi
Method deleteCertificate
Soft deletes a certificate.
deleteCertificate(partial: Partial<DojoCertificateApi>): Promise<number>
Argument Details
- partial
- The partial certificate data identifying the certificate to soft delete.
Method findCertificates
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
Method getAvatar
Returns the name and photo URL of the user
getAvatar(): Promise<DojoAvatarApi>
Returns
The avatar of the user
Method getChain
Returns which BSV network we are using (main or test)
getChain(): Promise<Chain>
Method getClientChangeKeyPair
Return the private / public keypair used by the Ninja client for change UTXOs
getClientChangeKeyPair(): KeyPairApi
See also: KeyPairApi
Method getEnvelopeForTransaction
Returns an Everett Style envelope for the given txid.
A transaction envelope is a tree of inputs where all the leaves are proven transactions. The trivial case is a single leaf: the envelope for a proven transaction is the rawTx and its proof.
Each branching level of the tree corresponds to an unmined transaction without a proof, in which case the envelope is:
- rawTx
- mapiResponses from transaction processors (optional)
- inputs object where keys are this transaction's input txids and values are recursive envelope for those txids.
getEnvelopeForTransaction(txid: string): Promise<EnvelopeApi | undefined>
Argument Details
- txid
- double hash of raw transaction as hex string
Method getEnvelopesOfConflictingTransactions
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
Method getHeaderForHeight
getHeaderForHeight(height: number): Promise<number[] | undefined>
Returns
serialized block header for the given height or undefined, if height is invalid or unknown.
Method getHeight
Returns the current chain height of the network
getHeight(): Promise<number>
Returns
The current chain height
Method getInfo
getInfo(params: GetInfoParams): Promise<GetInfoResult>
Returns
information about the metanet-client context (version, chain, height, user...).
Method getMerkleRootForHeight
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.
Method getNetOfAmounts
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>
Method getNetwork
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.
Method getPaymail
Returns the current Paymail handle
getPaymail(): Promise<string>
Method getPendingTransactions
Returns a set of all transactions that need to be signed and submitted, or canceled
getPendingTransactions(referenceNumber?: string): Promise<DojoPendingTxApi[]>
Method getSyncDojosByConfig
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;
}>
Method getTotalOfAmounts
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;
}>
Method getTotalValue
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
Method getTransactionLabels
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'
Method getTransactionOutputs
Returns a set of transaction outputs that Dojo has tracked
getTransactionOutputs(options?: DojoGetTransactionOutputsOptions): Promise<NinjaGetTransactionOutputsResultApi[]>
See also: NinjaGetTransactionOutputsResultApi
Method getTransactionWithOutputs
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>
See also: NinjaGetTransactionWithOutputsParams, NinjaTransactionWithOutputsResultApi
Method getTransactions
Returns a set of transactions that match the criteria
getTransactions(options?: DojoGetTransactionsOptions): Promise<NinjaGetTransactionsResultApi>
See also: NinjaGetTransactionsResultApi
Argument Details
- options
- limit defaults to 25, offset defaults to 0, addLabels defaults to true, order defaults to 'descending'
Method isAuthenticated
isAuthenticated(): boolean
Returns
false until a call to authenticate
succeeds
Method labelTransaction
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
Method processPendingTransactions
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>
See also: NinjaTransactionFailedHandler, NinjaTransactionProcessedHandler
Method processTransaction
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'
Method processTransactionWithOutputs
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>
See also: NinjaGetTransactionWithOutputsParams, NinjaTransactionWithOutputsResultApi
Method saveCertificate
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
Method setAvatar
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
Method setPaymail
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>
Method setSyncDojosByConfig
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.
Method signAction
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>
See also: NinjaSignActionParams, NinjaSignActionResultApi
Method submitDirectTransaction
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>
See also: NinjaSubmitDirectTransactionParams, NinjaSubmitDirectTransactionResultApi
Method sync
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>
Method tagOutput
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
Method unbasketOutput
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>
Method unlabelTransaction
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
Method untagOutput
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
Method updateOutpointStatus
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
Method updateTransactionStatus
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
Interface: NinjaCompleteCreateTransactionWithOutputsParams
export interface NinjaCompleteCreateTransactionWithOutputsParams {
inputs?: Record<string, NinjaTxInputsApi>;
note?: string;
createResult: DojoCreateTransactionResultApi;
}
See also: NinjaTxInputsApi
Property inputs
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>
See also: NinjaTxInputsApi
Links: API, Interfaces, Classes, Functions, Types, Variables
Interface: NinjaCreateActionConfirmResult
export interface NinjaCreateActionConfirmResult {
proceedToSign: boolean;
}
Links: API, Interfaces, Classes, Functions, Types, Variables
Interface: NinjaCreateActionParams
export interface NinjaCreateActionParams {
params: CreateActionParams;
confirmCreateTransactionResult?: (result: NinjaTransactionWithOutputsResultApi) => Promise<NinjaCreateActionConfirmResult>;
}
See also: NinjaCreateActionConfirmResult, NinjaTransactionWithOutputsResultApi
Links: API, Interfaces, Classes, Functions, Types, Variables
Interface: NinjaCreateActionResult
export interface NinjaCreateActionResult {
proceedToSign: boolean;
result?: CreateActionResult;
}
Links: API, Interfaces, Classes, Functions, Types, Variables
Interface: NinjaCreateTransactionParams
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;
}
Property fee
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
Property inputSelection
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
Property inputs
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>
Property labels
The labels to affix to this transaction
labels: string[]
Property note
A numan-readable note describing the transaction
note?: string
Property outputGeneration
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
Property outputs
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[]
Property recipient
The Paymail handle for the recipient of the transaction
recipient?: string
Links: API, Interfaces, Classes, Functions, Types, Variables
Interface: NinjaGetPendingTransactionsInputApi
export interface NinjaGetPendingTransactionsInputApi extends EnvelopeEvidenceApi {
outputsToRedeem: number[];
instructions: Record<number, NinjaGetPendingTransactionsInstructionsApi>;
}
See also: NinjaGetPendingTransactionsInstructionsApi
Links: API, Interfaces, Classes, Functions, Types, Variables
Interface: NinjaGetPendingTransactionsInstructionsApi
export interface NinjaGetPendingTransactionsInstructionsApi {
type: string;
derivationPrefix: string | null;
derivationSuffix: string | null;
paymailHandle: string | null;
senderIdentityKey: string | null;
customInstructions: string | null;
}
Property customInstructions
max length of 2500
customInstructions: string | null
Property derivationPrefix
max length of 32 base64 encoded
derivationPrefix: string | null
Property derivationSuffix
max length of 32 base64 encoded
derivationSuffix: string | null
Property paymailHandle
max length of 64
paymailHandle: string | null
Property senderIdentityKey
max length of 130 hex encoded
senderIdentityKey: string | null
Property type
max length of 50 e.g. P2PKH, custom
type: string
Links: API, Interfaces, Classes, Functions, Types, Variables
Interface: NinjaGetPendingTransactionsTxApi
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>;
}
See also: NinjaGetPendingTransactionsInputApi
Property amount
The number of satoshis added or removed from Dojo by this transaction
amount: number
Property created_at
The time the transaction was registered with the Dojo
created_at: string
Property inputs
parsed truncatedExternalInputs
inputs?: Record<string, NinjaGetPendingTransactionsInputApi>
See also: NinjaGetPendingTransactionsInputApi
Property provenTxId
Is valid when transaction proof record exists in DojoProvenTxApi table.
provenTxId?: number | null
Property referenceNumber
The Dojo reference number for the transaction
referenceNumber: string
Property senderPaymail
The Paymail handle of the person who sent the transaction
senderPaymail: string | undefined | null
Property status
max length of 64 e.g. unprocessed, unsigned
status: DojoTransactionStatusApi
Links: API, Interfaces, Classes, Functions, Types, Variables
Interface: NinjaGetTransactionOutputsResultApi
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[];
}
Property amount
Number of satoshis in the output
amount: number
Property basket
If includeBasket
option is true, name of basket to which this output belongs.
basket?: string
Property customInstructions
When envelope requested, any custom instructions associated with this output.
customInstructions?: string
Property envelope
When requested and available, output validity support envelope.
envelope?: EnvelopeApi
Property outputScript
Hex representation of output locking script
outputScript: string
Property spendable
Whether this output is free to be spent
spendable: boolean
Property tags
If includeTags
option is true, tags assigned to this output.
tags?: string[]
Property txid
Transaction ID of transaction that created the output
txid: string
Property type
The type of output, for example "P2PKH" or "P2RPH"
type: string
Property vout
Index in the transaction of the output
vout: number
Links: API, Interfaces, Classes, Functions, Types, Variables
Interface: NinjaGetTransactionWithOutputsParams
Input parameters to getTransactionWithOutputs method.
export interface NinjaGetTransactionWithOutputsParams {
outputs?: DojoCreateTxOutputApi[];
labels?: string[];
inputs?: Record<string, NinjaTxInputsApi>;
beef?: Beef | number[];
note?: string;
lockTime?: number;
version?: number;
recipient?: string;
autoProcess?: boolean;
feePerKb?: number;
feeModel?: DojoFeeModelApi;
options?: CreateActionOptions;
acceptDelayedBroadcast?: boolean;
log?: string;
}
See also: NinjaTxInputsApi
Property acceptDelayedBroadcast
DEPRECATED: Use options.acceptDelayedBroadcast
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
Property autoProcess
Whether the transaction should be processed automatically
with processTransaction. Note that this will return mapiResponses
and note
instead of referenceNumber
default true
autoProcess?: boolean
Property beef
Optional. Alternate source of validity proof data for inputs
.
If number[]
it must be serialized Beef
.
beef?: Beef | number[]
Property feeModel
Optional. The fee model used by this transaction.
If both feeModel and feePerKb are specified, feeModel takes precendence
feeModel?: DojoFeeModelApi
Property feePerKb
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
Property inputs
Input scripts to spend as part of this transaction.
This is an object whose keys are TXIDs and whose values are, optionally, Everett-style transaction envelopes.
The values must contain a 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.
If hex scriptcode is provided, 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>
See also: NinjaTxInputsApi
Property labels
A set of label strings to affix to the transaction
labels?: string[]
Property lockTime
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
Property log
Optional transaction processing log
log?: string
Property note
A note about the transaction
note?: string
Property options
Processing options.
options?: CreateActionOptions
Property outputs
A set of outputs to include, each with script
and satoshis
.
outputs?: DojoCreateTxOutputApi[]
Property recipient
Paymail recipient for transaction
recipient?: string
Property version
Optional. Transaction version number, default is current standard transaction version value.
version?: number
Links: API, Interfaces, Classes, Functions, Types, Variables
Interface: NinjaGetTransactionsResultApi
export interface NinjaGetTransactionsResultApi {
totalTransactions: number;
transactions: NinjaGetTransactionsTxApi[];
}
See also: NinjaGetTransactionsTxApi
Property totalTransactions
The number of transactions in the complete set
totalTransactions: number
Property transactions
The specific transactions from the set that were requested, based on limit
and offset
transactions: NinjaGetTransactionsTxApi[]
See also: NinjaGetTransactionsTxApi
Links: API, Interfaces, Classes, Functions, Types, Variables
Interface: NinjaGetTransactionsTxApi
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[];
}
See also: NinjaGetTransactionsTxInputApi, NinjaGetTransactionsTxOutputApi
Property amount
The number of satoshis added or removed from Dojo by this transaction
amount: number
Property created_at
The time the transaction was registered with the Dojo
created_at: string
Property isOutgoing
Whether or not the transaction was created with createTransaction
isOutgoing: boolean
Property labels
A set of all the labels affixed to the transaction
labels: string[]
Property note
The human-readable tag for the transaction, provided by the person who initiated it
note: string
Property recipientPaymail
The Paymail handle of the person who received the transaction
recipientPaymail: string
Property referenceNumber
The Dojo reference number for the transaction
referenceNumber: string
Property senderPaymail
The Paymail handle of the person who sent the transaction
senderPaymail: string
Property status
The current state of the transaction. Common statuses are completed
and unproven
.
status: TransactionStatusApi
Property txid
The transaction ID
txid: string
Links: API, Interfaces, Classes, Functions, Types, Variables
Interface: NinjaGetTransactionsTxInputApi
export interface NinjaGetTransactionsTxInputApi extends ListActionsTransactionInput {
txid: string;
vout: number;
amount: number;
outputScript: string;
type: string;
spendable: boolean;
spendingDescription?: string;
basket?: string;
tags?: string[];
}
Property amount
Number of satoshis in the output
amount: number
Property basket
Optionally included basket assignment.
basket?: string
Property outputScript
Hex representation of output locking script
outputScript: string
Property spendable
Whether this output is free to be spent
spendable: boolean
Property spendingDescription
Spending description for this transaction input
spendingDescription?: string
Property tags
Optionally included tag assignments.
tags?: string[]
Property txid
Transaction ID of transaction that created the output
txid: string
Property type
The type of output, for example "P2PKH" or "P2RPH"
type: string
Property vout
Index in the transaction of the output
vout: number
Links: API, Interfaces, Classes, Functions, Types, Variables
Interface: NinjaGetTransactionsTxOutputApi
export interface NinjaGetTransactionsTxOutputApi extends ListActionsTransactionOutput {
txid: string;
vout: number;
amount: number;
outputScript: string;
type: string;
spendable: boolean;
description?: string;
basket?: string;
tags?: string[];
}
Property amount
Number of satoshis in the output
amount: number
Property basket
Optionally included basket assignment.
basket?: string
Property description
Output description
description?: string
Property outputScript
Hex representation of output locking script
outputScript: string
Property spendable
Whether this output is free to be spent
spendable: boolean
Property tags
Optionally included tag assignments.
tags?: string[]
Property txid
Transaction ID of transaction that created the output
txid: string
Property type
The type of output, for example "P2PKH" or "P2RPH"
type: string
Property vout
Index in the transaction of the output
vout: number
Links: API, Interfaces, Classes, Functions, Types, Variables
Interface: NinjaOutputToRedeemApi
export interface NinjaOutputToRedeemApi {
index: number;
unlockingScript: string | number;
spendingDescription?: string;
sequenceNumber?: number;
}
Property index
Zero based output index within its transaction to spend.
index: number
Property sequenceNumber
Sequence number to use when spending
sequenceNumber?: number
Property unlockingScript
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
Interface: NinjaSignActionParams
export interface NinjaSignActionParams extends NinjaSignCreatedTransactionParams {
inputs: Record<string, NinjaTxInputsApi>;
createResult: DojoCreateTransactionResultApi;
acceptDelayedBroadcast?: boolean;
}
See also: NinjaSignCreatedTransactionParams, NinjaTxInputsApi
Property acceptDelayedBroadcast
Must match original value passed to createAction
.
acceptDelayedBroadcast?: boolean
Property createResult
The dojo createTransaction results returned from createAction.
createResult: DojoCreateTransactionResultApi
Property inputs
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>
See also: NinjaTxInputsApi
Links: API, Interfaces, Classes, Functions, Types, Variables
Interface: NinjaSignActionResultApi
export interface NinjaSignActionResultApi extends NinjaTransactionWithOutputsResultApi {
rawTx?: string;
txid?: string;
amount: number;
inputs: Record<string, OptionalEnvelopeEvidenceApi>;
note?: string;
referenceNumber: string;
outputMap?: Record<string, number>;
mapiResponses?: MapiResponseApi[];
log?: string;
}
See also: NinjaTransactionWithOutputsResultApi
Property amount
The amount of the transaction
amount: number
Property inputs
This is the fully-formed inputs
field of this transaction, as per the SPV Envelope specification.
inputs: Record<string, OptionalEnvelopeEvidenceApi>
Property log
Optional transaction processing history
log?: string
Property mapiResponses
If processed, array of acceptance responses from mapi transaction processors.
Only valid if signActionRequired !== true
mapiResponses?: MapiResponseApi[]
Property outputMap
Map of change output derivationSuffix values to transaction vout indices
Only valid if signActionRequired !== true
outputMap?: Record<string, number>
Property rawTx
The serialized, signed transaction that is ready for broadcast, or has been broadcast.
Only valid if signActionRequired !== true
rawTx?: string
Property referenceNumber
The reference number that should now be provided back to processTransaction (or
updateTransactionStatus`)
referenceNumber: string
Property txid
rawTx hash as hex string
Only valid if signActionRequired !== true
txid?: string
Links: API, Interfaces, Classes, Functions, Types, Variables
Interface: NinjaSignCreatedTransactionParams
export interface NinjaSignCreatedTransactionParams {
inputs: Record<string, NinjaTxInputsApi>;
createResult: DojoCreateTransactionResultApi;
}
See also: NinjaTxInputsApi
Property inputs
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>
See also: NinjaTxInputsApi
Links: API, Interfaces, Classes, Functions, Types, Variables
Interface: NinjaSubmitDirectTransactionApi
Transaction input parameter to submitDirectTransaction method.
export interface NinjaSubmitDirectTransactionApi extends SubmitDirectTransaction {
rawTx: string;
txid?: string;
inputs?: Record<string, OptionalEnvelopeEvidenceApi>;
mapiResponses?: MapiResponseApi[];
proof?: TscMerkleProofApi;
outputs: NinjaSubmitDirectTransactionOutputApi[];
referenceNumber?: string;
}
See also: NinjaSubmitDirectTransactionOutputApi
Property outputs
sparse array of outputs of interest where indices match vout numbers.
outputs: NinjaSubmitDirectTransactionOutputApi[]
See also: NinjaSubmitDirectTransactionOutputApi
Links: API, Interfaces, Classes, Functions, Types, Variables
Interface: NinjaSubmitDirectTransactionOutputApi
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
Interface: NinjaSubmitDirectTransactionParams
Input parameters to submitDirectTransaction method.
export interface NinjaSubmitDirectTransactionParams {
protocol?: string;
transaction: NinjaSubmitDirectTransactionApi;
senderIdentityKey: string;
note: string;
labels?: string[];
derivationPrefix?: string;
amount?: number;
}
See also: NinjaSubmitDirectTransactionApi
Property derivationPrefix
A derivation prefix used for all outputs. If provided, derivation prefixes on all outputs are optional.
derivationPrefix?: string
Property labels
Labels to assign to transaction.
labels?: string[]
Property note
Human-readable description for the transaction
note: string
Property protocol
Specify the transaction submission payment protocol to use. Currently, the only supported protocol is that with BRFC ID "3241645161d8"
protocol?: string
Property senderIdentityKey
Provide the identity key for the person who sent the transaction
senderIdentityKey: string
Property transaction
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
See also: NinjaSubmitDirectTransactionApi
Links: API, Interfaces, Classes, Functions, Types, Variables
Interface: NinjaSubmitDirectTransactionResultApi
export interface NinjaSubmitDirectTransactionResultApi extends SubmitDirectTransactionResult {
transactionId: number;
referenceNumber: string;
}
Links: API, Interfaces, Classes, Functions, Types, Variables
Interface: NinjaTransactionFailedApi
export interface NinjaTransactionFailedApi {
inputs: Record<string, DojoPendingTxInputApi>;
isOutgoing: boolean;
reference: string;
error: CwiError;
}
Links: API, Interfaces, Classes, Functions, Types, Variables
Interface: NinjaTransactionProcessedApi
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
Interface: NinjaTransactionWithOutputsResultApi
export interface NinjaTransactionWithOutputsResultApi {
signActionRequired?: boolean;
createResult?: DojoCreateTransactionResultApi;
beef?: number[];
noSendChange?: OutPoint[];
rawTx?: string;
txid?: string;
amount: number;
inputs: Record<string, OptionalEnvelopeEvidenceApi>;
note?: string;
referenceNumber: string;
outputMap?: Record<string, number>;
mapiResponses?: MapiResponseApi[];
options: CreateActionOptions;
log?: string;
}
Property amount
The amount of the transaction
amount: number
Property beef
valid if options.resultFormat
is 'beef'
When valid, rawTx and inputs will be undefined and {}
respectively.
may contain