arweave 0.9.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9d04de6a25b28b4b42809d2d14fbcd7e71befe7b49ed3977a81ef7eba5d3ac35
4
+ data.tar.gz: 74e087df6a11aa74699391335df2c8c01ec6bfe640a874320ce6e2dca300426e
5
+ SHA512:
6
+ metadata.gz: 79526f3f277e5425d6c52b0dbfcd63e1852d8a6923195d38e28378dacf753992817ddbea79fcba7d1558260cc4985d2120decaa4af10b9d53bfacfc13acee831
7
+ data.tar.gz: 52b5b82f06a20d5cee8f4c0e13621d27a50f5eb6068d7d1790c1d870c3420671ceadaab2ead190de3ea805529b92221ce1bf0ab66659f2d7b521d411af1a52ae
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /*.gem
10
+ .byebug_history
11
+
12
+ # rspec failure tracking
13
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.5.3
6
+ before_install: gem install bundler -v 2.1.4
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at arefaslani@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in arweave.gemspec
4
+ gemspec
5
+
6
+ gem 'rake', '~> 12.0'
7
+ gem 'rspec', '~> 3.0'
@@ -0,0 +1,65 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ arweave (0.1.0)
5
+ httparty (~> 0.18.1)
6
+ json-jwt (~> 1.13)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activesupport (6.0.3.1)
12
+ concurrent-ruby (~> 1.0, >= 1.0.2)
13
+ i18n (>= 0.7, < 2)
14
+ minitest (~> 5.1)
15
+ tzinfo (~> 1.1)
16
+ zeitwerk (~> 2.2, >= 2.2.2)
17
+ aes_key_wrap (1.0.1)
18
+ bindata (2.4.7)
19
+ byebug (11.1.3)
20
+ concurrent-ruby (1.1.6)
21
+ diff-lcs (1.3)
22
+ httparty (0.18.1)
23
+ mime-types (~> 3.0)
24
+ multi_xml (>= 0.5.2)
25
+ i18n (1.8.3)
26
+ concurrent-ruby (~> 1.0)
27
+ json-jwt (1.13.0)
28
+ activesupport (>= 4.2)
29
+ aes_key_wrap
30
+ bindata
31
+ mime-types (3.3.1)
32
+ mime-types-data (~> 3.2015)
33
+ mime-types-data (3.2020.0512)
34
+ minitest (5.14.1)
35
+ multi_xml (0.6.0)
36
+ rake (12.3.3)
37
+ rspec (3.9.0)
38
+ rspec-core (~> 3.9.0)
39
+ rspec-expectations (~> 3.9.0)
40
+ rspec-mocks (~> 3.9.0)
41
+ rspec-core (3.9.2)
42
+ rspec-support (~> 3.9.3)
43
+ rspec-expectations (3.9.2)
44
+ diff-lcs (>= 1.2.0, < 2.0)
45
+ rspec-support (~> 3.9.0)
46
+ rspec-mocks (3.9.1)
47
+ diff-lcs (>= 1.2.0, < 2.0)
48
+ rspec-support (~> 3.9.0)
49
+ rspec-support (3.9.3)
50
+ thread_safe (0.3.6)
51
+ tzinfo (1.2.7)
52
+ thread_safe (~> 0.1)
53
+ zeitwerk (2.3.0)
54
+
55
+ PLATFORMS
56
+ ruby
57
+
58
+ DEPENDENCIES
59
+ arweave!
60
+ byebug (~> 11.1)
61
+ rake (~> 12.0)
62
+ rspec (~> 3.0)
63
+
64
+ BUNDLED WITH
65
+ 2.1.4
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Aref Aslani
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,33 @@
1
+ # Arweave Ruby SDK
2
+ Ruby flavoured Arweave
3
+
4
+ ## installation
5
+ Simply run
6
+
7
+ `gem install arweave`
8
+
9
+ or put the gem into your gemfile:
10
+ ```ruby
11
+ gem 'arweave'
12
+ ```
13
+ ## Usage
14
+
15
+ ### Configuration
16
+ The default node that this package uses is `https://arweave.net`. But you can simply configure it:
17
+
18
+ ```ruby
19
+ Arweave::Client.configure do |config|
20
+ config.host = 'xxx.xxx.xxx.xxx' # a valid node IP
21
+ config.port = '1984'
22
+ config.scheme = 'https'
23
+ end
24
+ ```
25
+
26
+ ### Creating transactions
27
+ For a complete list of argument you can pass to the `create_transaction` method, checkout the [documentation](https://docs.arweave.org/developers/server/http-api#submit-a-transaction).
28
+
29
+ ```ruby
30
+ client = Arweave::Client.new
31
+ jwk = JSON.parse(File.read(File.expand_path(File.join('path-to-keyfile'))))
32
+ client.create_transaction(wallet: wallet, data: '<b>test</b>').commit
33
+ ```
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,30 @@
1
+ require_relative 'lib/arweave/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'arweave'
5
+ spec.version = Arweave::VERSION
6
+ spec.authors = ['Aref Aslani']
7
+ spec.email = ['arefaslani@gmail.com']
8
+
9
+ spec.summary = %q{Arweave SDK}
10
+ spec.description = %q{Ruby SDK for Arweave decentralized services}
11
+ spec.homepage = 'https://github.com/arefaslani/arweave'
12
+ spec.license = 'MIT'
13
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
14
+
15
+ spec.metadata['homepage_uri'] = spec.homepage
16
+ spec.metadata['source_code_uri'] = spec.homepage
17
+
18
+ # Specify which files should be added to the gem when it is released.
19
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
21
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
+ end
23
+ spec.bindir = 'exe'
24
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
+ spec.require_paths = ['lib']
26
+
27
+ spec.add_dependency 'json-jwt', '~> 1.13'
28
+ spec.add_dependency 'httparty', '~> 0.18.1'
29
+ spec.add_development_dependency 'byebug', '~> 11.1'
30
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "arweave"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,5 @@
1
+ require 'arweave/version'
2
+ require 'arweave/client'
3
+ require 'arweave/api'
4
+ require 'arweave/transaction'
5
+ require 'arweave/wallet'
@@ -0,0 +1,42 @@
1
+ require 'httparty'
2
+
3
+ module Arweave
4
+ class Api
5
+ include HTTParty
6
+
7
+ class << self
8
+ def instance
9
+ @instance ||=
10
+ new(
11
+ scheme: Client.configuration&.scheme || 'https',
12
+ host: Client.configuration&.host || 'arweave.net',
13
+ port: Client.configuration&.port || '443'
14
+ )
15
+ end
16
+ end
17
+
18
+ def get_transaction_anchor
19
+ self.class.get('/tx_anchor')
20
+ end
21
+
22
+ def reward(byte_size, address = '')
23
+ self.class.get("/price/#{byte_size}/#{address}")
24
+ end
25
+
26
+ def commit(transaction)
27
+ self.class.post(
28
+ '/tx',
29
+ body: transaction.attributes.to_json,
30
+ headers: { 'Content-Type' => 'application/json' }
31
+ )
32
+ end
33
+
34
+ private
35
+
36
+ def initialize(scheme:, host:, port:)
37
+ self.class.base_uri URI::Generic.build(
38
+ scheme: scheme, host: host, port: port
39
+ ).to_s
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,62 @@
1
+ require 'base64'
2
+
3
+ module Arweave
4
+ class Client
5
+ def initialize
6
+ @api = Api.instance
7
+ end
8
+
9
+ def create_transaction(wallet:, **attributes)
10
+ attributes.transform_keys!(&:to_sym)
11
+
12
+ transaction =
13
+ Transaction.new(
14
+ last_tx: api.get_transaction_anchor,
15
+ owner: wallet.owner,
16
+ tags: [],
17
+ target: attributes.fetch(:target, ''),
18
+ quantity: attributes.fetch(:quantity, '0'),
19
+ data:
20
+ Base64.urlsafe_encode64(
21
+ attributes.fetch(:data, ''),
22
+ padding: false
23
+ ),
24
+ reward:
25
+ api.reward(
26
+ attributes.fetch(:data, '').length,
27
+ attributes.fetch(:target, nil)
28
+ )
29
+ )
30
+
31
+ transaction.sign(wallet)
32
+ transaction
33
+ end
34
+
35
+ def commit(transaction)
36
+ api.commit(transaction)
37
+ end
38
+
39
+ class << self
40
+ attr_accessor :configuration
41
+ end
42
+
43
+ def self.configure
44
+ self.configuration ||= Configuration.new
45
+ yield @configuration
46
+ end
47
+
48
+ private
49
+
50
+ class Configuration
51
+ attr_accessor :scheme, :host, :port
52
+
53
+ def initialize
54
+ @scheme = 'https'
55
+ @port = '443'
56
+ @host = 'arweave.net'
57
+ end
58
+ end
59
+
60
+ attr_reader :api
61
+ end
62
+ end
@@ -0,0 +1,63 @@
1
+ require 'base64'
2
+
3
+ module Arweave
4
+ class Transaction
5
+ attr_reader :attributes
6
+
7
+ def initialize(attributes)
8
+ @attributes =
9
+ {
10
+ id: '',
11
+ last_tx: '',
12
+ owner: '',
13
+ tags: [],
14
+ target: '',
15
+ quantity: '0',
16
+ data: '',
17
+ reward: '0',
18
+ signature: ''
19
+ }.merge(attributes).yield_self do |hash|
20
+ hash.each do |key, value|
21
+ value.respond_to?(:map) ? hash[key] = value : hash[key] = value.to_s
22
+ end
23
+
24
+ hash
25
+ end.transform_keys!(&:to_sym)
26
+ end
27
+
28
+ def sign(wallet)
29
+ signature = wallet.sign(get_signature_data)
30
+
31
+ @attributes[:signature] =
32
+ Base64.urlsafe_encode64 signature, padding: false
33
+ @attributes[:id] =
34
+ Base64.urlsafe_encode64 Digest::SHA256.digest(signature), padding: false
35
+
36
+ # TODO: verify signature
37
+ signature
38
+ end
39
+
40
+ def commit
41
+ Api.instance.commit(self)
42
+ end
43
+
44
+ private
45
+
46
+ def get_signature_data
47
+ Base64.urlsafe_decode64(attributes.fetch(:owner)) +
48
+ Base64.urlsafe_decode64(attributes.fetch(:target)) +
49
+ Base64.urlsafe_decode64(attributes.fetch(:data)) +
50
+ attributes.fetch(:quantity) + attributes.fetch(:reward) +
51
+ Base64.urlsafe_decode64(attributes.fetch(:last_tx)) + tags_string
52
+ end
53
+
54
+ def verify
55
+ true
56
+ end
57
+
58
+ def tags_string
59
+ # TODO: Create tags string
60
+ ''
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,3 @@
1
+ module Arweave
2
+ VERSION = '0.9.0'
3
+ end
@@ -0,0 +1,40 @@
1
+ require 'json/jwt'
2
+ require 'base64'
3
+ require 'digest'
4
+
5
+ module Arweave
6
+ class Wallet
7
+ attr_reader :address, :owner
8
+
9
+ def initialize(jwk)
10
+ @jwk = jwk.transform_keys!(&:to_sym)
11
+ end
12
+
13
+ def owner
14
+ jwk.dig(:n)
15
+ end
16
+
17
+ def address
18
+ Base64.urlsafe_encode64(
19
+ Digest::SHA256.digest(Base64.urlsafe_decode64(owner)),
20
+ padding: false
21
+ )
22
+ end
23
+
24
+ def sign(message)
25
+ private_key.sign_pss(
26
+ 'SHA256',
27
+ message,
28
+ salt_length: 0, mgf1_hash: 'SHA256'
29
+ )
30
+ end
31
+
32
+ private
33
+
34
+ attr_reader :jwk
35
+
36
+ def private_key
37
+ JSON::JWK.new(jwk).to_key
38
+ end
39
+ end
40
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: arweave
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.0
5
+ platform: ruby
6
+ authors:
7
+ - Aref Aslani
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-06-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: json-jwt
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.13'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.13'
27
+ - !ruby/object:Gem::Dependency
28
+ name: httparty
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.18.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.18.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: byebug
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '11.1'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '11.1'
55
+ description: Ruby SDK for Arweave decentralized services
56
+ email:
57
+ - arefaslani@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".travis.yml"
65
+ - CODE_OF_CONDUCT.md
66
+ - Gemfile
67
+ - Gemfile.lock
68
+ - LICENSE.txt
69
+ - README.md
70
+ - Rakefile
71
+ - arweave.gemspec
72
+ - bin/console
73
+ - bin/setup
74
+ - lib/arweave.rb
75
+ - lib/arweave/api.rb
76
+ - lib/arweave/client.rb
77
+ - lib/arweave/transaction.rb
78
+ - lib/arweave/version.rb
79
+ - lib/arweave/wallet.rb
80
+ homepage: https://github.com/arefaslani/arweave
81
+ licenses:
82
+ - MIT
83
+ metadata:
84
+ homepage_uri: https://github.com/arefaslani/arweave
85
+ source_code_uri: https://github.com/arefaslani/arweave
86
+ post_install_message:
87
+ rdoc_options: []
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: 2.3.0
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ requirements: []
101
+ rubygems_version: 3.1.3
102
+ signing_key:
103
+ specification_version: 4
104
+ summary: Arweave SDK
105
+ test_files: []