constprivateKey=testData.meta_data.party_a_order.private_key.substring(2);constkeyPair=starkwareCrypto.ec.keyFromPrivate(privateKey,'hex');constpublicKey=starkwareCrypto.ec.keyFromPublic(keyPair.getPublic(true,'hex'),'hex');constpublicKeyX=publicKey.pub.getX();assert(publicKeyX.toString(16)===testData.settlement.party_a_order.public_key.substring(2),`Got: ${publicKeyX.toString(16)}. Expected: ${testData.settlement.party_a_order.public_key.substring(2)}`);const{party_a_order: partyAOrder}=testData.settlement;constfeeInfo=testData.fee_info_user;constmsgHash=starkwareCrypto.getLimitOrderMsgHashWithFee(partyAOrder.vault_id_sell,// - vault_sell (uint64)partyAOrder.vault_id_buy,// - vault_buy (uint64)partyAOrder.amount_sell,// - amount_sell (uint63 decimal str)partyAOrder.amount_buy,// - amount_buy (uint63 decimal str)partyAOrder.token_sell,// - token_sell (hex str with 0x prefix < prime)partyAOrder.token_buy,// - token_buy (hex str with 0x prefix < prime)partyAOrder.nonce,// - nonce (uint31)partyAOrder.expiration_timestamp,// - expiration_timestamp (uint22)feeInfo.token_id,// - token (hex str with 0x prefix < prime)feeInfo.source_vault_id,// - fee_source_vault_id (uint31)feeInfo.fee_limit// - amount (uint63 decimal str));assert(msgHash===testData.meta_data.party_a_order_with_fee.message_hash.substring(2),`Got: ${msgHash}. Expected: `+testData.meta_data.party_a_order_with_fee.message_hash.substring(2));// The following is the JSON representation of an order:console.log('Order With Fee JSON representation: ');// Fee info is added to the order, and will be also be seen in the JSON of Settlement.partyAOrder.fee_info=feeInfo;// eslint-disable-lineconsole.log(partyAOrder);console.log('\n');
StarkEx transfer
conststarkwareCrypto=require('@starkware-libs/starkware-crypto-utils');consttestData=require('test/config/signature_test_data.json');constprivateKey=testData.meta_data.transfer_order.private_key.substring(2);constkeyPair=starkwareCrypto.ec.keyFromPrivate(privateKey,'hex');constpublicKey=starkwareCrypto.ec.keyFromPublic(keyPair.getPublic(true,'hex'),'hex');constpublicKeyX=publicKey.pub.getX();assert(publicKeyX.toString(16)===testData.transfer_order.public_key.substring(2),`Got: ${publicKeyX.toString(16)}. Expected: ${testData.transfer_order.public_key.substring(2)}`);consttransfer=testData.transfer_order;constmsgHash=starkwareCrypto.getTransferMsgHash(transfer.amount,// - amount (uint63 decimal str)transfer.nonce,// - nonce (uint31)transfer.sender_vault_id,// - sender_vault_id (uint31)transfer.token,// - token (hex str with 0x prefix < prime)transfer.target_vault_id,// - target_vault_id (uint31)transfer.target_public_key,// - target_public_key (hex str with 0x prefix < prime)transfer.expiration_timestamp// - expiration_timestamp (uint22));assert(msgHash===testData.meta_data.transfer_order.message_hash.substring(2),`Got: ${msgHash}. Expected: `+testData.meta_data.transfer_order.message_hash.substring(2));// The following is the JSON representation of a transfer:console.log('Transfer JSON representation: ');console.log(transfer);console.log('\n');
StarkEx conditional transfer
conststarkwareCrypto=require('@starkware-libs/starkware-crypto-utils');consttestData=require('test/config/signature_test_data.json');constprivateKey=testData.meta_data.conditional_transfer_order.private_key.substring(2);constkeyPair=starkwareCrypto.ec.keyFromPrivate(privateKey,'hex');constpublicKey=starkwareCrypto.ec.keyFromPublic(keyPair.getPublic(true,'hex'),'hex');constpublicKeyX=publicKey.pub.getX();assert(publicKeyX.toString(16)===testData.conditional_transfer_order.public_key.substring(2),`Got: ${publicKeyX.toString(16)}. Expected: ${testData.conditional_transfer_order.public_key.substring(2)}`);consttransfer=testData.conditional_transfer_order;constmsgHash=starkwareCrypto.getTransferMsgHash(transfer.amount,// - amount (uint63 decimal str)transfer.nonce,// - nonce (uint31)transfer.sender_vault_id,// - sender_vault_id (uint31)transfer.token,// - token (hex str with 0x prefix < prime)transfer.target_vault_id,// - target_vault_id (uint31)transfer.target_public_key,// - target_public_key (hex str with 0x prefix < prime)transfer.expiration_timestamp,// - expiration_timestamp (uint22)transfer.condition// - condition (hex str with 0x prefix < prime));assert(msgHash===testData.meta_data.conditional_transfer_order.message_hash.substring(2),`Got: ${msgHash}. Expected: `+testData.meta_data.conditional_transfer_order.message_hash.substring(2));// The following is the JSON representation of a transfer:console.log('Conditional Transfer JSON representation: ');console.log(transfer);console.log('\n');
StarkEx transfer with fee
constprivateKey=testData.meta_data.transfer_order.private_key.substring(2);constkeyPair=starkwareCrypto.ec.keyFromPrivate(privateKey,'hex');constpublicKey=starkwareCrypto.ec.keyFromPublic(keyPair.getPublic(true,'hex'),'hex');constpublicKeyX=publicKey.pub.getX();assert(publicKeyX.toString(16)===testData.transfer_order.public_key.substring(2),`Got: ${publicKeyX.toString(16)}. Expected: ${testData.transfer_order.public_key.substring(2)}`);consttransfer=testData.transfer_order;constfeeInfo=testData.fee_info_user;constmsgHash=starkwareCrypto.getTransferMsgHashWithFee(transfer.amount,// - amount (uint63 decimal str)transfer.nonce,// - nonce (uint31)transfer.sender_vault_id,// - sender_vault_id (uint64)transfer.token,// - token (hex str with 0x prefix < prime)transfer.target_vault_id,// - target_vault_id (uint64)transfer.target_public_key,// - target_public_key (hex str with 0x prefix < prime)transfer.expiration_timestamp,// - expiration_timestamp (uint22)feeInfo.token_id,// - token (hex str with 0x prefix < prime)feeInfo.source_vault_id,// - fee_source_vault_id (uint64)feeInfo.fee_limit// - amount (uint63 decimal str));assert(msgHash===testData.meta_data.transfer_order_with_fee.message_hash.substring(2),`Got: ${msgHash}. Expected: `+testData.meta_data.transfer_order.message_hash.substring(2));// The following is the JSON representation of a transfer:console.log('Transfer With Fee JSON representation: ');console.log(transfer);console.log('\n');
StarkEx conditional Transfer with fee
constprivateKey=testData.meta_data.conditional_transfer_order.private_key.substring(2);constkeyPair=starkwareCrypto.ec.keyFromPrivate(privateKey,'hex');constpublicKey=starkwareCrypto.ec.keyFromPublic(keyPair.getPublic(true,'hex'),'hex');constpublicKeyX=publicKey.pub.getX();assert(publicKeyX.toString(16)===testData.conditional_transfer_order.public_key.substring(2),`Got: ${publicKeyX.toString(16)}. Expected: ${testData.conditional_transfer_order.public_key.substring(2)}`);consttransfer=testData.conditional_transfer_order;constfeeInfo=testData.fee_info_user;constmsgHash=starkwareCrypto.getTransferMsgHashWithFee(transfer.amount,// - amount (uint63 decimal str)transfer.nonce,// - nonce (uint31)transfer.sender_vault_id,// - sender_vault_id (uint64)transfer.token,// - token (hex str with 0x prefix < prime)transfer.target_vault_id,// - target_vault_id (uint64)transfer.target_public_key,// - target_public_key (hex str with 0x prefix < prime)transfer.expiration_timestamp,// - expiration_timestamp (uint22)feeInfo.token_id,// - token (hex str with 0x prefix < prime)feeInfo.source_vault_id,// - fee_source_vault_id (uint64)feeInfo.fee_limit,// - amount (uint63 decimal str)transfer.condition// - condition (hex str with 0x prefix < prime));assert(msgHash===testData.meta_data.conditional_transfer_order_with_fee.message_hash.substring(2),`Got: ${msgHash}. Expected: `+testData.meta_data.conditional_transfer_order.message_hash.substring(2));// The following is the JSON representation of a transfer:console.log('Conditional Transfer With Fee JSON representation: ');console.log(transfer);console.log('\n');
Adding a matching order to create a settlement
conststarkwareCrypto=require('@starkware-libs/starkware-crypto-utils');consttestData=require('test/config/signature_test_data.json');constprivateKey=testData.meta_data.party_b_order.private_key.substring(2);constkeyPair=starkwareCrypto.ec.keyFromPrivate(privateKey,'hex');constpublicKey=starkwareCrypto.ec.keyFromPublic(keyPair.getPublic(true,'hex'),'hex');constpublicKeyX=publicKey.pub.getX();assert(publicKeyX.toString(16)===testData.settlement.party_b_order.public_key.substring(2),`Got: ${publicKeyX.toString(16)}. Expected: ${testData.settlement.party_b_order.public_key.substring(2)}`);const{party_b_order: partyBOrder}=testData.settlement;constmsgHash=starkwareCrypto.getLimitOrderMsgHash(partyBOrder.vault_id_sell,// - vault_sell (uint31)partyBOrder.vault_id_buy,// - vault_buy (uint31)partyBOrder.amount_sell,// - amount_sell (uint63 decimal str)partyBOrder.amount_buy,// - amount_buy (uint63 decimal str)partyBOrder.token_sell,// - token_sell (hex str with 0x prefix < prime)partyBOrder.token_buy,// - token_buy (hex str with 0x prefix < prime)partyBOrder.nonce,// - nonce (uint31)partyBOrder.expiration_timestamp// - expiration_timestamp (uint22));assert(msgHash===testData.meta_data.party_b_order.message_hash.substring(2),`Got: ${msgHash}. Expected: `+testData.meta_data.party_b_order.message_hash.substring(2));constmsgSignature=starkwareCrypto.sign(keyPair,msgHash);const{r, s}=msgSignature;assert(starkwareCrypto.verify(publicKey,msgHash,msgSignature));assert(r.toString(16)===partyBOrder.signature.r.substring(2),`Got: ${r.toString(16)}. Expected: ${partyBOrder.signature.r.substring(2)}`);assert(s.toString(16)===partyBOrder.signature.s.substring(2),`Got: ${s.toString(16)}. Expected: ${partyBOrder.signature.s.substring(2)}`);// The following is the JSON representation of a settlement:console.log('Settlement JSON representation: ');console.log(testData.settlement);
Valid transfer with sender_vault_id=2**63+10
consttransfer=testData.transfer_order_2nd_valid_range;constfeeInfo=testData.fee_info_user;constmsgHash=starkwareCrypto.getTransferMsgHashWithFee(transfer.amount,// - amount (uint63 decimal str)transfer.nonce,// - nonce (uint31)transfer.sender_vault_id,// - sender_vault_id (uint64)transfer.token,// - token (hex str with 0x prefix < prime)transfer.target_vault_id,// - target_vault_id (uint64)transfer.target_public_key,// - target_public_key (hex str with 0x prefix < prime)transfer.expiration_timestamp,// - expiration_timestamp (uint22)feeInfo.token_id,// - token (hex str with 0x prefix < prime)feeInfo.source_vault_id,// - fee_source_vault_id (uint64)feeInfo.fee_limit,// - amount (uint63 decimal str)transfer.condition// - condition (hex str with 0x prefix < prime));assert(msgHash===testData.meta_data.transfer_order_2nd_valid_range.message_hash.substring(2),`Got: ${msgHash}. Expected: `+testData.meta_data.transfer_order_2nd_valid_range.message_hash.substring(2));// The following is the JSON representation of a transfer with sender_vault_id in the second// valid range:console.log('Transfer JSON representation: ');console.log(transfer);console.log('\n');