1- import * as _ from 'lodash' ;
21import {
32 BaseCoin ,
43 BitGoBase ,
@@ -7,43 +6,17 @@ import {
76 ParsedTransaction ,
87 ParseTransactionOptions ,
98 SignedTransaction ,
10- SignTransactionOptions as BaseSignTransactionOptions ,
119 VerifyAddressOptions ,
1210 VerifyTransactionOptions ,
1311} from '@bitgo/sdk-core' ;
14- import { BaseCoin as StaticsBaseCoin , CoinFamily } from '@bitgo/statics' ;
15- import { Interface , KeyPair as SubstrateKeyPair , Utils } from './lib' ;
16-
17- const utils = Utils . default ;
18-
19- export const DEFAULT_SCAN_FACTOR = 20 ; // default number of receive addresses to scan for funds
20-
21- export interface SignTransactionOptions extends BaseSignTransactionOptions {
22- txPrebuild : TransactionPrebuild ;
23- prv : string ;
24- }
25-
26- export interface TransactionPrebuild {
27- txHex : string ;
28- transaction : Interface . TxData ;
29- }
30-
31- export interface ExplainTransactionOptions {
32- txPrebuild : TransactionPrebuild ;
33- publicKey : string ;
34- feeInfo : {
35- fee : string ;
36- } ;
37- }
38-
39- export interface VerifiedTransactionParameters {
40- txHex : string ;
41- prv : string ;
42- }
12+ import { CoinFamily , BaseCoin as StaticsBaseCoin } from '@bitgo/statics' ;
13+ import { KeyPair as SubstrateKeyPair } from './lib' ;
14+ import { DEFAULT_SUBSTRATE_PREFIX } from './lib/constants' ;
15+ import { SignTransactionOptions , VerifiedTransactionParameters } from './lib/iface' ;
16+ import utils from './lib/utils' ;
4317
4418export class SubstrateCoin extends BaseCoin {
4519 protected readonly _staticsCoin : Readonly < StaticsBaseCoin > ;
46- readonly MAX_VALIDITY_DURATION = 2400 ;
4720
4821 protected constructor ( bitgo : BitGoBase , staticsCoin ?: Readonly < StaticsBaseCoin > ) {
4922 super ( bitgo ) ;
@@ -55,10 +28,6 @@ export class SubstrateCoin extends BaseCoin {
5528 this . _staticsCoin = staticsCoin ;
5629 }
5730
58- static createInstance ( bitgo : BitGoBase , staticsCoin ?: Readonly < StaticsBaseCoin > ) : BaseCoin {
59- return new SubstrateCoin ( bitgo , staticsCoin ) ;
60- }
61-
6231 /**
6332 * Creates an instance of TransactionBuilderFactory for the coin specific sdk
6433 */
@@ -98,7 +67,7 @@ export class SubstrateCoin extends BaseCoin {
9867
9968 /** @inheritDoc **/
10069 generateKeyPair ( seed ?: Buffer ) : KeyPair {
101- const keyPair = seed ? utils . keyPairFromSeed ( new Uint8Array ( seed ) ) : new SubstrateKeyPair ( ) ;
70+ const keyPair = seed ? new SubstrateKeyPair ( { seed } ) : new SubstrateKeyPair ( ) ;
10271 const keys = keyPair . getKeys ( ) ;
10372 if ( ! keys . prv ) {
10473 throw new Error ( 'Missing prv in key generation.' ) ;
@@ -120,8 +89,8 @@ export class SubstrateCoin extends BaseCoin {
12089 }
12190
12291 /** @inheritDoc **/
123- parseTransaction ( params : ParseTransactionOptions ) : Promise < ParsedTransaction > {
124- throw new Error ( 'Method not implemented' ) ;
92+ async parseTransaction ( params : ParseTransactionOptions ) : Promise < ParsedTransaction > {
93+ return { } ;
12594 }
12695
12796 /** @inheritDoc **/
@@ -141,28 +110,15 @@ export class SubstrateCoin extends BaseCoin {
141110 }
142111
143112 verifySignTransactionParams ( params : SignTransactionOptions ) : VerifiedTransactionParameters {
144- const prv = params . prv ;
145-
146- const txHex = params . txPrebuild . txHex ;
113+ const prv = params ?. prv ;
114+ const txHex = params ?. txPrebuild ?. txHex ;
147115
148- if ( ! txHex ) {
149- throw new Error ( 'missing txPrebuild parameter' ) ;
116+ if ( typeof txHex !== 'string' ) {
117+ throw new Error ( `txHex must be string, got type ${ typeof txHex } ` ) ;
150118 }
151119
152- if ( ! _ . isString ( txHex ) ) {
153- throw new Error ( `txPrebuild must be an object, got type ${ typeof txHex } ` ) ;
154- }
155-
156- if ( ! prv ) {
157- throw new Error ( 'missing prv parameter to sign transaction' ) ;
158- }
159-
160- if ( ! _ . isString ( prv ) ) {
161- throw new Error ( `prv must be a string, got type ${ typeof prv } ` ) ;
162- }
163-
164- if ( ! _ . has ( params , 'pubs' ) ) {
165- throw new Error ( 'missing public key parameter to sign transaction' ) ;
120+ if ( typeof prv !== 'string' ) {
121+ throw new Error ( `prv must be string, got type ${ typeof prv } ` ) ;
166122 }
167123
168124 return { txHex, prv } ;
@@ -177,7 +133,7 @@ export class SubstrateCoin extends BaseCoin {
177133 const { referenceBlock, blockNumber, transactionVersion, sender } = params . txPrebuild . transaction ;
178134
179135 txBuilder
180- . validity ( { firstValid : blockNumber , maxDuration : this . MAX_VALIDITY_DURATION } )
136+ . validity ( { firstValid : blockNumber , maxDuration : this . getMaxValidityDurationBlocks ( ) } )
181137 . referenceBlock ( referenceBlock )
182138 . version ( transactionVersion )
183139 . sender ( { address : sender } )
@@ -189,4 +145,26 @@ export class SubstrateCoin extends BaseCoin {
189145 const signedTxHex = transaction . toBroadcastFormat ( ) ;
190146 return { txHex : signedTxHex } ;
191147 }
148+
149+ /**
150+ * Retrieves the address format for the substrate coin.
151+ *
152+ * @returns {number } The address format as a number.
153+ */
154+ protected getAddressFormat ( ) : number {
155+ return DEFAULT_SUBSTRATE_PREFIX ;
156+ }
157+
158+ /**
159+ * Retrieves the maximum validity duration in blocks.
160+ *
161+ * This method is intended to be overridden by subclasses to provide the specific
162+ * maximum validity duration for different types of Substrate-based coins.
163+ *
164+ * @returns {number } The maximum validity duration in blocks.
165+ * @throws {Error } If the method is not implemented by the subclass.
166+ */
167+ protected getMaxValidityDurationBlocks ( ) : number {
168+ throw new Error ( 'Method not implemented.' ) ;
169+ }
192170}
0 commit comments