hpw-convert-eip681 0.1.0 → 0.1.1
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.
- package/LICENSE +21 -21
- package/README.md +147 -0
- package/hpw_convert_eip681_bg.wasm +0 -0
- package/package.json +3 -2
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 Osumi Akari
|
|
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 all
|
|
13
|
-
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 THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Osumi Akari
|
|
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 all
|
|
13
|
+
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 THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
# hpw-convert-eip681
|
|
2
|
+

|
|
3
|
+

|
|
4
|
+

|
|
5
|
+

|
|
6
|
+

|
|
7
|
+
|
|
8
|
+
日本におけるとある中央集権的なステーブルコイン決済QRコード(HashPort Wallet形式の決済リンク)のURLを解析し、EIP-681(ERC-681)形式の支払いURIや送金先アドレス・金額に変換する[Rust製ライブラリ](https://crates.io/crates/hpw-convert-eip681)です。[WebAssembly版(npm)](https://www.npmjs.com/package/hpw-convert-eip681)も同梱しています。
|
|
9
|
+
|
|
10
|
+
## 免責事項 / 非公式ツールについて
|
|
11
|
+
|
|
12
|
+
**本プロジェクトは個人による無保証のの非公式(unofficial)ツールです。**
|
|
13
|
+
|
|
14
|
+
本ライブラリの目的は、あくまで相互運用性(interoperability)の確保です。
|
|
15
|
+
|
|
16
|
+
実装は純粋なクライアントサイドの文字列・URL解析のみを行い、**外部のサーバーへ一切ネットワークリクエストを送信しません。** 入力として受け取ったURL文字列をその場でパースし、EIP-681形式の文字列やアドレス・金額に変換して返すだけです。
|
|
17
|
+
|
|
18
|
+
## 対応範囲
|
|
19
|
+
|
|
20
|
+
現時点では以下のみに対応しています(他のチェーン・通貨は今後の対応も未定です):
|
|
21
|
+
|
|
22
|
+
- チェーン: **Polygon (chain id `137`)** のみ
|
|
23
|
+
- 通貨: **JPYC** (`master_currency_id=487`) のみ
|
|
24
|
+
|
|
25
|
+
対応外のURL・チェーン・通貨は `ParseError` (もしくはJS側のタグ付きエラー)として明示的に拒否されます。
|
|
26
|
+
|
|
27
|
+
## 対象とするURL形式
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
https://link.expo2025-wallet.com/pay?to=<address>&master_currency_id=487&amount=<hex>&to_name=<label>
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
これをEIP-681形式に変換します:
|
|
34
|
+
|
|
35
|
+
```
|
|
36
|
+
ethereum:<JPYCコントラクトアドレス>@137/transfer?address=<to>&uint256=<amount>
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
`amount` は元URLに存在しないことがあります。その場合 `amount` は
|
|
40
|
+
`None`(JS側では `undefined`)として扱われ、EIP-681出力からも
|
|
41
|
+
`uint256=` パラメータ自体が省かれます(`ethereum:<contract>@137/transfer?address=<to>`)。これはEIP-681仕様が金額未指定のリクエストを
|
|
42
|
+
許容している(受け取り側のウォレットがユーザーに入力させる)ことに
|
|
43
|
+
対応したものです。
|
|
44
|
+
|
|
45
|
+
## インストール
|
|
46
|
+
|
|
47
|
+
### Rust (`core`)
|
|
48
|
+
|
|
49
|
+
```
|
|
50
|
+
cargo add hpw-convert-eip681
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### npm (`wasm`)
|
|
54
|
+
|
|
55
|
+
```
|
|
56
|
+
npm install hpw-convert-eip681
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## 使い方
|
|
60
|
+
|
|
61
|
+
### Rust
|
|
62
|
+
|
|
63
|
+
```rust
|
|
64
|
+
use hpw_convert_eip681::{is_supported, parse};
|
|
65
|
+
|
|
66
|
+
fn main() {
|
|
67
|
+
let url = "https://link.expo2025-wallet.com/pay?to=0x1234567890123456789012345678901234567890&master_currency_id=487&amount=0x3e8&to_name=Coffee%20Shop";
|
|
68
|
+
|
|
69
|
+
// 対応しているURLかどうかを事前に確認する
|
|
70
|
+
if !is_supported(url) {
|
|
71
|
+
eprintln!("unsupported link");
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// パースする
|
|
76
|
+
let link = parse(url).expect("valid HashPort link");
|
|
77
|
+
|
|
78
|
+
// EIP-681形式のURIを取得する
|
|
79
|
+
println!("{}", link.to_eip681());
|
|
80
|
+
// => ethereum:0xE7C3D8C9a439feDe00D2600032D5dB0Be71C3c29@137/transfer?address=0x1234...&uint256=1000
|
|
81
|
+
|
|
82
|
+
// アドレスと金額を個別に取得する(amountは元URLに無いこともあるため Option<U256>)
|
|
83
|
+
println!("to: {}", link.address());
|
|
84
|
+
match link.amount() {
|
|
85
|
+
Some(amount) => println!("amount: {amount}"),
|
|
86
|
+
None => println!("amount: (unspecified)"),
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// まとめて取得することもできる
|
|
90
|
+
let addr_amount = link.address_amount();
|
|
91
|
+
println!("{} / {:?}", addr_amount.address, addr_amount.amount);
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### JavaScript / TypeScript
|
|
96
|
+
|
|
97
|
+
```ts
|
|
98
|
+
import { isSupported, parseHashportLink, isValidChecksum } from "hpw-convert-eip681";
|
|
99
|
+
|
|
100
|
+
const url =
|
|
101
|
+
"https://link.expo2025-wallet.com/pay?to=0x1234567890123456789012345678901234567890&master_currency_id=487&amount=0x3e8&to_name=Coffee%20Shop";
|
|
102
|
+
|
|
103
|
+
// 対応しているURLかどうかを事前に確認する
|
|
104
|
+
if (!isSupported(url)) {
|
|
105
|
+
throw new Error("unsupported link");
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// パースする(失敗時は { kind: "...", ... } 形式のエラーをthrow)
|
|
109
|
+
try {
|
|
110
|
+
const link = parseHashportLink(url);
|
|
111
|
+
|
|
112
|
+
// EIP-681形式のURIを取得する
|
|
113
|
+
console.log(link.toEip681());
|
|
114
|
+
// => ethereum:0xE7C3D8C9a439feDe00D2600032D5dB0Be71C3c29@137/transfer?address=0x1234...&uint256=1000
|
|
115
|
+
|
|
116
|
+
// アドレスと金額を個別に取得する(amountは元URLに無い場合 undefined になる)
|
|
117
|
+
console.log(link.to, link.amount, link.amountHex);
|
|
118
|
+
|
|
119
|
+
// その他のフィールド
|
|
120
|
+
console.log(link.chainId, link.currencySymbol, link.currencyContract, link.toName);
|
|
121
|
+
} catch (err) {
|
|
122
|
+
console.error(err.kind, err);
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## チェックサム検証(オプション)
|
|
127
|
+
|
|
128
|
+
`parse` / `parseHashportLink` はアドレスの大文字・小文字を厳密にはチェックしない、寛容な(lenient)パースを行います。これとは別に、EIP-55チェックサムを厳密に検証したい場合のためのオプトインAPIとして `validate_checksum` / `isValidChecksum` を用意しています。
|
|
129
|
+
|
|
130
|
+
```rust
|
|
131
|
+
use hpw_convert_eip681::validate_checksum;
|
|
132
|
+
|
|
133
|
+
match validate_checksum("0xE7C3D8C9a439feDe00D2600032D5dB0Be71C3c29") {
|
|
134
|
+
Ok(address) => println!("valid checksum: {address}"),
|
|
135
|
+
Err(e) => eprintln!("invalid checksum: {e}"),
|
|
136
|
+
}
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
```ts
|
|
140
|
+
import { isValidChecksum } from "hpw-convert-eip681";
|
|
141
|
+
|
|
142
|
+
isValidChecksum("0xE7C3D8C9a439feDe00D2600032D5dB0Be71C3c29"); // => true / false
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## ライセンス
|
|
146
|
+
|
|
147
|
+
[MIT License](./LICENSE)
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"collaborators": [
|
|
5
5
|
"Osumi Akari"
|
|
6
6
|
],
|
|
7
|
-
"version": "0.1.
|
|
7
|
+
"version": "0.1.1",
|
|
8
8
|
"license": "MIT",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
@@ -15,7 +15,8 @@
|
|
|
15
15
|
"hpw_convert_eip681.js",
|
|
16
16
|
"hpw_convert_eip681_bg.js",
|
|
17
17
|
"hpw_convert_eip681.d.ts",
|
|
18
|
-
"LICENSE"
|
|
18
|
+
"LICENSE",
|
|
19
|
+
"README.md"
|
|
19
20
|
],
|
|
20
21
|
"main": "hpw_convert_eip681.js",
|
|
21
22
|
"types": "hpw_convert_eip681.d.ts",
|