id | title |
---|---|
examples |
Examples |
require 'arkecosystem/crypto'
transaction = ARKEcosystem::Crypto::Transactions::Builder::Transfer.new()
.set_recipient_id('validAddress')
.set_amount(1 * 10 ** 8)
.set_vendor_field('This is a transaction from Ruby')
.sign('This is a top secret passphrase')
A transaction is an object specifying the transfer of funds from the sender's wallet to the recipient's. Each transaction must be signed by the sender's private key to prove authenticity and origin. After broadcasting through the client SDK, a transaction is permanently incorporated in the blockchain by a Delegate Node.
The crypto SDK can sign a transaction using your private key or passphrase (from which the private key is generated). Ensure you are familiar with digital signatures before using the crypto SDKs.
transaction = ARKEcosystem::Crypto::Transactions::Builder::Transfer.new()
.set_recipient_id('validAddres')
.set_amount(1 * 10 ** 8)
.set_vendor_field('This is a transaction from Ruby')
.sign('This is a top secret passphrase')
print transaction.class
>>> ???
Serialization of a transaction object ensures it is compact and properly formatted to be incorporated in the ARK blockchain. If you are using the crypto SDK in combination with the public API SDK, you should not need to serialize manually.
serializer = ARKEcosystem::Crypto::Transactions::Serializer.new(transaction)
print serializer.class
>>> ???
A serialized transaction may be deserialized for inspection purposes. The public API does not return serialized transactions, so you should only need to deserialize in exceptional circumstances.
deserializer = ARKEcosystem::Crypto::Transactions::Deserializer.new(serialized_transaction)
print deserializer.class
>>> ???
The crypto SDK not only supports transactions but can also work with other arbitrary data (expressed as strings).
Signing a string works much like signing a transaction: in most implementations, the message is hashed, and the resulting hash is signed using the
private key
orpassphrase
.
message = ARKEcosystem::Crypto::Utils::Message.sign('Hello World', 'this is a top secret passphrase')
print message.class
>>> ???
A message's signature can easily be verified by hash, without the private key that signed the message, by using the
verify
method.
message = ARKEcosystem::Crypto::Utils::Message.new(
publickey: 'validPublicKey',
signature: 'validSignature',
message: 'Hello World'
)
print message.class
>>> ???
The identities class allows for the creation and inspection of keypairs from
passphrases
. Here you find vital functions when creating transactions and managing wallets.
address = ARKEcosystem::Crypto::Identities::Address.from_passphrase('this is a top secret passphrase')
print address.class
>>> ???
address = ARKEcosystem::Crypto::Identities::Address.from_public_key('validPublicKey')
print address.class
>>> ???
address = ARKEcosystem::Crypto::Identities::Address.from_private_key('validPrivateKey')
print address.class
>>> ???
address = ARKEcosystem::Crypto::Identities::Address.validate('validAddress')
print address.class
>>> ???
As the name implies, private keys and passphrases are to remain private. Never store these unencrypted and minimize access to these secrets
privateKey = ARKEcosystem::Crypto::Identities::PrivateKey.from_passphrase('this is a top secret passphrase')
print privateKey.class
>>> ???
privateKey = ARKEcosystem::Crypto::Identities::PrivateKey.from_hex('validHexString')
print privateKey.class
>>> ???
This function has not been implemented in this client library.
Public Keys may be freely shared, and are included in transaction objects to validate the authenticity.
publicKey = ARKEcosystem::Crypto::Identities::PublicKey.from_passphrase('this is a top secret passphrase')
print publicKey.class
>>> ???
publicKey = ARKEcosystem::Crypto::Identities::PublicKey.from_hex('validHexString')
print publicKey.class
>>> ???
This function has not been implemented in this client library.
The WIF should remain secret, just like your
passphrase
andprivate key
.
wif = ARKEcosystem::Crypto::Identities::WIF.from_passphrase('this is a top secret passphrase')
print wif.class
>>> ???