solana-ruby-web3js 2.1.4 → 2.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3022773f90f2e77d77ba86ab5a6e97d5d4420895ae981c74d57c6bceab87ad86
|
4
|
+
data.tar.gz: e42e19e6ac071cf7774d601c7b4807beba88e8fcc84d54718ae4d58c6846afdc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 64ca7a6a80bb656f421fbe95b8590f33f0428b8b1d85abf2b9bd521764b15da424a3dec4859df0cd3ef8f700ef48493204d746d2de658e7dfbd143487e11ecc2
|
7
|
+
data.tar.gz: dc0d28baf4b451798c379a01a8931e7033ccf9ce99b291d4619572469a620ec572f988467c833613d654f709a03ba1310d21254f3472b665333ffc40359df651
|
@@ -1,70 +1,36 @@
|
|
1
1
|
module SolanaRuby
|
2
2
|
class Ed25519CurveChecker
|
3
|
-
|
4
|
-
|
5
|
-
ONE = 1
|
3
|
+
require 'rbnacl'
|
4
|
+
require 'openssl'
|
6
5
|
|
7
|
-
#
|
8
|
-
|
9
|
-
|
10
|
-
return false unless public_key_bytes.bytesize == 32 # Public key must be 32 bytes
|
6
|
+
# Constants for the Ed25519 curve
|
7
|
+
Q = 2**255 - 19
|
8
|
+
D = -121665 * OpenSSL::BN.new(121666).mod_inverse(Q).to_i % Q # Ed25519 constant
|
11
9
|
|
12
|
-
|
13
|
-
|
14
|
-
y = decode_y(public_key_bytes)
|
10
|
+
def self.on_curve?(public_key)
|
11
|
+
return false unless public_key.bytesize == 32 # Must be exactly 32 bytes
|
15
12
|
|
16
|
-
|
17
|
-
|
18
|
-
numerator = (y_squared - 1) % P
|
19
|
-
denominator = (D * y_squared + 1) % P
|
13
|
+
# Extract y-coordinate from the public key
|
14
|
+
y = public_key.unpack1("H*").to_i(16) % Q
|
20
15
|
|
21
|
-
|
22
|
-
|
16
|
+
# Compute x² from the Ed25519 curve equation: x² = (y² - 1) / (d * y² + 1) mod Q
|
17
|
+
numerator = (y**2 - 1) % Q
|
18
|
+
denominator = (D * y**2 + 1) % Q
|
23
19
|
|
24
|
-
|
25
|
-
|
20
|
+
# Compute the modular inverse of the denominator
|
21
|
+
denominator_inv = OpenSSL::BN.new(denominator).mod_inverse(Q).to_i rescue nil
|
22
|
+
return false if denominator_inv.nil? # If inverse doesn't exist, it's off-curve
|
26
23
|
|
27
|
-
|
28
|
-
quadratic_residue?(x_squared)
|
29
|
-
rescue StandardError => e
|
30
|
-
puts "Error during curve check: #{e.message}"
|
31
|
-
false
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
private
|
24
|
+
x_squared = (numerator * denominator_inv) % Q
|
36
25
|
|
37
|
-
|
38
|
-
|
39
|
-
# Converts byte array directly to integer and maps it onto the curve's modulus
|
40
|
-
public_key_bytes.unpack1('H*').to_i(16) % P
|
41
|
-
end
|
26
|
+
# Check if x² is a quadratic residue (i.e., has a valid square root mod Q)
|
27
|
+
legendre_symbol = OpenSSL::BN.new(x_squared).mod_exp((Q - 1) / 2, Q).to_i
|
42
28
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
# Modular inverse using the Extended Euclidean Algorithm
|
50
|
-
def self.modular_inverse(value, mod_value)
|
51
|
-
t, new_t = 0, 1
|
52
|
-
r, new_r = mod_value, value
|
53
|
-
|
54
|
-
while new_r != 0
|
55
|
-
quotient = r / new_r
|
56
|
-
t, new_t = new_t, t - quotient * new_t
|
57
|
-
r, new_r = new_r, r - quotient * new_r
|
58
|
-
end
|
59
|
-
|
60
|
-
raise ArgumentError, 'Value has no modular inverse' if r > 1
|
61
|
-
|
62
|
-
t += mod_value if t.negative?
|
63
|
-
t % mod_value
|
29
|
+
# If legendre symbol is 1, it has a square root, meaning it's ON the curve
|
30
|
+
legendre_symbol == 1
|
31
|
+
rescue StandardError => e
|
32
|
+
puts "Curve check error: #{e.message}"
|
33
|
+
false
|
64
34
|
end
|
65
35
|
end
|
66
|
-
|
67
|
-
# Calculate the Ed25519 constant D
|
68
|
-
# D = -121665 * modular_inverse(121666, P) mod P
|
69
|
-
D = (-121665 * Ed25519CurveChecker.modular_inverse(121666, Ed25519CurveChecker::P)) % Ed25519CurveChecker::P
|
70
36
|
end
|
@@ -45,7 +45,7 @@ module SolanaRuby
|
|
45
45
|
nonce = 255
|
46
46
|
loop do
|
47
47
|
# Combine the current nonce with the seeds
|
48
|
-
seeds_with_nonce = seeds + [[nonce].pack('C
|
48
|
+
seeds_with_nonce = seeds + [[nonce].pack('C')]
|
49
49
|
hashed_buffer = hash_seeds(seeds_with_nonce, program_id)
|
50
50
|
|
51
51
|
# Debugging: Log every generated address for inspection
|
data/lib/solana_ruby/version.rb
CHANGED
@@ -15,39 +15,45 @@ payer = SolanaRuby::Keypair.load_keypair('/Users/chinaputtaiahbellamkonda/.confi
|
|
15
15
|
payer_pubkey = payer[:public_key]
|
16
16
|
|
17
17
|
# Generate a sender keypair and public key
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
puts "owner
|
23
|
-
puts "owner
|
18
|
+
loop do
|
19
|
+
owner = SolanaRuby::Keypair.generate
|
20
|
+
# owner = SolanaRuby::Keypair.from_private_key("4b9a36383e12d13581c37a50c38a00d91ae0e80f3ce25de852ea61f499102a33")
|
21
|
+
owner_pubkey = owner[:public_key]
|
22
|
+
puts "owner public key: #{owner_pubkey}"
|
23
|
+
puts "owner private key: #{owner[:private_key]}"
|
24
|
+
puts "owner full private key: #{owner[:full_private_key]}"
|
24
25
|
|
25
|
-
# Airdrop some lamports to the sender's account
|
26
|
-
# lamports = 10 * 1_000_000_000
|
27
|
-
# sleep(1)
|
28
|
-
# result = client.request_airdrop(payer_pubkey, lamports)
|
29
|
-
# puts "Solana Balance #{lamports} lamports added sucessfully for the public key: #{payer_pubkey}"
|
30
|
-
# sleep(10)
|
26
|
+
# Airdrop some lamports to the sender's account
|
27
|
+
# lamports = 10 * 1_000_000_000
|
28
|
+
# sleep(1)
|
29
|
+
# result = client.request_airdrop(payer_pubkey, lamports)
|
30
|
+
# puts "Solana Balance #{lamports} lamports added sucessfully for the public key: #{payer_pubkey}"
|
31
|
+
# sleep(10)
|
31
32
|
|
32
33
|
|
33
|
-
mint_pubkey = "
|
34
|
-
program_id = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
|
35
|
-
puts "payer public key: #{payer_pubkey}"
|
34
|
+
mint_pubkey = "BPk3nqC1GsYsU5reEvzXjjBPQgWooSYbUzpBoktY2Uzh"
|
35
|
+
program_id = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
|
36
|
+
puts "payer public key: #{payer_pubkey}"
|
36
37
|
|
37
|
-
# associated_token_address = SolanaRuby::TransactionHelpers::TokenAccount.get_associated_token_address(mint_pubkey, payer_pubkey, program_id)
|
38
|
+
# associated_token_address = SolanaRuby::TransactionHelpers::TokenAccount.get_associated_token_address(mint_pubkey, payer_pubkey, program_id)
|
38
39
|
|
39
|
-
# puts "Associated Token Address: #{associated_token_address}"
|
40
|
+
# puts "Associated Token Address: #{associated_token_address}"
|
40
41
|
|
41
|
-
transaction = SolanaRuby::TransactionHelper.create_associated_token_account(payer_pubkey, mint_pubkey, owner_pubkey, recent_blockhash)
|
42
|
+
transaction = SolanaRuby::TransactionHelper.create_associated_token_account(payer_pubkey, mint_pubkey, owner_pubkey, recent_blockhash)
|
42
43
|
|
43
|
-
resp = transaction.sign([payer])
|
44
|
+
resp = transaction.sign([payer])
|
44
45
|
|
45
|
-
puts "signature: #{resp}"
|
46
|
+
puts "signature: #{resp}"
|
46
47
|
|
47
|
-
# Send the transaction
|
48
|
-
puts "Sending transaction..."
|
49
|
-
response = client.send_transaction(transaction.to_base64, { encoding: 'base64' })
|
48
|
+
# Send the transaction
|
49
|
+
puts "Sending transaction..."
|
50
|
+
response = client.send_transaction(transaction.to_base64, { encoding: 'base64' })
|
50
51
|
|
51
|
-
# Output transaction results
|
52
|
-
puts "Transaction Signature: #{response}"
|
52
|
+
# Output transaction results
|
53
|
+
puts "Transaction Signature: #{response}"
|
54
|
+
break
|
55
|
+
rescue StandardError
|
56
|
+
sleep(5)
|
57
|
+
next
|
58
|
+
end
|
53
59
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: solana-ruby-web3js
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- BuildSquad
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-03-
|
11
|
+
date: 2025-03-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: websocket-client-simple
|