Add signWithKeypair (#769)

This commit is contained in:
amougel
2018-04-04 00:33:24 +02:00
committed by Elliot Lee
parent c71540e77a
commit 2570e2a6d8
9 changed files with 152 additions and 16 deletions

View File

@@ -503,6 +503,58 @@ describe('RippleAPI', function () {
assert.deepEqual(signature, responses.sign.signAs);
});
it('sign - withKeypair', function () {
const keypair = {
privateKey:
'00ACCD3309DB14D1A4FC9B1DAE608031F4408C85C73EE05E035B7DC8B25840107A',
publicKey:
'02F89EAEC7667B30F33D0687BBA86C3FE2A08CCA40A9186C5BDE2DAA6FA97A37D8'
};
const result = this.api.sign(requests.sign.normal.txJSON, keypair);
assert.deepEqual(result, responses.sign.normal);
schemaValidator.schemaValidate('sign', result);
});
it('sign - withKeypair already signed', function () {
const keypair = {
privateKey:
'00ACCD3309DB14D1A4FC9B1DAE608031F4408C85C73EE05E035B7DC8B25840107A',
publicKey:
'02F89EAEC7667B30F33D0687BBA86C3FE2A08CCA40A9186C5BDE2DAA6FA97A37D8'
};
const result = this.api.sign(requests.sign.normal.txJSON, keypair);
assert.throws(() => {
const tx = JSON.stringify(binary.decode(result.signedTransaction));
this.api.sign(tx, keypair);
}, /txJSON must not contain "TxnSignature" or "Signers" properties/);
});
it('sign - withKeypair EscrowExecution', function () {
const keypair = {
privateKey:
'001ACAAEDECE405B2A958212629E16F2EB46B153EEE94CDD350FDEFF52795525B7',
publicKey:
'0330E7FC9D56BB25D6893BA3F317AE5BCF33B3291BD63DB32654A313222F7FD020'
};
const result = this.api.sign(requests.sign.escrow.txJSON, keypair);
assert.deepEqual(result, responses.sign.escrow);
schemaValidator.schemaValidate('sign', result);
});
it('sign - withKeypair signAs', function () {
const txJSON = requests.sign.signAs;
const keypair = {
privateKey:
'001ACAAEDECE405B2A958212629E16F2EB46B153EEE94CDD350FDEFF52795525B7',
publicKey:
'0330E7FC9D56BB25D6893BA3F317AE5BCF33B3291BD63DB32654A313222F7FD020'
};
const signature = this.api.sign(JSON.stringify(txJSON), keypair, {
signAs: 'rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh'
});
assert.deepEqual(signature, responses.sign.signAs);
});
it('submit', function () {
return this.api.submit(responses.sign.normal.signedTransaction).then(
_.partial(checkResult, responses.submit, 'submit'));