1- import BigNumber from 'bignumber.js' ;
2- import * as request from 'superagent' ;
31import {
42 BaseBroadcastTransactionOptions ,
53 BaseBroadcastTransactionResult ,
@@ -13,32 +11,35 @@ import {
1311 MPCAlgorithm ,
1412 MultisigType ,
1513 multisigTypes ,
16- ParseTransactionOptions ,
1714 ParsedTransaction ,
18- SignTransactionOptions ,
15+ ParseTransactionOptions ,
1916 SignedTransaction ,
17+ SigningError ,
18+ SignTransactionOptions ,
2019 TssVerifyAddressOptions ,
2120 VerifyTransactionOptions ,
2221} from '@bitgo/sdk-core' ;
23- import { BaseCoin as StaticsBaseCoin , coins } from '@bitgo/statics' ;
22+ import { coins , BaseCoin as StaticsBaseCoin } from '@bitgo/statics' ;
23+ import { Principal } from '@dfinity/principal' ;
24+ import axios from 'axios' ;
25+ import BigNumber from 'bignumber.js' ;
26+ import { createHash , Hash } from 'crypto' ;
27+ import * as request from 'superagent' ;
2428import {
29+ ACCOUNT_BALANCE_ENDPOINT ,
30+ CurveType ,
31+ LEDGER_CANISTER_ID ,
2532 Network ,
2633 PayloadsData ,
34+ PUBLIC_NODE_REQUEST_ENDPOINT ,
35+ PublicNodeSubmitResponse ,
2736 RecoveryOptions ,
37+ ROOT_PATH ,
2838 Signatures ,
2939 SigningPayload ,
30- ACCOUNT_BALANCE_ENDPOINT ,
31- ROOT_PATH ,
32- LEDGER_CANISTER_ID ,
33- PublicNodeSubmitResponse ,
34- CurveType ,
35- PUBLIC_NODE_REQUEST_ENDPOINT ,
3640} from './lib/iface' ;
3741import { TransactionBuilderFactory } from './lib/transactionBuilderFactory' ;
3842import utils from './lib/utils' ;
39- import { createHash , Hash } from 'crypto' ;
40- import { Principal } from '@dfinity/principal' ;
41- import axios from 'axios' ;
4243
4344/**
4445 * Class representing the Internet Computer (ICP) coin.
@@ -107,8 +108,25 @@ export class Icp extends BaseCoin {
107108 return utils . isValidAddress ( address ) ;
108109 }
109110
110- signTransaction ( _ : SignTransactionOptions ) : Promise < SignedTransaction > {
111- throw new MethodNotImplementedError ( ) ;
111+ async signTransaction (
112+ params : SignTransactionOptions & { txPrebuild : { txHex : string } ; prv : string }
113+ ) : Promise < SignedTransaction > {
114+ const txHex = params ?. txPrebuild ?. txHex ;
115+ const privateKey = params ?. prv ;
116+ if ( ! txHex ) {
117+ throw new SigningError ( 'missing required txPrebuild parameter: params.txPrebuild.txHex' ) ;
118+ }
119+ if ( ! privateKey ) {
120+ throw new SigningError ( 'missing required prv parameter: params.prv' ) ;
121+ }
122+ const factory = this . getBuilderFactory ( ) ;
123+ const txBuilder = await factory . from ( params . txPrebuild . txHex ) ;
124+ txBuilder . sign ( { key : params . prv } ) ;
125+ txBuilder . combine ( ) ;
126+ const serializedTx = txBuilder . transaction . toBroadcastFormat ( ) ;
127+ return {
128+ txHex : serializedTx ,
129+ } ;
112130 }
113131
114132 isValidPub ( key : string ) : boolean {
0 commit comments