Created
June 16, 2020 12:43
-
-
Save arefaslani/cd1948f968aef12b8cfb67197dd9d669 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'json/jwt' | |
require 'base64' | |
require 'digest' | |
module Arweave | |
class Wallet | |
attr_reader :address, :owner | |
def initialize(jwk) | |
@jwk = jwk.transform_keys!(&:to_sym) | |
end | |
def owner | |
jwk.dig(:n) | |
end | |
def address | |
Base64.urlsafe_encode64( | |
Digest::SHA256.hexdigest(Base64.urlsafe_decode64(owner)), | |
padding: false | |
) | |
end | |
def sign(message) | |
private_key.sign_pss('SHA256', message, salt_length: 0, mgf1_hash: 'SHA256') | |
end | |
private | |
attr_reader :jwk | |
def private_key | |
JSON::JWK.new(jwk).to_key | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment