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: 46de109c663619406d3793d4c55576a0001665de9c299c2ee3f7dfc2d10d34f4
4
- data.tar.gz: 2f5cbec75d552d3875b408c7476f2b4b4c2efb092a4663d66709ba8cc41e4905
3
+ metadata.gz: 3022773f90f2e77d77ba86ab5a6e97d5d4420895ae981c74d57c6bceab87ad86
4
+ data.tar.gz: e42e19e6ac071cf7774d601c7b4807beba88e8fcc84d54718ae4d58c6846afdc
5
5
  SHA512:
6
- metadata.gz: d0dff220eb7d48e540210067798d9ab36dd30636993645234ed102a723f281b00cb2eaf57ab9f09497f3093e06df2bf8716152517e710c7f88712cdd6bef0582
7
- data.tar.gz: 1a91da13eee1e2e321b28766c398d96fda74d9c7a6bd0839d2f4c69b0a7feb2be89142299fda6b71b4520955b85729eb9ee675b103bdd9d6457bee189a095d1d
6
+ metadata.gz: 64ca7a6a80bb656f421fbe95b8590f33f0428b8b1d85abf2b9bd521764b15da424a3dec4859df0cd3ef8f700ef48493204d746d2de658e7dfbd143487e11ecc2
7
+ data.tar.gz: dc0d28baf4b451798c379a01a8931e7033ccf9ce99b291d4619572469a620ec572f988467c833613d654f709a03ba1310d21254f3472b665333ffc40359df651
@@ -1,70 +1,36 @@
1
1
  module SolanaRuby
2
2
  class Ed25519CurveChecker
3
- # Constants for Ed25519
4
- P = 2**255 - 19
5
- ONE = 1
3
+ require 'rbnacl'
4
+ require 'openssl'
6
5
 
7
- # Main function to check if a public key is on the Ed25519 curve
8
- def self.on_curve?(public_key_bytes)
9
- # Validate public key length
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
- begin
13
- # Decode the y-coordinate from the public key
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
- # Validate if y is a quadratic residue on the curve equation
17
- y_squared = (y * y) % P
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
- # Ensure denominator isn't zero to avoid invalid computation
22
- return false if denominator.zero?
16
+ # Compute 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
- # Calculate x_squared = numerator * modular_inverse(denominator, P) mod P
25
- x_squared = (numerator * modular_inverse(denominator, P)) % P
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
- # Check if x_squared is a valid quadratic residue
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
- # Decode the y-coordinate from the public key
38
- def self.decode_y(public_key_bytes)
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 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
- # Determine if value is a quadratic residue modulo P
44
- def self.quadratic_residue?(value)
45
- # Quadratic residues satisfy value^((p - 1) / 2) mod P == 1
46
- value.pow((P - 1) / 2, P) == 1
47
- end
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SolanaRuby
4
- VERSION = "2.1.4"
4
+ VERSION = "2.1.5"
5
5
  end
@@ -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
- owner = SolanaRuby::Keypair.generate
19
- # owner = SolanaRuby::Keypair.from_private_key("4b9a36383e12d13581c37a50c38a00d91ae0e80f3ce25de852ea61f499102a33")
20
- owner_pubkey = owner[:public_key]
21
- puts "owner public key: #{owner_pubkey}"
22
- puts "owner private key: #{owner[:private_key]}"
23
- puts "owner full private key: #{owner[:full_private_key]}"
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 = "InsertMintPublicKeyHere"
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
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-10 00:00:00.000000000 Z
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