calldata 0.1.1 → 1.0.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +2 -1
- data/README.md +5 -3
- data/Rakefile +2 -2
- data/lib/calldata/parser.rb +1 -1
- data/lib/calldata/version.rb +3 -3
- data/lib/calldata.rb +34 -21
- metadata +7 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c4dd0b6fb62eefef1c10f244cb566a87c6a15847ae6485120bb8eef8c943fa7b
|
|
4
|
+
data.tar.gz: e8d7ae06405ff382922ae150e085780c14bb94d9a764b9af6e5ab4640ef5b156
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a0e6b1d1b714f3f9ab48e85a865d4c08102e5f5908ccbe93db2bcde5ebff6d8f5275b538b708187272e6962b5c0ff05a77ba7f8c28dc97df2b199a49185058a3
|
|
7
|
+
data.tar.gz: ebaf152e85680c18a7f10bfca7cd4a09accb3b72284c5d5af1c7e820dc90d69f4463f9408c08be5254f102a5bfde7a7f948010230f3939ab55795062d30512fe
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
calldata - Calldata.encode / Calldata.decode using utf8_to_hex and hex_to_utf8 helpers and more for inscriptions / inscribes for ethereum & co
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
* home :: [github.com/
|
|
7
|
-
* bugs :: [github.com/
|
|
6
|
+
* home :: [github.com/0xCompute/ethscribe](https://github.com/0xCompute/ethscribe)
|
|
7
|
+
* bugs :: [github.com/0xCompute/ethscribe/issues](https://github.com/0xCompute/ethscribe/issues)
|
|
8
8
|
* gem :: [rubygems.org/gems/calldata](https://rubygems.org/gems/calldata)
|
|
9
9
|
* rdoc :: [rubydoc.info/gems/calldata](http://rubydoc.info/gems/calldata)
|
|
10
10
|
|
|
@@ -161,7 +161,9 @@ at the ruby code commons (rubycocos) org.
|
|
|
161
161
|
|
|
162
162
|
## Questions? Comments?
|
|
163
163
|
|
|
164
|
-
Join us in the [
|
|
164
|
+
Join us in the [0xCompute discord (chat server)](https://discord.gg/3JRnDUap6y)
|
|
165
|
+
(or in the more general Ethscription discord).
|
|
166
|
+
Yes you can.
|
|
165
167
|
Your questions and commentary welcome.
|
|
166
168
|
|
|
167
169
|
Or post them over at the [Help & Support](https://github.com/geraldb/help) page. Thanks.
|
data/Rakefile
CHANGED
|
@@ -8,7 +8,7 @@ Hoe.spec 'calldata' do
|
|
|
8
8
|
self.summary = "calldata gem - Calldata.encode / Calldata.decode using utf8_to_hex and hex_to_utf8 helpers and more for inscriptions / inscribes for ethereum & co"
|
|
9
9
|
self.description = summary
|
|
10
10
|
|
|
11
|
-
self.urls = { home: 'https://github.com/
|
|
11
|
+
self.urls = { home: 'https://github.com/0xCompute/ethscribe' }
|
|
12
12
|
|
|
13
13
|
self.author = 'Gerald Bauer'
|
|
14
14
|
self.email = 'gerald.bauer@gmail.com'
|
|
@@ -18,7 +18,7 @@ Hoe.spec 'calldata' do
|
|
|
18
18
|
self.history_file = 'CHANGELOG.md'
|
|
19
19
|
|
|
20
20
|
self.extra_deps = [
|
|
21
|
-
['datauris', '>= 1.
|
|
21
|
+
['datauris', '>= 1.2.0'],
|
|
22
22
|
['cocos'],
|
|
23
23
|
]
|
|
24
24
|
|
data/lib/calldata/parser.rb
CHANGED
|
@@ -17,7 +17,7 @@ class Calldata
|
|
|
17
17
|
def self.parse_hex( hex ) parse_data( decode( hex )); end
|
|
18
18
|
|
|
19
19
|
def self.parse_data( utf8 )
|
|
20
|
-
|
|
20
|
+
data, type = DataUri.parse( utf8 ) ## note: data, type order switched in datauris 1.0.1+
|
|
21
21
|
|
|
22
22
|
binary = if type
|
|
23
23
|
if type.start_with?( 'image/svg+xml' )
|
data/lib/calldata/version.rb
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
|
|
2
2
|
class Calldata
|
|
3
|
-
MAJOR =
|
|
4
|
-
MINOR =
|
|
5
|
-
PATCH =
|
|
3
|
+
MAJOR = 1 ## todo: namespace inside version or something - why? why not??
|
|
4
|
+
MINOR = 0
|
|
5
|
+
PATCH = 0
|
|
6
6
|
VERSION = [MAJOR,MINOR,PATCH].join('.')
|
|
7
7
|
|
|
8
8
|
def self.version
|
data/lib/calldata.rb
CHANGED
|
@@ -14,29 +14,45 @@ require_relative 'calldata/version' # let version go first
|
|
|
14
14
|
## hexdata encode/decode (hex string NOT binary, utf8-encoded string)
|
|
15
15
|
## utf8-to-hex, hex-to-utf8
|
|
16
16
|
|
|
17
|
-
def utf8_to_hex( utf8 ) ## use
|
|
18
|
-
# str.unpack('U'*str.length).map {|b| b.to_s(16) }.join
|
|
19
|
-
# str.unpack('H*').first
|
|
20
|
-
## note: 0 or 3 must be 00 or 03 with padding!!
|
|
21
|
-
## or use rjust( 2, '0' ) - why? why not?
|
|
22
|
-
# str.each_byte.map { |b| '%02x' % b }.join
|
|
17
|
+
def utf8_to_hex( utf8 ) ## use bin_to_hex - why? why not?
|
|
23
18
|
utf8.unpack('H*').first
|
|
24
19
|
end
|
|
25
20
|
|
|
26
21
|
|
|
27
|
-
def hex_to_utf8( hex ) ## use
|
|
28
|
-
# str.scan(/../).map { |x| x.hex }.pack('c*')
|
|
29
|
-
## fix: will NOT work for multi-byte chars
|
|
30
|
-
## str.scan(/../).map { |x| x.hex.chr }.join
|
|
31
|
-
|
|
22
|
+
def hex_to_utf8( hex ) ## use hex_to_bin - why? why not?
|
|
32
23
|
### cut-off optionial 0x/0X
|
|
33
|
-
hex = hex[2..-1] if hex.start_with?( '0x' ) || hex.start_with?( '0X')
|
|
34
|
-
|
|
35
|
-
##
|
|
24
|
+
hex = hex[2..-1] if hex.start_with?( '0x' ) || hex.start_with?( '0X' )
|
|
25
|
+
|
|
26
|
+
## check if force_encoding( 'UTF-8' ) redundant here?
|
|
27
|
+
return hex.force_encoding( 'UTF-8' ) if hex.empty? ## empty string - return as is
|
|
28
|
+
|
|
29
|
+
## add hexchars check here - why? why not?
|
|
30
|
+
## do NOT allow space, or anything except a-z, A-Z, 0-9
|
|
31
|
+
raise ArgumentError, "hexstring expected; got #{hex}" unless /\A[0-9a-fA-F]+\z/.match?( hex )
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
## note: ethscriptions specifies that \u0000
|
|
36
35
|
## (that is, \x00 - 0 byte) gets deleted/removed (even if valid utf-8)
|
|
37
36
|
## reason given: 0 byte in utf-8 messes up postgresql storage!
|
|
38
37
|
|
|
39
|
-
|
|
38
|
+
## fix-fix-fix - todo: add support for cleanup / fix corrup utf8 encoding - why? why not?
|
|
39
|
+
## unless utf8_string.valid_encoding?
|
|
40
|
+
## utf8_string = utf8_string.encode('UTF-8',
|
|
41
|
+
## invalid: :replace,
|
|
42
|
+
## undef: :replace,
|
|
43
|
+
## replace: "\uFFFD")
|
|
44
|
+
## end
|
|
45
|
+
## check what's the replace char -> "\uFFFD"
|
|
46
|
+
|
|
47
|
+
# note: about string#delete
|
|
48
|
+
# Returns a copy of str with all characters of its arguments deleted.
|
|
49
|
+
# Uses the same rules for building the set of characters as String#count.
|
|
50
|
+
|
|
51
|
+
##
|
|
52
|
+
## note: single hexchars get expanded e.g.
|
|
53
|
+
# ['a'].pack('H*') => "\xA0"
|
|
54
|
+
|
|
55
|
+
[hex].pack('H*').force_encoding( 'UTF-8' ).delete( "\u0000" )
|
|
40
56
|
end
|
|
41
57
|
|
|
42
58
|
|
|
@@ -44,7 +60,6 @@ end
|
|
|
44
60
|
##
|
|
45
61
|
## note: change Calldata to a base class with concrete/subclasses!!
|
|
46
62
|
|
|
47
|
-
|
|
48
63
|
class Calldata
|
|
49
64
|
def self.encode( utf8 )
|
|
50
65
|
raise TypeError, "Calldata.encode - String expected; got #{utf8.inspect} : #{utf8.class.name}" unless utf8.is_a?( String )
|
|
@@ -54,14 +69,12 @@ class Calldata
|
|
|
54
69
|
|
|
55
70
|
def self.decode( hex )
|
|
56
71
|
raise TypeError, "Calldata.decode - String expected; got #{hex.inspect} : #{hex.class.name}" unless hex.is_a?( String )
|
|
57
|
-
raise ArgumentError, "Calldata.decode - hexstring expected; got #{hex}" unless valid_hex?( hex )
|
|
58
72
|
## todo/check - add a regex/format check here - why? why not?
|
|
59
73
|
## must be string and hexchars only (0x/0X)
|
|
60
74
|
hex_to_utf8( hex )
|
|
61
75
|
end
|
|
62
76
|
|
|
63
77
|
|
|
64
|
-
HEXCHARS_RX = /\A[0-9a-fA-F]{2,}\z/
|
|
65
78
|
|
|
66
79
|
def self.valid_hex?( hex )
|
|
67
80
|
### cut-off optionial 0x/0X
|
|
@@ -70,10 +83,10 @@ class Calldata
|
|
|
70
83
|
## allow 0x/0X - that is zero? as valid - why? why not?
|
|
71
84
|
return true if hex.empty?
|
|
72
85
|
|
|
73
|
-
match = HEXCHARS_RX.match( hex)
|
|
74
|
-
|
|
75
86
|
## note: a byte requires two hexchars (hexchars must be even!! 2,4,6,8,etc.)
|
|
76
|
-
|
|
87
|
+
## enforce this even requirement - why? why not?
|
|
88
|
+
## or turn a into a0 and 0 int 00 and so on - why? why not?
|
|
89
|
+
/\A[0-9a-fA-F]+\z/.match?( hex ) ## && hex.length.even?
|
|
77
90
|
end
|
|
78
91
|
|
|
79
92
|
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: calldata
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 1.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Gerald Bauer
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2024-04-04 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: datauris
|
|
@@ -16,14 +16,14 @@ dependencies:
|
|
|
16
16
|
requirements:
|
|
17
17
|
- - ">="
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: 1.
|
|
19
|
+
version: 1.2.0
|
|
20
20
|
type: :runtime
|
|
21
21
|
prerelease: false
|
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
23
|
requirements:
|
|
24
24
|
- - ">="
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: 1.
|
|
26
|
+
version: 1.2.0
|
|
27
27
|
- !ruby/object:Gem::Dependency
|
|
28
28
|
name: cocos
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -64,14 +64,14 @@ dependencies:
|
|
|
64
64
|
requirements:
|
|
65
65
|
- - "~>"
|
|
66
66
|
- !ruby/object:Gem::Version
|
|
67
|
-
version: '4.
|
|
67
|
+
version: '4.1'
|
|
68
68
|
type: :development
|
|
69
69
|
prerelease: false
|
|
70
70
|
version_requirements: !ruby/object:Gem::Requirement
|
|
71
71
|
requirements:
|
|
72
72
|
- - "~>"
|
|
73
73
|
- !ruby/object:Gem::Version
|
|
74
|
-
version: '4.
|
|
74
|
+
version: '4.1'
|
|
75
75
|
description: calldata gem - Calldata.encode / Calldata.decode using utf8_to_hex and
|
|
76
76
|
hex_to_utf8 helpers and more for inscriptions / inscribes for ethereum & co
|
|
77
77
|
email: gerald.bauer@gmail.com
|
|
@@ -89,7 +89,7 @@ files:
|
|
|
89
89
|
- lib/calldata.rb
|
|
90
90
|
- lib/calldata/parser.rb
|
|
91
91
|
- lib/calldata/version.rb
|
|
92
|
-
homepage: https://github.com/
|
|
92
|
+
homepage: https://github.com/0xCompute/ethscribe
|
|
93
93
|
licenses:
|
|
94
94
|
- Public Domain
|
|
95
95
|
metadata: {}
|