Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions js/tests/redemption.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ const TEST_VECTORS = [
{
redemptionKey: Buffer.from('qXQWDxI3JrlFRtC4SeQjeGzLbVXWBomYPbNO1Vfm1T4=', 'base64'),
expectedAddress: 'Ae2tdPwUPEZ1xZTLczMGYL5PhADi1nbFmESqS9vUuLkyUe1isQ77TRUE9NS',
expectedPublicKey: 'faf8ed5be127c8ea22e3a0f1b9335f910aaa672e96c41d7cbdcaed897a450667',
expectedSignature: '80ed81b9f3683684fdb7c286eb7cfa63580a239ed6bf67f71643d290de2206855171003c7f33cad04e9fa28ee5d5c18c4e5f0d788ae2a63fa492ba7b59995c03',
txId: new Uint8Array([0xaa,0xd7,0x8a,0x13,0xb5,0x0a,0x01,0x4a,0x24,0x63,0x3c,0x7d,0x44,0xfd,0x8f,0x8d,0x18,0xf6,0x7b,0xbb,0x3f,0xa9,0xcb,0xce,0xdf,0x83,0x4a,0xc8,0x99,0x75,0x9d,0xcd]),
txOutIndex: 1,
coinValue: 12345678
}
];

let mkTest = (i) => {
const { redemptionKey, expectedAddress, txId, txOutIndex, coinValue } = TEST_VECTORS[i];
const { redemptionKey, expectedAddress, expectedPublicKey, expectedSignature, txId, txOutIndex, coinValue } = TEST_VECTORS[i];
const cfg = CardanoCrypto.Config.defaultConfig();

describe('Test ' + i, function() {
Expand Down Expand Up @@ -65,12 +67,10 @@ let mkTest = (i) => {
const [[witnessType, witnessTagged]] = resultWitnesses;
expect(witnessType).equal(2);
const [witnessPub, witnessSign] = cbor.decode(witnessTagged.value);

// TODO: expecting fake witness data - fix after implementing signing in Rust
expect(witnessPub.toString('hex'))
.equal('ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff');
.equal(expectedPublicKey);
expect(witnessSign.toString('hex'))
.equal('ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff');
.equal(expectedSignature);
});
});
};
Expand Down
2 changes: 1 addition & 1 deletion rust
Submodule rust updated from e869c9 to 9bef10
22 changes: 3 additions & 19 deletions wallet-wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ pub extern "C" fn wallet_tx_sign(
let mut deserialiser = cbor_event::de::Deserializer::from(tx_bytes.as_slice());
let tx: tx::Tx = deserialiser.deserialize_complete().unwrap();

let txinwitness = tx::TxInWitness::new(cfg.protocol_magic, &xprv, &tx.id());
let txinwitness = tx::TxInWitness::new_extended_pk(cfg.protocol_magic, &xprv, &tx.id());

let signature = match txinwitness {
tx::TxInWitness::PkWitness(_, sig) => sig,
Expand Down Expand Up @@ -1307,10 +1307,8 @@ pub extern "C" fn xwallet_redeem(
redeem::PrivateKey::from_slice(&data.redemption_key)
);
print!("Key: {}", redemption_key);
let witness = jrpc_try!(
output_ptr,
create_redemption_witness(data.protocol_magic, &redemption_key, &tx.id())
);
let witness = tx::TxInWitness::new_redeem_pk(
data.protocol_magic, &redemption_key, &tx.id());
let mut finalized = txbuild::TxFinalized::new(tx);
jrpc_try!(
output_ptr,
Expand All @@ -1325,17 +1323,3 @@ pub extern "C" fn xwallet_redeem(
cbor_encoded_tx: cbor
})
}

fn create_redemption_witness(
protocol_magic: cardano::config::ProtocolMagic,
key: &redeem::PrivateKey,
txid: &tx::TxId,
) -> redeem::Result<tx::TxInWitness> {
// TODO: actual implementation
let s32 = (0..64).map(|_| "f").collect::<String>();
let s64 = (0..128).map(|_| "f").collect::<String>();
let pk = redeem::PublicKey::from_hex(&s32);
let sg = redeem::Signature::from_hex(&s64);
return pk.and_then(|k| sg.map(|s| (k, s)))
.map(|(k,s)| tx::TxInWitness::RedeemWitness(k, s));
}