Examples

Initialization

1require 'arkecosystem/crypto'
2 
3transaction = ArkEcosystem::Crypto::Transactions::Builder::Transfer.new()
4 .set_recipient_id('validAddress')
5 .set_amount(1 * 10 ** 8)
6 .set_vendor_field('This is a transaction from Ruby')
7 .sign('This is a top secret passphrase')

Transactions

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.

Sign

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.

1transaction = ArkEcosystem::Crypto::Transactions::Builder::Transfer.new()
2 .set_recipient_id('validAddress')
3 .set_amount(1 * 10 ** 8)
4 .set_vendor_field('This is a transaction from Ruby')
5 .sign('This is a top secret passphrase')
6 
7print transaction.class
8 
9>>> ???

Serialize (AIP11)

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.

1serializer = ArkEcosystem::Crypto::Transactions::Serializer.new(transaction)
2 
3print serializer.class
4 
5>>> ???

Deserialize (AIP11)

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.

1deserializer = ArkEcosystem::Crypto::Transactions::Deserializer.new(serialized_transaction)
2 
3print deserializer.class
4 
5>>> ???

Message

The crypto SDK not only supports transactions but can also work with other arbitrary data (expressed as strings).

Sign

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 or passphrase.

1message = ArkEcosystem::Crypto::Utils::Message.sign('Hello World', 'this is a top secret passphrase')
2 
3print message.class
4 
5>>> ???

Verify

A message’s signature can easily be verified by hash, without the private key that signed the message, by using the verify method.

1message = ArkEcosystem::Crypto::Utils::Message.new(
2 publickey: 'validPublicKey',
3 signature: 'validSignature',
4 message: 'Hello World'
5)
6 
7print message.class
8 
9>>> ???

Identities

The identities class allows for the creation and inspection of keyPairs from passphrases. Here you find vital functions when creating transactions and managing wallets.

Derive the Address from a Passphrase

1address = ArkEcosystem::Crypto::Identities::Address.from_passphrase('this is a top secret passphrase')
2 
3print address.class
4 
5>>> ???

Derive the Address from a Public Key

1address = ArkEcosystem::Crypto::Identities::Address.from_public_key('validPublicKey')
2 
3print address.class
4 
5>>> ???

Derive the Address from a Private Key

1address = ArkEcosystem::Crypto::Identities::Address.from_private_key('validPrivateKey')
2 
3print address.class
4 
5>>> ???

Validate an Address

1address = ArkEcosystem::Crypto::Identities::Address.validate('validAddress')
2 
3print address.class
4 
5>>> ???

Private Key

As the name implies, private keys and passphrases are to remain private. Never store these unencrypted and minimize access to these secrets

Derive the Private Key from a Passphrase

1privateKey = ArkEcosystem::Crypto::Identities::PrivateKey.from_passphrase('this is a top secret passphrase')
2 
3print privateKey.class
4 
5>>> ???

Derive the Private Key Instance Object from a Hexadecimal Encoded String

1privateKey = ArkEcosystem::Crypto::Identities::PrivateKey.from_hex('validHexString')
2 
3print privateKey.class
4 
5>>> ???

Derive the Private Key from a WIF

1This function has not been implemented in this client library.

Public Key

Public Keys may be freely shared, and are included in transaction objects to validate the authenticity.

Derive the Public Key from a Passphrase

1publicKey = ArkEcosystem::Crypto::Identities::PublicKey.from_passphrase('this is a top secret passphrase')
2 
3print publicKey.class
4 
5>>> ???

Derive the Public Key Instance Object from a Hexadecimal Encoded String

1publicKey = ArkEcosystem::Crypto::Identities::PublicKey.from_hex('validHexString')
2 
3print publicKey.class
4 
5>>> ???

Validate a Public Key

1This function has not been implemented in this client library.

WIF

The WIF should remain secret, just like your passphrase and private key.

Derive the WIF from a Passphrase

1wif = ArkEcosystem::Crypto::Identities::WIF.from_passphrase('this is a top secret passphrase')
2 
3print wif.class
4 
5>>> ???
Last updated 2 years ago
Edit Page
Share: