Skip to content

Commit 69566e1

Browse files
committed
fix: signTxList.
1 parent 88bf97d commit 69566e1

File tree

14 files changed

+140
-168
lines changed

14 files changed

+140
-168
lines changed

CHANGELOG.md

Lines changed: 0 additions & 8 deletions
This file was deleted.

packages/plugin-register/src/index.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ export class BitPluginRegister implements BitPluginBase {
6565
orderId: orderInfo.order_id,
6666
evmChainId: chainId
6767
})
68-
const res = await this.signer.signTxList(mmJsonTxs)
69-
const { hash } = await this.bitBuilder.registerAPI.sendTransaction(res)
68+
const signatureList = await this.signer.signTxList(mmJsonTxs)
69+
const { hash } = await this.bitBuilder.registerAPI.sendTransaction(signatureList)
7070
txHash = hash
7171
}
7272
else {
@@ -108,8 +108,8 @@ export class BitPluginRegister implements BitPluginBase {
108108
account
109109
})
110110

111-
const res = await this.signer.signTxList(mmJsonTxs)
112-
const { hash: txHash } = await this.bitBuilder.crossChainSendTransaction(res)
111+
const signatureList = await this.signer.signTxList(mmJsonTxs)
112+
const { hash: txHash } = await this.bitBuilder.crossChainSendTransaction(signatureList)
113113

114114
return {
115115
keyInfo,
@@ -260,8 +260,8 @@ export class BitPluginRegister implements BitPluginBase {
260260
orderId: orderInfo.order_id,
261261
evmChainId: chainId
262262
})
263-
const res = await this.signer.signTxList(mmJsonTxs)
264-
const { hash } = await this.bitBuilder.registerAPI.sendTransaction(res)
263+
const signatureList = await this.signer.signTxList(mmJsonTxs)
264+
const { hash } = await this.bitBuilder.registerAPI.sendTransaction(signatureList)
265265
txHash = hash
266266
}
267267
else {

src/BitAccount.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { RecordsEditor } from './builders/RecordsEditor'
22
import { RemoteTxBuilder } from './builders/RemoteTxBuilder'
33
import {
44
AccountStatus,
5-
AlgorithmId2CoinType,
5+
SignType2CoinType,
66
BitNetwork,
77
CheckSubAccountStatus,
88
CoinType,
@@ -34,7 +34,7 @@ import {
3434
toRecordExtended,
3535
} from './tools/account'
3636
import { BitErrorCode, BitIndexerErrorCode, BitSubAccountErrorCode, DotbitError } from './errors/DotbitError'
37-
import { TxsWithMMJsonSignedOrUnSigned } from './fetchers/RegisterAPI.type'
37+
import { SignTxListParams } from './fetchers/RegisterAPI.type'
3838
import { CrossChainAccountStatusRes } from './fetchers/CrossChainAPI'
3939
import { matchDWebProtocol } from './tools/common'
4040

@@ -154,9 +154,9 @@ export class BitAccount {
154154
coin_type: coinType,
155155
})
156156

157-
await this.signer.signTxList(txs)
157+
const signatureList = await this.signer.signTxList(txs)
158158

159-
return await this.bitBuilder.subAccountAPI.sendTransaction(txs)
159+
return await this.bitBuilder.subAccountAPI.sendTransaction(signatureList)
160160
}
161161

162162
/**
@@ -240,9 +240,9 @@ export class BitAccount {
240240

241241
const txs = await this.bitBuilder.mintSubAccounts(mintSubAccountsParams)
242242

243-
await this.signer.signTxList(txs)
243+
const signatureList = await this.signer.signTxList(txs)
244244

245-
return await this.bitBuilder.subAccountAPI.sendTransaction(txs)
245+
return await this.bitBuilder.subAccountAPI.sendTransaction(signatureList)
246246
}
247247

248248
/**
@@ -260,7 +260,7 @@ export class BitAccount {
260260
const signerChainType = CoinType2ChainType[signerCoinType]
261261
const newChainType = CoinType2ChainType[keyInfo.coin_type]
262262

263-
let mmJsonTxs: TxsWithMMJsonSignedOrUnSigned
263+
let mmJsonTxs: SignTxListParams
264264
if (isOwner) {
265265
mmJsonTxs = await this.bitBuilder.changeOwner({
266266
chain_type: signerChainType,
@@ -286,9 +286,9 @@ export class BitAccount {
286286
})
287287
}
288288

289-
const res = await this.signer.signTxList(mmJsonTxs)
289+
const signatureList = await this.signer.signTxList(mmJsonTxs)
290290

291-
return await this.bitBuilder.registerAPI.sendTransaction(res)
291+
return await this.bitBuilder.registerAPI.sendTransaction(signatureList)
292292
}
293293

294294
/**
@@ -332,8 +332,8 @@ export class BitAccount {
332332
},
333333
})
334334

335-
const res = await this.signer.signTxList(txs)
336-
return await this.bitBuilder.registerAPI.sendTransaction(res)
335+
const signatureList = await this.signer.signTxList(txs)
336+
return await this.bitBuilder.registerAPI.sendTransaction(signatureList)
337337
}
338338

339339
/**
@@ -360,7 +360,7 @@ export class BitAccount {
360360
const info = await this.info()
361361
return {
362362
key: info.owner_key,
363-
coin_type: AlgorithmId2CoinType[info.owner_algorithm_id],
363+
coin_type: SignType2CoinType[info.owner_algorithm_id],
364364
algorithm_id: info.owner_algorithm_id,
365365
}
366366
}
@@ -369,7 +369,7 @@ export class BitAccount {
369369
const info = await this.info()
370370
return {
371371
key: info.manager_key,
372-
coin_type: AlgorithmId2CoinType[info.manager_algorithm_id],
372+
coin_type: SignType2CoinType[info.manager_algorithm_id],
373373
algorithm_id: info.manager_algorithm_id,
374374
}
375375
}

src/BitSubAccount.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import { BitAccount, BitAccountOptions } from './BitAccount'
22
import { BitAccountRecord, KeyInfo } from './fetchers/BitIndexer.type'
33
import { toEditingRecord } from './fetchers/RegisterAPI'
4-
import { EditAccountRecord } from './fetchers/RegisterAPI.type'
4+
import { EditAccountRecord, SignTxListRes } from './fetchers/RegisterAPI.type'
55
import {
66
EditSubAccountEditKey,
77
EditSubAccountParams,
88
SubAccountListParams,
9-
SubAccountMintParams,
10-
TxsSignedOrUnSigned
9+
SubAccountMintParams
1110
} from './fetchers/SubAccountAPI'
1211
import { BitErrorCode, DotbitError } from './errors/DotbitError'
1312
import { isSubAccount } from './tools/account'
@@ -64,7 +63,7 @@ export class BitSubAccount extends BitAccount {
6463
},
6564
}
6665

67-
let mmJsonTxs: TxsSignedOrUnSigned
66+
let mmJsonTxs: SignTxListRes
6867
if (editKey === 'owner') {
6968
value = value as KeyInfo
7069
mmJsonTxs = await this.bitBuilder.editSubAccount({
@@ -102,9 +101,9 @@ export class BitSubAccount extends BitAccount {
102101
})
103102
}
104103

105-
const res = await this.signer.signTxList(mmJsonTxs)
104+
const signatureList = await this.signer.signTxList(mmJsonTxs)
106105

107-
return await this.bitBuilder.subAccountAPI.sendTransaction(res)
106+
return await this.bitBuilder.subAccountAPI.sendTransaction(signatureList)
108107
}
109108

110109
/**

src/builders/RemoteTxBuilder.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
import { KeyInfo } from '../fetchers/BitIndexer.type'
22
import { RegisterAPI } from '../fetchers/RegisterAPI'
33
import {
4-
CreateSubAccountsParams, EditSubAccountParams,
4+
CreateSubAccountsParams,
5+
EditSubAccountParams,
56
SubAccountAPI,
6-
TxsSignedOrUnSigned,
77
} from '../fetchers/SubAccountAPI'
88
import {
99
EditAccountManagerParam,
1010
EditAccountOwnerParam,
1111
EditAccountRecordsParam,
1212
PayWithDotbitBalanceParam,
1313
ReturnTrxHashToServiceParam,
14+
SignTxListParams,
15+
SignTxListRes,
1416
SubmitRegisterAccountOrderParam,
1517
SubmitRegisterAccountOrderRes,
1618
SubmitRenewAccountOrderParam,
17-
SubmitRenewAccountOrderRes,
18-
TxsWithMMJsonSignedOrUnSigned
19+
SubmitRenewAccountOrderRes
1920
} from '../fetchers/RegisterAPI.type'
2021
import {
2122
CrossChainAPI,
@@ -44,11 +45,11 @@ export class RemoteTxBuilder {
4445
this.crossChainAPI = new CrossChainAPI(config.crossChainUri)
4546
}
4647

47-
enableSubAccount (account: string, keyInfo: KeyInfo): Promise<TxsSignedOrUnSigned> {
48+
enableSubAccount (account: string, keyInfo: KeyInfo): Promise<SignTxListParams> {
4849
return this.subAccountAPI.initSubAccount(account, keyInfo)
4950
}
5051

51-
mintSubAccounts (params: CreateSubAccountsParams): Promise<TxsSignedOrUnSigned> {
52+
mintSubAccounts (params: CreateSubAccountsParams): Promise<SignTxListParams> {
5253
return this.subAccountAPI.createSubAccounts(params)
5354
}
5455

@@ -76,7 +77,7 @@ export class RemoteTxBuilder {
7677
return this.registerAPI.submitRenewAccountOrder(params)
7778
}
7879

79-
payWithDotbitBalance (params: PayWithDotbitBalanceParam): Promise<TxsWithMMJsonSignedOrUnSigned> {
80+
payWithDotbitBalance (params: PayWithDotbitBalanceParam): Promise<SignTxListParams> {
8081
return this.registerAPI.payWithDotbitBalance(params)
8182
}
8283

@@ -88,7 +89,7 @@ export class RemoteTxBuilder {
8889
return this.crossChainAPI.mintNftSignInfo(params)
8990
}
9091

91-
crossChainLockAccount (params: LockAccountParam): Promise<TxsWithMMJsonSignedOrUnSigned> {
92+
crossChainLockAccount (params: LockAccountParam): Promise<SignTxListParams> {
9293
return this.crossChainAPI.lockAccount(params)
9394
}
9495

@@ -100,7 +101,7 @@ export class RemoteTxBuilder {
100101
return this.crossChainAPI.returnTrxHashToService(params)
101102
}
102103

103-
crossChainSendTransaction (params: Omit<TxsWithMMJsonSignedOrUnSigned, 'mm_json'>): Promise<{ hash: string }> {
104+
crossChainSendTransaction (params: SignTxListRes): Promise<{ hash: string }> {
104105
return this.crossChainAPI.sendTransaction(params)
105106
}
106107
}

src/const.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,17 +94,22 @@ export enum IndexerAccountStatus {
9494
onCrossChain
9595
}
9696

97-
export enum AlgorithmId {
98-
ethPersonalSign = 3,
99-
tronSign = 4,
100-
eip712 = 5,
101-
ed2519 = 6,
97+
export enum SIGN_TYPE {
98+
noSign,
99+
ckbMulti,
100+
ckbSingle,
101+
eth,
102+
tron,
103+
eth712,
104+
ed25519,
105+
doge,
106+
webauthn,
102107
}
103108

104-
export const AlgorithmId2CoinType = {
105-
[AlgorithmId.ethPersonalSign]: CoinType.ETH,
106-
[AlgorithmId.eip712]: CoinType.ETH,
107-
[AlgorithmId.tronSign]: CoinType.TRX,
109+
export const SignType2CoinType = {
110+
[SIGN_TYPE.eth]: CoinType.ETH,
111+
[SIGN_TYPE.eth712]: CoinType.ETH,
112+
[SIGN_TYPE.tron]: CoinType.TRX,
108113
}
109114

110115
export enum SubAccountEnabledStatus {

src/fetchers/CrossChainAPI.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Networking } from '../tools/Networking'
22
import { BitKeyInfo, KeyInfo } from './BitIndexer.type'
3-
import { TxsWithMMJsonSignedOrUnSigned } from './RegisterAPI.type'
43
import { CrossChainDirection, CrossChainAccountStatus } from '../const'
4+
import { SignTxListParams, SignTxListRes } from './RegisterAPI.type'
55

66
export interface LockAccountParam {
77
key_info: KeyInfo,
@@ -72,7 +72,7 @@ export class CrossChainAPI {
7272
this.net = new Networking(baseUri)
7373
}
7474

75-
lockAccount (params: LockAccountParam): Promise<TxsWithMMJsonSignedOrUnSigned> {
75+
lockAccount (params: LockAccountParam): Promise<SignTxListParams> {
7676
return this.net.post('lock/account', {
7777
type: 'blockchain',
7878
account: params.account,
@@ -129,7 +129,7 @@ export class CrossChainAPI {
129129
})
130130
}
131131

132-
sendTransaction (params: Omit<TxsWithMMJsonSignedOrUnSigned, 'mm_json'>): Promise<{ hash: string }> {
132+
sendTransaction (params: SignTxListRes): Promise<{ hash: string }> {
133133
return this.net.post('transaction/send', params)
134134
}
135135
}

src/fetchers/RegisterAPI.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ import {
99
EditAccountRecordsParam,
1010
PayWithDotbitBalanceParam,
1111
ReturnTrxHashToServiceParam,
12+
SignTxListParams,
13+
SignTxListRes,
1214
SubmitRegisterAccountOrderParam,
1315
SubmitRegisterAccountOrderRes,
1416
SubmitRenewAccountOrderParam,
15-
SubmitRenewAccountOrderRes,
16-
TxsWithMMJsonSignedOrUnSigned
17+
SubmitRenewAccountOrderRes
1718
} from './RegisterAPI.type'
1819

1920
export function toEditingRecord (record: BitAccountRecord): EditAccountRecord {
@@ -31,15 +32,15 @@ export class RegisterAPI {
3132
this.net = new Networking(baseUri)
3233
}
3334

34-
editAccountManager (params: EditAccountManagerParam): Promise<TxsWithMMJsonSignedOrUnSigned> {
35+
editAccountManager (params: EditAccountManagerParam): Promise<SignTxListParams> {
3536
return this.net.post('account/edit/manager', params)
3637
}
3738

38-
editAccountOwner (params: EditAccountOwnerParam): Promise<TxsWithMMJsonSignedOrUnSigned> {
39+
editAccountOwner (params: EditAccountOwnerParam): Promise<SignTxListParams> {
3940
return this.net.post('account/edit/owner', params)
4041
}
4142

42-
editAccountRecords (params: EditAccountRecordsParam): Promise<TxsWithMMJsonSignedOrUnSigned> {
43+
editAccountRecords (params: EditAccountRecordsParam): Promise<SignTxListParams> {
4344
return this.net.post('account/edit/records', params)
4445
}
4546

@@ -78,7 +79,7 @@ export class RegisterAPI {
7879
})
7980
}
8081

81-
payWithDotbitBalance (params: PayWithDotbitBalanceParam): Promise<TxsWithMMJsonSignedOrUnSigned> {
82+
payWithDotbitBalance (params: PayWithDotbitBalanceParam): Promise<SignTxListParams> {
8283
const address = params.keyInfo.key
8384
const coinType = params.keyInfo.coin_type
8485

@@ -107,12 +108,11 @@ export class RegisterAPI {
107108
})
108109
}
109110

110-
// todo-open: response should have same signature with SubAccountAPI.sendTransaction
111-
sendTransaction (params: Omit<TxsWithMMJsonSignedOrUnSigned, 'mm_json'>): Promise<{hash: string}> {
111+
sendTransaction (params: SignTxListRes): Promise<{hash: string}> {
112112
return this.net.post('transaction/send', {
113113
sign_key: params.sign_key,
114114
sign_list: params.sign_list,
115-
} as Omit<TxsWithMMJsonSignedOrUnSigned, 'mm_json'>)
115+
})
116116
}
117117
}
118118

src/fetchers/RegisterAPI.type.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,25 @@ import { MessageTypes, TypedMessage } from '@metamask/eth-sig-util'
22
import { ChainType, CoinType, EvmChainId, PaymentMethodIDs } from '../const'
33
import { KeyInfo } from './BitIndexer.type'
44

5-
export interface SignList {
5+
export interface SignInfo {
66
sign_type: number,
77
sign_msg: string,
88
}
99

10-
// todo-open: should be merged with TxsSignedOrUnsigned
11-
export interface TxsWithMMJsonSignedOrUnSigned {
10+
export interface SignTxListParams {
11+
action?: string,
12+
sub_action?: string,
1213
sign_key: string,
13-
sign_list: SignList[],
14-
mm_json: TypedMessage<MessageTypes>,
14+
sign_list: SignInfo[],
15+
mm_json?: TypedMessage<MessageTypes>,
16+
}
17+
18+
export interface SignTxListRes {
19+
action?: string,
20+
sub_action?: string,
21+
sign_key: string,
22+
sign_list: SignInfo[],
23+
sign_address?: string,
1524
}
1625

1726
// todo-open: should be replaced with owner

0 commit comments

Comments
 (0)