This repository has been archived by the owner on Sep 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prepare/sign/submit flow for settings
- Loading branch information
Chris Clark
committed
Apr 10, 2015
1 parent
7b1af23
commit eadb0db
Showing
17 changed files
with
444 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
'use strict'; | ||
var sjcl = require('ripple-lib').sjcl; | ||
var Seed = require('ripple-lib').Seed; | ||
var SerializedObject = require('ripple-lib').SerializedObject; | ||
var validate = require('./lib/validate'); | ||
|
||
/** | ||
* These prefixes are inserted before the source material used to | ||
* generate various hashes. This is done to put each hash in its own | ||
* "space." This way, two different types of objects with the | ||
* same binary data will produce different hashes. | ||
* | ||
* Each prefix is a 4-byte value with the last byte set to zero | ||
* and the first three bytes formed from the ASCII equivalent of | ||
* some arbitrary string. For example "TXN". | ||
*/ | ||
var HASH_TX_ID = 0x54584E00; // 'TXN' | ||
var HASH_TX_SIGN = 0x53545800; // 'STX' | ||
var HASH_TX_SIGN_TESTNET = 0x73747800; // 'stx' | ||
|
||
function getKeyPair(address, secret) { | ||
return Seed.from_json(secret).get_key(address); | ||
} | ||
|
||
function getPublicKeyHex(keypair) { | ||
return keypair.to_hex_pub(); | ||
} | ||
|
||
function serialize(txJSON) { | ||
return SerializedObject.from_json(txJSON); | ||
} | ||
|
||
function hashSerialization(serialized, prefix) { | ||
return serialized.hash(prefix || HASH_TX_ID).to_hex(); | ||
} | ||
|
||
function hashJSON(txJSON, prefix) { | ||
return hashSerialization(serialize(txJSON), prefix); | ||
} | ||
|
||
function signingHash(txJSON, isTestNet) { | ||
return hashJSON(txJSON, isTestNet ? HASH_TX_SIGN_TESTNET : HASH_TX_SIGN); | ||
} | ||
|
||
function computeSignature(txJSON, keypair) { | ||
var signature = keypair.sign(signingHash(txJSON)); | ||
return sjcl.codec.hex.fromBits(signature).toUpperCase(); | ||
} | ||
|
||
function sign(txJSON, secret) { | ||
validate.txJSON(txJSON); | ||
validate.addressAndSecret({address: txJSON.Account, secret: secret}); | ||
|
||
var keypair = getKeyPair(txJSON.Acccount, secret); | ||
if (txJSON.SigningPubKey === undefined) { | ||
txJSON.SigningPubKey = getPublicKeyHex(keypair); | ||
} | ||
txJSON.TxnSignature = computeSignature(txJSON, keypair); | ||
var serialized = serialize(txJSON); | ||
return { | ||
tx_blob: serialized.to_hex(), | ||
hash: hashSerialization(serialized, HASH_TX_ID) | ||
}; | ||
} | ||
|
||
module.exports = sign; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
'use strict'; | ||
var Request = require('ripple-lib').Request; | ||
var validate = require('./lib/validate'); | ||
|
||
function submit(tx_blob, callback) { | ||
validate.blob(tx_blob); | ||
var request = new Request(this.remote, 'submit'); | ||
request.message.tx_blob = tx_blob; | ||
request.request(callback); | ||
} | ||
|
||
module.exports = submit; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.