auction-ruby-base 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/.travis.yml +15 -0
- data/.yardopts +8 -0
- data/CHANGELOG.md +58 -0
- data/CONTRIBUTING.md +48 -0
- data/Gemfile +15 -0
- data/Guardfile +5 -0
- data/LICENSE.txt +202 -0
- data/README.md +83 -0
- data/Rakefile +4 -0
- data/auction-ruby-base.gemspec +35 -0
- data/examples/create_account.rb +26 -0
- data/examples/low_level_transaction_post.rb +46 -0
- data/examples/mid_level_transaction_post.rb +33 -0
- data/examples/non_native_payment.rb +60 -0
- data/examples/offer.rb +75 -0
- data/examples/transaction_merge.rb +23 -0
- data/generated/stellar-base-generated.rb +174 -0
- data/generated/stellar/account_entry.rb +55 -0
- data/generated/stellar/account_entry/ext.rb +24 -0
- data/generated/stellar/account_flags.rb +31 -0
- data/generated/stellar/account_merge_result.rb +26 -0
- data/generated/stellar/account_merge_result_code.rb +30 -0
- data/generated/stellar/affirm_fail_op.rb +22 -0
- data/generated/stellar/affirm_fail_result.rb +25 -0
- data/generated/stellar/affirm_fail_result_code.rb +22 -0
- data/generated/stellar/affirm_pass_op.rb +24 -0
- data/generated/stellar/affirm_pass_result.rb +25 -0
- data/generated/stellar/affirm_pass_result_code.rb +22 -0
- data/generated/stellar/allow_trust_op.rb +38 -0
- data/generated/stellar/allow_trust_op/asset.rb +33 -0
- data/generated/stellar/allow_trust_result.rb +25 -0
- data/generated/stellar/allow_trust_result_code.rb +31 -0
- data/generated/stellar/asset.rb +47 -0
- data/generated/stellar/asset/alpha_num12.rb +22 -0
- data/generated/stellar/asset/alpha_num4.rb +22 -0
- data/generated/stellar/asset_type.rb +24 -0
- data/generated/stellar/auth.rb +20 -0
- data/generated/stellar/auth_cert.rb +22 -0
- data/generated/stellar/authenticated_message.rb +32 -0
- data/generated/stellar/authenticated_message/v0.rb +24 -0
- data/generated/stellar/bucket_entry.rb +28 -0
- data/generated/stellar/bucket_entry_type.rb +22 -0
- data/generated/stellar/change_trust_op.rb +22 -0
- data/generated/stellar/change_trust_result.rb +25 -0
- data/generated/stellar/change_trust_result_code.rb +31 -0
- data/generated/stellar/claim_offer_atom.rb +33 -0
- data/generated/stellar/create_account_op.rb +20 -0
- data/generated/stellar/create_account_result.rb +25 -0
- data/generated/stellar/create_account_result_code.rb +32 -0
- data/generated/stellar/create_bid_op.rb +20 -0
- data/generated/stellar/create_bid_result.rb +25 -0
- data/generated/stellar/create_bid_result_code.rb +22 -0
- data/generated/stellar/create_lot_op.rb +46 -0
- data/generated/stellar/create_lot_result.rb +25 -0
- data/generated/stellar/create_lot_result_code.rb +22 -0
- data/generated/stellar/create_passive_offer_op.rb +24 -0
- data/generated/stellar/crypto_key_type.rb +20 -0
- data/generated/stellar/curve25519_public.rb +18 -0
- data/generated/stellar/curve25519_secret.rb +18 -0
- data/generated/stellar/decorated_signature.rb +20 -0
- data/generated/stellar/dont_have.rb +20 -0
- data/generated/stellar/envelope_type.rb +24 -0
- data/generated/stellar/error.rb +20 -0
- data/generated/stellar/error_code.rb +28 -0
- data/generated/stellar/hello.rb +34 -0
- data/generated/stellar/hmac_sha256_key.rb +18 -0
- data/generated/stellar/hmac_sha256_mac.rb +18 -0
- data/generated/stellar/inflation_payout.rb +20 -0
- data/generated/stellar/inflation_result.rb +26 -0
- data/generated/stellar/inflation_result_code.rb +24 -0
- data/generated/stellar/ip_addr_type.rb +22 -0
- data/generated/stellar/ledger_entry.rb +52 -0
- data/generated/stellar/ledger_entry/data.rb +49 -0
- data/generated/stellar/ledger_entry/ext.rb +24 -0
- data/generated/stellar/ledger_entry_change.rb +35 -0
- data/generated/stellar/ledger_entry_change_type.rb +26 -0
- data/generated/stellar/ledger_entry_type.rb +32 -0
- data/generated/stellar/ledger_header.rb +69 -0
- data/generated/stellar/ledger_header/ext.rb +24 -0
- data/generated/stellar/ledger_header_history_entry.rb +33 -0
- data/generated/stellar/ledger_header_history_entry/ext.rb +24 -0
- data/generated/stellar/ledger_key.rb +87 -0
- data/generated/stellar/ledger_key/account.rb +20 -0
- data/generated/stellar/ledger_key/lot.rb +22 -0
- data/generated/stellar/ledger_key/message.rb +22 -0
- data/generated/stellar/ledger_key/offer.rb +22 -0
- data/generated/stellar/ledger_key/participant.rb +22 -0
- data/generated/stellar/ledger_key/proof.rb +22 -0
- data/generated/stellar/ledger_key/trust_line.rb +22 -0
- data/generated/stellar/ledger_scp_messages.rb +20 -0
- data/generated/stellar/ledger_upgrade.rb +31 -0
- data/generated/stellar/ledger_upgrade_type.rb +24 -0
- data/generated/stellar/lot_branch.rb +21 -0
- data/generated/stellar/lot_entry.rb +64 -0
- data/generated/stellar/lot_entry/ext.rb +24 -0
- data/generated/stellar/lot_type.rb +21 -0
- data/generated/stellar/manage_offer_effect.rb +24 -0
- data/generated/stellar/manage_offer_op.rb +28 -0
- data/generated/stellar/manage_offer_result.rb +26 -0
- data/generated/stellar/manage_offer_result_code.rb +50 -0
- data/generated/stellar/manage_offer_success_result.rb +34 -0
- data/generated/stellar/manage_offer_success_result/offer.rb +30 -0
- data/generated/stellar/memo.rb +38 -0
- data/generated/stellar/memo_type.rb +28 -0
- data/generated/stellar/message_entry.rb +38 -0
- data/generated/stellar/message_entry/ext.rb +24 -0
- data/generated/stellar/message_type.rb +51 -0
- data/generated/stellar/offer_entry.rb +49 -0
- data/generated/stellar/offer_entry/ext.rb +24 -0
- data/generated/stellar/offer_entry_flags.rb +21 -0
- data/generated/stellar/operation.rb +65 -0
- data/generated/stellar/operation/body.rb +88 -0
- data/generated/stellar/operation_meta.rb +18 -0
- data/generated/stellar/operation_result.rb +67 -0
- data/generated/stellar/operation_result/tr.rb +89 -0
- data/generated/stellar/operation_result_code.rb +25 -0
- data/generated/stellar/operation_type.rb +52 -0
- data/generated/stellar/participant_entry.rb +39 -0
- data/generated/stellar/participant_entry/ext.rb +24 -0
- data/generated/stellar/participant_state.rb +25 -0
- data/generated/stellar/path_payment_op.rb +32 -0
- data/generated/stellar/path_payment_result.rb +38 -0
- data/generated/stellar/path_payment_result/success.rb +22 -0
- data/generated/stellar/path_payment_result_code.rb +47 -0
- data/generated/stellar/payment_op.rb +22 -0
- data/generated/stellar/payment_result.rb +25 -0
- data/generated/stellar/payment_result_code.rb +41 -0
- data/generated/stellar/peer_address.rb +33 -0
- data/generated/stellar/peer_address/ip.rb +29 -0
- data/generated/stellar/price.rb +20 -0
- data/generated/stellar/proof_entry.rb +42 -0
- data/generated/stellar/proof_entry/ext.rb +24 -0
- data/generated/stellar/provide_proof_op.rb +24 -0
- data/generated/stellar/provide_proof_result.rb +25 -0
- data/generated/stellar/provide_proof_result_code.rb +22 -0
- data/generated/stellar/public_key.rb +23 -0
- data/generated/stellar/register_participant_op.rb +22 -0
- data/generated/stellar/register_participant_result.rb +25 -0
- data/generated/stellar/register_participant_result_code.rb +22 -0
- data/generated/stellar/scp_ballot.rb +20 -0
- data/generated/stellar/scp_envelope.rb +20 -0
- data/generated/stellar/scp_history_entry.rb +23 -0
- data/generated/stellar/scp_history_entry_v0.rb +20 -0
- data/generated/stellar/scp_nomination.rb +22 -0
- data/generated/stellar/scp_quorum_set.rb +22 -0
- data/generated/stellar/scp_statement.rb +58 -0
- data/generated/stellar/scp_statement/pledges.rb +63 -0
- data/generated/stellar/scp_statement/pledges/confirm.rb +30 -0
- data/generated/stellar/scp_statement/pledges/externalize.rb +26 -0
- data/generated/stellar/scp_statement/pledges/prepare.rb +32 -0
- data/generated/stellar/scp_statement_type.rb +26 -0
- data/generated/stellar/send_message_op.rb +22 -0
- data/generated/stellar/send_message_result.rb +25 -0
- data/generated/stellar/send_message_result_code.rb +22 -0
- data/generated/stellar/set_options_op.rb +41 -0
- data/generated/stellar/set_options_result.rb +25 -0
- data/generated/stellar/set_options_result_code.rb +40 -0
- data/generated/stellar/signer.rb +20 -0
- data/generated/stellar/simple_payment_result.rb +22 -0
- data/generated/stellar/stellar_message.rb +74 -0
- data/generated/stellar/stellar_value.rb +41 -0
- data/generated/stellar/stellar_value/ext.rb +24 -0
- data/generated/stellar/threshold_indexes.rb +26 -0
- data/generated/stellar/time_bounds.rb +20 -0
- data/generated/stellar/transaction.rb +50 -0
- data/generated/stellar/transaction/ext.rb +24 -0
- data/generated/stellar/transaction_envelope.rb +20 -0
- data/generated/stellar/transaction_history_entry.rb +33 -0
- data/generated/stellar/transaction_history_entry/ext.rb +24 -0
- data/generated/stellar/transaction_history_result_entry.rb +33 -0
- data/generated/stellar/transaction_history_result_entry/ext.rb +24 -0
- data/generated/stellar/transaction_meta.rb +23 -0
- data/generated/stellar/transaction_result.rb +43 -0
- data/generated/stellar/transaction_result/ext.rb +24 -0
- data/generated/stellar/transaction_result/result.rb +30 -0
- data/generated/stellar/transaction_result_code.rb +45 -0
- data/generated/stellar/transaction_result_pair.rb +20 -0
- data/generated/stellar/transaction_result_set.rb +18 -0
- data/generated/stellar/transaction_set.rb +20 -0
- data/generated/stellar/trust_line_entry.rb +41 -0
- data/generated/stellar/trust_line_entry/ext.rb +24 -0
- data/generated/stellar/trust_line_flags.rb +21 -0
- data/lib/stellar-base.rb +33 -0
- data/lib/stellar/account_flags.rb +28 -0
- data/lib/stellar/asset.rb +69 -0
- data/lib/stellar/base.rb +1 -0
- data/lib/stellar/base/version.rb +5 -0
- data/lib/stellar/convert.rb +32 -0
- data/lib/stellar/key_pair.rb +112 -0
- data/lib/stellar/networks.rb +45 -0
- data/lib/stellar/operation.rb +384 -0
- data/lib/stellar/path_payment_result.rb +17 -0
- data/lib/stellar/price.rb +32 -0
- data/lib/stellar/thresholds.rb +39 -0
- data/lib/stellar/transaction.rb +205 -0
- data/lib/stellar/transaction_envelope.rb +32 -0
- data/lib/stellar/util/continued_fraction.rb +96 -0
- data/lib/stellar/util/strkey.rb +43 -0
- data/spec/lib/stellar/account_flags_spec.rb +19 -0
- data/spec/lib/stellar/asset_spec.rb +45 -0
- data/spec/lib/stellar/convert_spec.rb +61 -0
- data/spec/lib/stellar/key_pair_spec.rb +238 -0
- data/spec/lib/stellar/networks_spec.rb +77 -0
- data/spec/lib/stellar/operation_spec.rb +13 -0
- data/spec/lib/stellar/path_payment_result_spec.rb +95 -0
- data/spec/lib/stellar/price_spec.rb +34 -0
- data/spec/lib/stellar/thresholds_spec.rb +62 -0
- data/spec/lib/stellar/transaction_envelope_spec.rb +93 -0
- data/spec/lib/stellar/transaction_spec.rb +83 -0
- data/spec/lib/stellar/util/strkey_spec.rb +46 -0
- data/spec/spec_helper.rb +16 -0
- data/spec/support/matchers/be_strkey.rb +9 -0
- data/spec/support/matchers/eq_bytes.rb +5 -0
- data/spec/support/matchers/have_length.rb +5 -0
- data/tasks/rspec.rake +6 -0
- data/tasks/travis.rake +1 -0
- data/tasks/xdr.rake +50 -0
- data/xdr/Stellar-SCP.x +86 -0
- data/xdr/Stellar-ledger-entries.x +351 -0
- data/xdr/Stellar-ledger.x +288 -0
- data/xdr/Stellar-overlay.x +146 -0
- data/xdr/Stellar-transaction.x +936 -0
- data/xdr/Stellar-types.x +55 -0
- metadata +495 -0
@@ -0,0 +1,20 @@
|
|
1
|
+
# This code was automatically generated using xdrgen
|
2
|
+
# DO NOT EDIT or your changes may be overwritten
|
3
|
+
|
4
|
+
require 'xdr'
|
5
|
+
|
6
|
+
# === xdr source ============================================================
|
7
|
+
#
|
8
|
+
# struct TransactionResultPair
|
9
|
+
# {
|
10
|
+
# Hash transactionHash;
|
11
|
+
# TransactionResult result; // result for the transaction
|
12
|
+
# };
|
13
|
+
#
|
14
|
+
# ===========================================================================
|
15
|
+
module Stellar
|
16
|
+
class TransactionResultPair < XDR::Struct
|
17
|
+
attribute :transaction_hash, Hash
|
18
|
+
attribute :result, TransactionResult
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# This code was automatically generated using xdrgen
|
2
|
+
# DO NOT EDIT or your changes may be overwritten
|
3
|
+
|
4
|
+
require 'xdr'
|
5
|
+
|
6
|
+
# === xdr source ============================================================
|
7
|
+
#
|
8
|
+
# struct TransactionResultSet
|
9
|
+
# {
|
10
|
+
# TransactionResultPair results<MAX_TX_PER_LEDGER>;
|
11
|
+
# };
|
12
|
+
#
|
13
|
+
# ===========================================================================
|
14
|
+
module Stellar
|
15
|
+
class TransactionResultSet < XDR::Struct
|
16
|
+
attribute :results, XDR::VarArray[TransactionResultPair, MAX_TX_PER_LEDGER]
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# This code was automatically generated using xdrgen
|
2
|
+
# DO NOT EDIT or your changes may be overwritten
|
3
|
+
|
4
|
+
require 'xdr'
|
5
|
+
|
6
|
+
# === xdr source ============================================================
|
7
|
+
#
|
8
|
+
# struct TransactionSet
|
9
|
+
# {
|
10
|
+
# Hash previousLedgerHash;
|
11
|
+
# TransactionEnvelope txs<MAX_TX_PER_LEDGER>;
|
12
|
+
# };
|
13
|
+
#
|
14
|
+
# ===========================================================================
|
15
|
+
module Stellar
|
16
|
+
class TransactionSet < XDR::Struct
|
17
|
+
attribute :previous_ledger_hash, Hash
|
18
|
+
attribute :txs, XDR::VarArray[TransactionEnvelope, MAX_TX_PER_LEDGER]
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# This code was automatically generated using xdrgen
|
2
|
+
# DO NOT EDIT or your changes may be overwritten
|
3
|
+
|
4
|
+
require 'xdr'
|
5
|
+
|
6
|
+
# === xdr source ============================================================
|
7
|
+
#
|
8
|
+
# struct TrustLineEntry
|
9
|
+
# {
|
10
|
+
# AccountID accountID; // account this trustline belongs to
|
11
|
+
# Asset asset; // type of asset (with issuer)
|
12
|
+
# int64 balance; // how much of this asset the user has.
|
13
|
+
# // Asset defines the unit for this;
|
14
|
+
#
|
15
|
+
# int64 limit; // balance cannot be above this
|
16
|
+
# uint32 flags; // see TrustLineFlags
|
17
|
+
#
|
18
|
+
# // reserved for future use
|
19
|
+
# union switch (int v)
|
20
|
+
# {
|
21
|
+
# case 0:
|
22
|
+
# void;
|
23
|
+
# }
|
24
|
+
# ext;
|
25
|
+
# };
|
26
|
+
#
|
27
|
+
# ===========================================================================
|
28
|
+
module Stellar
|
29
|
+
class TrustLineEntry < XDR::Struct
|
30
|
+
include XDR::Namespace
|
31
|
+
|
32
|
+
autoload :Ext
|
33
|
+
|
34
|
+
attribute :account_id, AccountID
|
35
|
+
attribute :asset, Asset
|
36
|
+
attribute :balance, Int64
|
37
|
+
attribute :limit, Int64
|
38
|
+
attribute :flags, Uint32
|
39
|
+
attribute :ext, Ext
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# This code was automatically generated using xdrgen
|
2
|
+
# DO NOT EDIT or your changes may be overwritten
|
3
|
+
|
4
|
+
require 'xdr'
|
5
|
+
|
6
|
+
# === xdr source ============================================================
|
7
|
+
#
|
8
|
+
# union switch (int v)
|
9
|
+
# {
|
10
|
+
# case 0:
|
11
|
+
# void;
|
12
|
+
# }
|
13
|
+
#
|
14
|
+
# ===========================================================================
|
15
|
+
module Stellar
|
16
|
+
class TrustLineEntry
|
17
|
+
class Ext < XDR::Union
|
18
|
+
switch_on XDR::Int, :v
|
19
|
+
|
20
|
+
switch 0
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# This code was automatically generated using xdrgen
|
2
|
+
# DO NOT EDIT or your changes may be overwritten
|
3
|
+
|
4
|
+
require 'xdr'
|
5
|
+
|
6
|
+
# === xdr source ============================================================
|
7
|
+
#
|
8
|
+
# enum TrustLineFlags
|
9
|
+
# {
|
10
|
+
# // issuer has authorized account to perform transactions with its credit
|
11
|
+
# AUTHORIZED_FLAG = 1
|
12
|
+
# };
|
13
|
+
#
|
14
|
+
# ===========================================================================
|
15
|
+
module Stellar
|
16
|
+
class TrustLineFlags < XDR::Enum
|
17
|
+
member :authorized_flag, 1
|
18
|
+
|
19
|
+
seal
|
20
|
+
end
|
21
|
+
end
|
data/lib/stellar-base.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'xdr'
|
2
|
+
require 'rbnacl/libsodium'
|
3
|
+
require 'digest/sha2'
|
4
|
+
require 'active_support/core_ext/object/blank'
|
5
|
+
require 'active_support/core_ext/enumerable'
|
6
|
+
require 'active_support/core_ext/kernel/reporting'
|
7
|
+
|
8
|
+
# See ../generated for code-gen'ed files
|
9
|
+
|
10
|
+
silence_warnings do
|
11
|
+
require 'stellar-base-generated'
|
12
|
+
end
|
13
|
+
Stellar.load_all!
|
14
|
+
|
15
|
+
Stellar::ONE = 1_0000000
|
16
|
+
|
17
|
+
|
18
|
+
# extensions onto the generated files must be loaded manually, below
|
19
|
+
|
20
|
+
require_relative './stellar/account_flags'
|
21
|
+
require_relative './stellar/asset'
|
22
|
+
require_relative './stellar/key_pair'
|
23
|
+
require_relative './stellar/operation'
|
24
|
+
require_relative './stellar/path_payment_result'
|
25
|
+
require_relative './stellar/price'
|
26
|
+
require_relative './stellar/thresholds'
|
27
|
+
require_relative './stellar/transaction'
|
28
|
+
require_relative './stellar/transaction_envelope'
|
29
|
+
require_relative './stellar/util/strkey'
|
30
|
+
require_relative './stellar/util/continued_fraction'
|
31
|
+
require_relative './stellar/convert'
|
32
|
+
require_relative './stellar/networks'
|
33
|
+
require_relative './stellar/base/version'
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Stellar
|
2
|
+
class AccountFlags
|
3
|
+
|
4
|
+
|
5
|
+
#
|
6
|
+
# Converts an array of Stellar::AccountFlags members into
|
7
|
+
# an Integer suitable for use in a SetOptionsOp.
|
8
|
+
#
|
9
|
+
# @param flags=nil [Array<Stellar::AccountFlags>] the flags to combine
|
10
|
+
#
|
11
|
+
# @return [Fixnum] the combined result
|
12
|
+
def self.make_mask(flags=nil)
|
13
|
+
flags ||= []
|
14
|
+
|
15
|
+
flags.map(&:value).inject(&:|) || 0
|
16
|
+
end
|
17
|
+
|
18
|
+
#
|
19
|
+
# Converts an integer used in SetOptionsOp on the set/clear flag options
|
20
|
+
# into an array of Stellar::AccountFlags members
|
21
|
+
#
|
22
|
+
# @param combined [Fixnum]
|
23
|
+
# @return [Array<Stellar::AccountFlags>]
|
24
|
+
def self.parse_mask(combined)
|
25
|
+
members.values.select{|m| (m.value & combined) != 0}
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module Stellar
|
2
|
+
class Asset
|
3
|
+
def self.native
|
4
|
+
new(:asset_type_native)
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.alphanum4(code, issuer)
|
8
|
+
raise ArgumentError, "Bad :issuer" unless issuer.is_a?(KeyPair)
|
9
|
+
code = normalize_code(code, 4)
|
10
|
+
an = AlphaNum4.new({asset_code:code, issuer:issuer.account_id})
|
11
|
+
new(:asset_type_credit_alphanum4, an)
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.alphanum12(code, issuer)
|
15
|
+
raise ArgumentError, "Bad :issuer" unless issuer.is_a?(KeyPair)
|
16
|
+
code = normalize_code(code, 12)
|
17
|
+
an = AlphaNum12.new({asset_code:code, issuer:issuer.account_id})
|
18
|
+
new(:asset_type_credit_alphanum12, an)
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_s
|
22
|
+
case switch
|
23
|
+
when AssetType.asset_type_native
|
24
|
+
"native"
|
25
|
+
when AssetType.asset_type_credit_alphanum4
|
26
|
+
anum = alpha_num4!
|
27
|
+
issuer_address = Stellar::Convert.pk_to_address(anum.issuer)
|
28
|
+
"#{anum.asset_code}/#{issuer_address}"
|
29
|
+
when AssetType.asset_type_credit_alphanum12
|
30
|
+
anum = alpha_num12!
|
31
|
+
issuer_address = Stellar::Convert.pk_to_address(anum.issuer)
|
32
|
+
"#{anum.asset_code}/#{issuer_address}"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def inspect
|
37
|
+
label = switch.to_s
|
38
|
+
"#<Stellar::Asset #{to_s}>"
|
39
|
+
end
|
40
|
+
|
41
|
+
def code
|
42
|
+
case switch
|
43
|
+
when AssetType.asset_type_credit_alphanum4
|
44
|
+
alpha_num4!.asset_code
|
45
|
+
when AssetType.asset_type_credit_alphanum12
|
46
|
+
alpha_num12!.asset_code
|
47
|
+
else
|
48
|
+
raise "#{switch} assets do not have a code"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def issuer
|
53
|
+
case switch
|
54
|
+
when AssetType.asset_type_credit_alphanum4
|
55
|
+
alpha_num4!.issuer
|
56
|
+
when AssetType.asset_type_credit_alphanum12
|
57
|
+
alpha_num12!.issuer
|
58
|
+
else
|
59
|
+
raise "#{switch} assets do not have a isuuer"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def self.normalize_code(code, length)
|
64
|
+
raise ArgumentError, "Invalid asset code: #{code}, must be <= #{length} bytes" if code.length > length
|
65
|
+
|
66
|
+
code.ljust(length, "\x00")
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
data/lib/stellar/base.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "stellar-base"
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Stellar
|
2
|
+
#
|
3
|
+
# Generic format conversion module
|
4
|
+
#
|
5
|
+
module Convert
|
6
|
+
require 'base64'
|
7
|
+
|
8
|
+
def to_hex(string)
|
9
|
+
string.unpack("H*").first
|
10
|
+
end
|
11
|
+
|
12
|
+
def from_hex(hex_string)
|
13
|
+
[hex_string].pack("H*")
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_base64(string)
|
17
|
+
Base64.strict_encode64(string)
|
18
|
+
end
|
19
|
+
|
20
|
+
def from_base64(base64_string)
|
21
|
+
Base64.strict_decode64(base64_string)
|
22
|
+
end
|
23
|
+
|
24
|
+
## Converts a Stellar::PublicKey instance (or any typedef of it such as
|
25
|
+
# Stellar::AccountID) to an address
|
26
|
+
def pk_to_address(pk)
|
27
|
+
Stellar::Util::StrKey.check_encode(:account_id, pk.ed25519!)
|
28
|
+
end
|
29
|
+
|
30
|
+
extend self
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
module Stellar
|
2
|
+
class KeyPair
|
3
|
+
def self.from_seed(seed)
|
4
|
+
seed_bytes = Util::StrKey.check_decode(:seed, seed)
|
5
|
+
from_raw_seed seed_bytes
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.from_raw_seed(seed_bytes)
|
9
|
+
secret_key = RbNaCl::SigningKey.new(seed_bytes)
|
10
|
+
public_key = secret_key.verify_key
|
11
|
+
new(public_key, secret_key)
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.from_public_key(pk_bytes)
|
15
|
+
public_key = RbNaCl::VerifyKey.new(pk_bytes)
|
16
|
+
new(public_key)
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.from_address(address)
|
20
|
+
pk_bytes = Util::StrKey.check_decode(:account_id, address)
|
21
|
+
from_public_key(pk_bytes)
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.random
|
25
|
+
secret_key = RbNaCl::SigningKey.generate
|
26
|
+
public_key = secret_key.verify_key
|
27
|
+
new(public_key, secret_key)
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.from_network_passphrase(passphrase)
|
31
|
+
network_id = Digest::SHA256.digest(passphrase)
|
32
|
+
from_raw_seed network_id
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.master
|
36
|
+
from_raw_seed(Stellar.current_network_id)
|
37
|
+
end
|
38
|
+
|
39
|
+
def initialize(public_key, secret_key=nil)
|
40
|
+
@public_key = public_key
|
41
|
+
@secret_key = secret_key
|
42
|
+
end
|
43
|
+
|
44
|
+
def account_id
|
45
|
+
Stellar::AccountID.new :key_type_ed25519, raw_public_key
|
46
|
+
end
|
47
|
+
|
48
|
+
def public_key
|
49
|
+
Stellar::PublicKey.new :key_type_ed25519, raw_public_key
|
50
|
+
end
|
51
|
+
|
52
|
+
def raw_public_key
|
53
|
+
@public_key.to_bytes
|
54
|
+
end
|
55
|
+
|
56
|
+
def signature_hint
|
57
|
+
# take last 4 bytes
|
58
|
+
account_id.to_xdr.slice(-4, 4)
|
59
|
+
end
|
60
|
+
|
61
|
+
def raw_seed
|
62
|
+
@secret_key.to_bytes
|
63
|
+
end
|
64
|
+
|
65
|
+
def rbnacl_signing_key
|
66
|
+
@secret_key
|
67
|
+
end
|
68
|
+
|
69
|
+
def rbnacl_verify_key
|
70
|
+
@public_key
|
71
|
+
end
|
72
|
+
|
73
|
+
def address
|
74
|
+
pk_bytes = raw_public_key
|
75
|
+
Util::StrKey.check_encode(:account_id, pk_bytes)
|
76
|
+
end
|
77
|
+
|
78
|
+
def seed
|
79
|
+
raise "no private key" if @secret_key.nil?
|
80
|
+
#TODO: improve the error class above
|
81
|
+
seed_bytes = raw_seed
|
82
|
+
encoder = Util::StrKey.check_encode(:seed, seed_bytes)
|
83
|
+
end
|
84
|
+
|
85
|
+
def sign?
|
86
|
+
!@secret_key.nil?
|
87
|
+
end
|
88
|
+
|
89
|
+
def sign(message)
|
90
|
+
raise "no private key" if @secret_key.nil?
|
91
|
+
#TODO: improve the error class above
|
92
|
+
@secret_key.sign(message)
|
93
|
+
end
|
94
|
+
|
95
|
+
def sign_decorated(message)
|
96
|
+
raw_signature = sign(message)
|
97
|
+
Stellar::DecoratedSignature.new({
|
98
|
+
hint: signature_hint,
|
99
|
+
signature: raw_signature
|
100
|
+
})
|
101
|
+
end
|
102
|
+
|
103
|
+
def verify(signature, message)
|
104
|
+
@public_key.verify(signature, message)
|
105
|
+
rescue RbNaCl::LengthError
|
106
|
+
false
|
107
|
+
rescue RbNaCl::BadSignatureError
|
108
|
+
false
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
end
|