Skip to content

Commit

Permalink
feat: add signrawtransaction
Browse files Browse the repository at this point in the history
  • Loading branch information
gridcat committed Jun 29, 2021
1 parent 33e3741 commit d532d40
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/RPC/Wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { Reserve } from '../contracts/reserve';
import { Script } from '../contracts/script';
import { StakeListing } from '../contracts/stake';
import { DetailedRawTransaction, Transaction } from '../contracts/transaction';
import { SigHashType, TransactionDependencies, TransactionSigned } from '../contracts/transactionRaw';
import { TransactionShort } from '../contracts/transactionShort';
import { TransactionUnspent } from '../contracts/transactionUnspent';
import { UnspentReport, UTXO } from '../contracts/utxo';
Expand Down Expand Up @@ -779,4 +780,30 @@ export class Wallet extends RPCBase {
public async signMessage(address: Address, message: string): Promise<string> {
return this.call('signmessage', address, message);
}

/**
* Sign inputs for raw transaction (serialized, hex-encoded).
*
*
* @param {string} rawTransaction - raw transaction (serialized, hex-encoded)
* @param {TransactionDependencies[]|null} transactionDependencies - is an array of previous transaction outputs that this transaction depends on but may not yet be in the blockchain.
* @param {string[]|null} privateKeys - is an array of base58-encoded private keys that, if given, will be the only keys used to sign the transaction
* @param {SigHashType} sigHashType - is a string that is one of six values; ALL, NONE, SINGLE or ALL|ANYONECANPAY, NONE|ANYONECANPAY, SINGLE|ANYONECANPAY.
* @returns {Promise<TransactionSigned>}
* @memberof Wallet
*/
public async signRawTransaction(
rawTransaction: string,
transactionDependencies: TransactionDependencies[] | null,
privateKeys: string[] | null,
sigHashType: SigHashType,
): Promise<TransactionSigned> {
return this.call<TransactionSigned>(
'signrawtransaction',
rawTransaction,
transactionDependencies as any,
privateKeys,
sigHashType,
);
}
}
32 changes: 32 additions & 0 deletions src/contracts/transactionRaw.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { TX } from '../types';

export type SigHashType =
'ALL'
| 'NONE'
| 'SINGLE'
| 'ALL|ANYONECANPAY'
| 'NONE|ANYONECANPAY'
| 'SINGLE|ANYONECANPAY'

export interface TransactionDependencies {
txid: TX;
vout: number;
scriptPubKey: string;
}

export interface TransactionSigned {
/**
* raw transaction with signature(s) (hex-encoded string)
*
* @type {string}
* @memberof TransactionSigned
*/
hex: string;
/**
* 1 if transaction has a complete set of signature (0 if not)
*
* @type {(0 | 1)}
* @memberof TransactionSigned
*/
complete: 0 | 1;
}

0 comments on commit d532d40

Please sign in to comment.