@@ -26,7 +26,7 @@ let Cosmos = function(url, chainId) {
26
26
throw new Error ( "chainId object was not set or invalid" )
27
27
}
28
28
29
- console . log ( "WARN deprecated @cosmostation/cosmosjs@0.8.2 : You needs to upgrade to @cosmostation/cosmosjs above 0.9 .0+ : 1) Proper nodejs v14+ support 2) 0.9 .0+ supports protobuf signing for cosmos-sdk 0.40.0+" ) ;
29
+ console . log ( "WARN deprecated @cosmostation/cosmosjs@0.9.x : You needs to upgrade to @cosmostation/cosmosjs above 0.10 .0+ : 1) Proper nodejs v14+ support 2) 0.10 .0+ supports protobuf signing for cosmos-sdk 0.40.0+" ) ;
30
30
}
31
31
32
32
function network ( url , chainId ) {
@@ -84,8 +84,10 @@ Cosmos.prototype.getAccounts = function(address) {
84
84
accountsApi = "/cosmos/auth/v1beta1/accounts/" ;
85
85
} else if ( this . chainId . indexOf ( "stargate-final" ) != - 1 ) {
86
86
accountsApi = "/cosmos/auth/v1beta1/accounts/" ;
87
+ } else if ( this . chainId . indexOf ( "bifrost" ) != - 1 ) {
88
+ accountsApi = "/cosmos/auth/v1beta1/accounts/" ;
87
89
} else if ( this . chainId . indexOf ( "irishub" ) != - 1 ) {
88
- accountsApi = "/bank /accounts/" ;
90
+ accountsApi = "/cosmos/auth/v1beta1 /accounts/" ;
89
91
} else {
90
92
accountsApi = "/auth/accounts/" ;
91
93
}
@@ -121,150 +123,44 @@ Cosmos.prototype.getECPairPriv = function(mnemonic) {
121
123
Cosmos . prototype . newStdMsg = function ( input ) {
122
124
const stdSignMsg = new Object ;
123
125
stdSignMsg . json = input ;
124
-
125
- // Exception
126
- if ( input . msgs [ 0 ] . type == "irishub/bank/Send" ) {
127
- stdSignMsg . jsonForSigningIrisTx =
128
- {
129
- msgs : [
130
- {
131
- inputs : [
132
- {
133
- address : input . msgs [ 0 ] . value . inputs [ 0 ] . address ,
134
- coins : [
135
- {
136
- denom : input . msgs [ 0 ] . value . inputs [ 0 ] . coins [ 0 ] . denom ,
137
- amount : input . msgs [ 0 ] . value . inputs [ 0 ] . coins [ 0 ] . amount
138
- }
139
- ]
140
- }
141
- ] ,
142
- outputs : [
143
- ...input . msgs [ 0 ] . value . outputs
144
- ]
145
- }
146
- ] ,
147
- chain_id : input . chain_id ,
148
- fee : { amount : [ { amount : input . fee . amount [ 0 ] . amount , denom : input . fee . amount [ 0 ] . denom } ] , gas : input . fee . gas } ,
149
- memo : input . memo ,
150
- account_number : input . account_number ,
151
- sequence : input . sequence
152
- }
153
- } else if ( input . msgs [ 0 ] . type == "irishub/stake/BeginUnbonding" ) {
154
- stdSignMsg . jsonForSigningIrisTx =
155
- {
156
- msgs : [
157
- {
158
- shares_amount : String ( input . msgs [ 0 ] . value . shares_amount ) ,
159
- delegator_addr : input . msgs [ 0 ] . value . delegator_addr ,
160
- validator_addr : input . msgs [ 0 ] . value . validator_addr
161
- }
162
- ] ,
163
- chain_id : input . chain_id ,
164
- fee : { amount : [ { amount : input . fee . amount [ 0 ] . amount , denom : input . fee . amount [ 0 ] . denom } ] , gas : input . fee . gas } ,
165
- memo : input . memo ,
166
- account_number : input . account_number ,
167
- sequence : input . sequence
168
- }
169
- } else if ( input . msgs [ 0 ] . type == "irishub/stake/BeginRedelegate" ) {
170
- stdSignMsg . jsonForSigningIrisTx =
171
- {
172
- msgs : [
173
- {
174
- delegator_addr : input . msgs [ 0 ] . value . delegator_addr ,
175
- validator_src_addr : input . msgs [ 0 ] . value . validator_src_addr ,
176
- validator_dst_addr : input . msgs [ 0 ] . value . validator_dst_addr ,
177
- shares : String ( input . msgs [ 0 ] . value . shares_amount ) + ".0000000000" // IRIS Exception) For signing, shares is correct.
178
- }
179
- ] ,
180
- chain_id : input . chain_id ,
181
- fee : { amount : [ { amount : input . fee . amount [ 0 ] . amount , denom : input . fee . amount [ 0 ] . denom } ] , gas : input . fee . gas } ,
182
- memo : input . memo ,
183
- account_number : input . account_number ,
184
- sequence : input . sequence
185
- }
186
- }
187
-
188
126
stdSignMsg . bytes = convertStringToBytes ( JSON . stringify ( sortObject ( stdSignMsg . json ) ) ) ;
189
127
return stdSignMsg ;
190
128
}
191
129
192
130
Cosmos . prototype . sign = function ( stdSignMsg , ecpairPriv , modeType = "sync" ) {
193
131
// The supported return types includes "block"(return after tx commit), "sync"(return after CheckTx) and "async"(return right away).
194
132
let signMessage = new Object ;
195
- if ( stdSignMsg . json . msgs [ 0 ] . type == "irishub/bank/Send" ||
196
- stdSignMsg . json . msgs [ 0 ] . type == "irishub/stake/BeginUnbonding" ||
197
- stdSignMsg . json . msgs [ 0 ] . type == "irishub/stake/BeginRedelegate" ) {
198
- signMessage = stdSignMsg . jsonForSigningIrisTx ;
199
- } else {
200
- signMessage = stdSignMsg . json ;
201
- }
133
+ signMessage = stdSignMsg . json ;
202
134
const hash = crypto . createHash ( 'sha256' ) . update ( JSON . stringify ( sortObject ( signMessage ) ) ) . digest ( 'hex' ) ;
203
135
const buf = Buffer . from ( hash , 'hex' ) ;
204
136
let signObj = secp256k1 . sign ( buf , ecpairPriv ) ;
205
137
var signatureBase64 = Buffer . from ( signObj . signature , 'binary' ) . toString ( 'base64' ) ;
206
138
let signedTx = new Object ;
207
- if ( this . chainId . indexOf ( "irishub" ) != - 1 ) {
208
- signedTx = {
209
- "tx" : {
210
- "msg" : stdSignMsg . json . msgs ,
211
- "fee" : stdSignMsg . json . fee ,
212
- "signatures" : [
213
- {
214
- "signature" : signatureBase64 ,
215
- "account_number" : stdSignMsg . json . account_number ,
216
- "sequence" : stdSignMsg . json . sequence ,
217
- "pub_key" : {
218
- "type" : "tendermint/PubKeySecp256k1" ,
219
- "value" : getPubKeyBase64 ( ecpairPriv )
220
- }
221
- }
222
- ] ,
223
- "memo" : stdSignMsg . json . memo
224
- } ,
225
- "mode" : modeType
226
- }
227
-
228
- // The key of "shares" is using to sign for IRIS Redelegate.
229
- // After signing, you have to replace the "shares" key name to "shares_amount".
230
- // It is an exception to "irishub/stake/BeginRedelegate".
231
- if ( stdSignMsg . json . msgs [ 0 ] . type == "irishub/stake/BeginRedelegate" ) {
232
- var txBodyStr = JSON . stringify ( signedTx ) ;
233
- txBodyStr = txBodyStr . replace ( "\"shares" , "\"shares_amount" ) ;
234
- signedTx = JSON . parse ( txBodyStr ) ;
235
- }
236
- } else {
237
- signedTx = {
238
- "tx" : {
239
- "msg" : stdSignMsg . json . msgs ,
240
- "fee" : stdSignMsg . json . fee ,
241
- "signatures" : [
242
- {
243
- "account_number" : stdSignMsg . json . account_number ,
244
- "sequence" : stdSignMsg . json . sequence ,
245
- "signature" : signatureBase64 ,
246
- "pub_key" : {
247
- "type" : "tendermint/PubKeySecp256k1" ,
248
- "value" : getPubKeyBase64 ( ecpairPriv )
249
- }
250
- }
251
- ] ,
252
- "memo" : stdSignMsg . json . memo
253
- } ,
254
- "mode" : modeType
255
- }
139
+ signedTx = {
140
+ "tx" : {
141
+ "msg" : stdSignMsg . json . msgs ,
142
+ "fee" : stdSignMsg . json . fee ,
143
+ "signatures" : [
144
+ {
145
+ "account_number" : stdSignMsg . json . account_number ,
146
+ "sequence" : stdSignMsg . json . sequence ,
147
+ "signature" : signatureBase64 ,
148
+ "pub_key" : {
149
+ "type" : "tendermint/PubKeySecp256k1" ,
150
+ "value" : getPubKeyBase64 ( ecpairPriv )
151
+ }
152
+ }
153
+ ] ,
154
+ "memo" : stdSignMsg . json . memo
155
+ } ,
156
+ "mode" : modeType
256
157
}
257
158
258
159
return signedTx ;
259
160
}
260
161
261
162
Cosmos . prototype . broadcast = function ( signedTx ) {
262
- let broadcastApi = "" ;
263
- if ( this . chainId . indexOf ( "irishub" ) != - 1 ) {
264
- broadcastApi = "/tx/broadcast" ;
265
- } else {
266
- broadcastApi = "/txs" ;
267
- }
163
+ let broadcastApi = "/txs" ;
268
164
269
165
return fetch ( this . url + broadcastApi , {
270
166
method : 'POST' ,
0 commit comments