@@ -41,6 +41,7 @@ import {
41
41
import { RosettaConstants , RosettaErrors } from '../api/rosetta-constants' ;
42
42
import { GetStacksTestnetNetwork , testnetKeys } from '../api/routes/debug' ;
43
43
import { getOptionsFromOperations , getSignature } from '../rosetta-helpers' ;
44
+ import { MessageSignature } from '@blockstack/stacks-transactions/lib/authorization' ;
44
45
45
46
describe ( 'Rosetta API' , ( ) => {
46
47
let db : PgDataStore ;
@@ -135,6 +136,8 @@ describe('Rosetta API', () => {
135
136
message : 'Signature(s) not verified with this public key(s)' ,
136
137
retriable : false ,
137
138
} ,
139
+ { code : 636 , message : 'Need one public key for single signature' , retriable : false } ,
140
+ { code : 637 , message : 'Need only one signature' , retriable : false } ,
138
141
] ,
139
142
historical_balance_lookup : true ,
140
143
} ,
@@ -1255,7 +1258,7 @@ describe('Rosetta API', () => {
1255
1258
expect ( JSON . parse ( result . text ) ) . toEqual ( expectedResponse ) ;
1256
1259
} ) ;
1257
1260
1258
- test ( 'payloads multi sign success ' , async ( ) => {
1261
+ test ( 'payloads multi sig ' , async ( ) => {
1259
1262
const publicKey1 = publicKeyToString ( pubKeyfromPrivKey ( testnetKeys [ 0 ] . secretKey ) ) ;
1260
1263
const publicKey2 = publicKeyToString ( pubKeyfromPrivKey ( testnetKeys [ 1 ] . secretKey ) ) ;
1261
1264
@@ -1345,39 +1348,14 @@ describe('Rosetta API', () => {
1345
1348
] ,
1346
1349
} ;
1347
1350
1348
- const accountInfo = await new StacksCoreRpcClient ( ) . getAccount ( sender ) ;
1349
-
1350
- const tokenTransferOptions : UnsignedMultiSigTokenTransferOptions = {
1351
- recipient : recipient ,
1352
- amount : new BN ( '500000' ) ,
1353
- fee : new BN ( fee ) ,
1354
- publicKeys : [ publicKey1 , publicKey2 ] ,
1355
- numSignatures : 2 ,
1356
- network : GetStacksTestnetNetwork ( ) ,
1357
- nonce : accountInfo . nonce ? new BN ( accountInfo . nonce ) : new BN ( 0 ) ,
1358
- } ;
1359
-
1360
- const transaction = await makeUnsignedSTXTokenTransfer ( tokenTransferOptions ) ;
1361
- const unsignedTransaction = transaction . serialize ( ) ;
1362
- const hexBytes = digestSha512_256 ( unsignedTransaction ) . toString ( 'hex' ) ;
1363
-
1364
1351
const result = await supertest ( api . server )
1365
1352
. post ( `/rosetta/v1/construction/payloads` )
1366
1353
. send ( request ) ;
1367
1354
1368
- expect ( result . status ) . toBe ( 200 ) ;
1355
+ expect ( result . status ) . toBe ( 400 ) ;
1369
1356
expect ( result . type ) . toBe ( 'application/json' ) ;
1370
1357
1371
- const expectedResponse = {
1372
- unsigned_transaction : unsignedTransaction . toString ( 'hex' ) ,
1373
- payloads : [
1374
- {
1375
- address : sender ,
1376
- hex_bytes : '0x' + hexBytes ,
1377
- signature_type : 'ecdsa' ,
1378
- } ,
1379
- ] ,
1380
- } ;
1358
+ const expectedResponse = RosettaErrors . needOnePublicKey ;
1381
1359
1382
1360
expect ( JSON . parse ( result . text ) ) . toEqual ( expectedResponse ) ;
1383
1361
} ) ;
@@ -1578,8 +1556,7 @@ describe('Rosetta API', () => {
1578
1556
signer . signOrigin ( createStacksPrivateKey ( testnetKeys [ 0 ] . secretKey ) ) ;
1579
1557
const signedSerializedTx = unsignedTransaction . serialize ( ) . toString ( 'hex' ) ;
1580
1558
1581
- const signature = getSignature ( unsignedTransaction ) ;
1582
- if ( ! signature ) return ;
1559
+ const signature : MessageSignature = getSignature ( unsignedTransaction ) as MessageSignature ;
1583
1560
1584
1561
const request : RosettaConstructionCombineRequest = {
1585
1562
network_identifier : {
@@ -1617,49 +1594,42 @@ describe('Rosetta API', () => {
1617
1594
expect ( JSON . parse ( result . text ) ) . toEqual ( expectedResponse ) ;
1618
1595
} ) ;
1619
1596
1620
- test ( 'combine multi sign success' , async ( ) => {
1621
- const publicKey1 = publicKeyToString ( pubKeyfromPrivKey ( testnetKeys [ 0 ] . secretKey ) ) ;
1622
- const publicKey2 = publicKeyToString ( pubKeyfromPrivKey ( testnetKeys [ 1 ] . secretKey ) ) ;
1623
-
1624
- const txOptions : UnsignedMultiSigTokenTransferOptions = {
1625
- publicKeys : [ publicKey1 , publicKey2 ] ,
1626
- numSignatures : 2 ,
1627
- recipient : standardPrincipalCV ( testnetKeys [ 1 ] . stacksAddress ) ,
1628
- amount : new BigNum ( 12345 ) ,
1629
- network : GetStacksTestnetNetwork ( ) ,
1630
- memo : 'test memo' ,
1631
- nonce : new BigNum ( 0 ) ,
1632
- fee : new BigNum ( 200 ) ,
1633
- } ;
1634
-
1635
- const unsignedTransaction = await makeUnsignedSTXTokenTransfer ( txOptions ) ;
1636
- const unsignedSerializedTx = unsignedTransaction . serialize ( ) . toString ( 'hex' ) ;
1637
-
1638
- const signer = new TransactionSigner ( unsignedTransaction ) ;
1639
- signer . signOrigin ( createStacksPrivateKey ( testnetKeys [ 0 ] . secretKey ) ) ;
1640
- const signedSerializedTx = unsignedTransaction . serialize ( ) . toString ( 'hex' ) ;
1641
-
1642
- const signature = getSignature ( unsignedTransaction ) ;
1643
- if ( ! signature ) return ;
1644
-
1597
+ test ( 'combine multi sig' , async ( ) => {
1645
1598
const request : RosettaConstructionCombineRequest = {
1646
1599
network_identifier : {
1647
1600
blockchain : 'stacks' ,
1648
1601
network : 'testnet' ,
1649
1602
} ,
1650
- unsigned_transaction : unsignedSerializedTx ,
1603
+ unsigned_transaction :
1604
+ '00000000010400539886f96611ba3ba6cef9618f8c78118b37c5be0000000000000000000000000000006400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003020000000000051ab71a091b4b8b7661a661c620966ab6573bc2dcd3000000000007a12074657374207472616e73616374696f6e000000000000000000000000000000000000' ,
1651
1605
signatures : [
1652
1606
{
1653
1607
signing_payload : {
1654
- hex_bytes : signature . data ,
1608
+ hex_bytes :
1609
+ '017c7fc676effda9d905440a052d304b5d9705c30625e654f5b3c9ed461337cdec695d14e5f24091d61f8409f2ab703102ca840dbf5ef752ec534fe1f418552201' ,
1655
1610
signature_type : 'ecdsa' ,
1656
1611
} ,
1657
1612
public_key : {
1658
- hex_bytes : publicKey1 ,
1613
+ hex_bytes : '025c13b2fc2261956d8a4ad07d481b1a3b2cbf93a24f992249a61c3a1c4de79c51' ,
1659
1614
curve_type : 'secp256k1' ,
1660
1615
} ,
1661
1616
signature_type : 'ecdsa' ,
1662
- hex_bytes : signature . data ,
1617
+ hex_bytes :
1618
+ '017c7fc676effda9d905440a052d304b5d9705c30625e654f5b3c9ed461337cdec695d14e5f24091d61f8409f2ab703102ca840dbf5ef752ec534fe1f418552201' ,
1619
+ } ,
1620
+ {
1621
+ signing_payload : {
1622
+ hex_bytes :
1623
+ '017c7fc676effda9d905440a052d304b5d9705c30625e654f5b3c9ed461337cdec695d14e5f24091d61f8409f2ab703102ca840dbf5ef752ec534fe1f418552201' ,
1624
+ signature_type : 'ecdsa' ,
1625
+ } ,
1626
+ public_key : {
1627
+ hex_bytes : '025c13b2fc2261956d8a4ad07d481b1a3b2cbf93a24f992249a61c3a1c4de79c51' ,
1628
+ curve_type : 'secp256k1' ,
1629
+ } ,
1630
+ signature_type : 'ecdsa' ,
1631
+ hex_bytes :
1632
+ '017c7fc676effda9d905440a052d304b5d9705c30625e654f5b3c9ed461337cdec695d14e5f24091d61f8409f2ab703102ca840dbf5ef752ec534fe1f418552201' ,
1663
1633
} ,
1664
1634
] ,
1665
1635
} ;
@@ -1668,12 +1638,10 @@ describe('Rosetta API', () => {
1668
1638
. post ( `/rosetta/v1/construction/combine` )
1669
1639
. send ( request ) ;
1670
1640
1671
- expect ( result . status ) . toBe ( 200 ) ;
1641
+ expect ( result . status ) . toBe ( 400 ) ;
1672
1642
expect ( result . type ) . toBe ( 'application/json' ) ;
1673
1643
1674
- const expectedResponse : RosettaConstructionCombineResponse = {
1675
- signed_transaction : signedSerializedTx ,
1676
- } ;
1644
+ const expectedResponse = RosettaErrors . needOnlyOneSignature ;
1677
1645
1678
1646
expect ( JSON . parse ( result . text ) ) . toEqual ( expectedResponse ) ;
1679
1647
} ) ;
@@ -1772,7 +1740,7 @@ describe('Rosetta API', () => {
1772
1740
signer . signOrigin ( createStacksPrivateKey ( testnetKeys [ 1 ] . secretKey ) ) ; // use different secret key to sign
1773
1741
1774
1742
const signature = getSignature ( unsignedTransaction ) ;
1775
- if ( ! signature ) return ;
1743
+ if ( ! signature ) throw Error ( 'Signature undefined' ) ;
1776
1744
1777
1745
const request : RosettaConstructionCombineRequest = {
1778
1746
network_identifier : {
0 commit comments