Skip to content

Commit 9c903ec

Browse files
authored
NUT12: test vectors (cashubtc#105)
* chore: Add hash_e description * tests(NUT12): DLEQ BlindSignature and hash_e test vector * tests: DLEQ of proof test vector * chore: format
1 parent 3d23faf commit 9c903ec

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

12.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,21 @@ e == hash(R1,R2,A,C')
3232
If true, a in A = a*G must be equal to a in C' = a*B'
3333
```
3434

35+
### `hash(x: <Array<[PublicKey]>) -> bytes`
36+
37+
The hash(x) function generates a deterministic Sha256 hash for a given input list of `PublicKey`. The uncompressed hexadecimal representations of each `PublicKey` is concatenated before taking the Sha256 hash.
38+
39+
```python
40+
def hash_e(*publickeys: PublicKey) -> bytes:
41+
e_ = ""
42+
for p in publickeys:
43+
_p = p.serialize(compressed=False).hex()
44+
e_ += str(_p)
45+
e = hashlib.sha256(e_.encode("utf-8")).digest()
46+
return e
47+
48+
```
49+
3550
### Mint to user: DLEQ in `BlindSignature`
3651

3752
The mint produces these DLEQ proofs when returning `BlindSignature`'s in the responses for minting ([NUT-04][04]) and swapping ([NUT-03][03]) tokens. The `BlindSignature` object is extended in the following way to include the DLEQ proof:

tests/12-tests.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# NUT-12 Test vectors
2+
3+
## `hash_e` function
4+
5+
```shell
6+
R1: "020000000000000000000000000000000000000000000000000000000000000001"
7+
R2: "020000000000000000000000000000000000000000000000000000000000000001"
8+
K: "020000000000000000000000000000000000000000000000000000000000000001"
9+
C_: "02a9acc1e48c25eeeb9289b5031cc57da9fe72f3fe2861d264bdc074209b107ba2"
10+
```
11+
12+
```shell
13+
hash(R1, R2, K, C_): "a4dc034b74338c28c6bc3ea49731f2a24440fc7c4affc08b31a93fc9fbe6401e"
14+
```
15+
16+
## DLEQ verification on `BlindSignature`
17+
18+
The following is a `BlindSignature` with a **valid** DLEQ proof.
19+
```shell
20+
A: "0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"
21+
B_: "02a9acc1e48c25eeeb9289b5031cc57da9fe72f3fe2861d264bdc074209b107ba2"
22+
```
23+
24+
```json
25+
{
26+
"amount": 8,
27+
"id": "00882760bfa2eb41",
28+
"C_": "02a9acc1e48c25eeeb9289b5031cc57da9fe72f3fe2861d264bdc074209b107ba2",
29+
"dleq": {
30+
"e": "9818e061ee51d5c8edc3342369a554998ff7b4381c8652d724cdf46429be73d9",
31+
"s": "9818e061ee51d5c8edc3342369a554998ff7b4381c8652d724cdf46429be73da"
32+
}
33+
}
34+
```
35+
36+
## DLEQ verification on `Proof`
37+
38+
The following is a `Prood` with a **valid** DLEQ proof.
39+
40+
```shell
41+
A: "0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"
42+
```
43+
44+
```json
45+
{
46+
"amount": 1,
47+
"id": "00882760bfa2eb41",
48+
"secret": "daf4dd00a2b68a0858a80450f52c8a7d2ccf87d375e43e216e0c571f089f63e9",
49+
"C": "024369d2d22a80ecf78f3937da9d5f30c1b9f74f0c32684d583cca0fa6a61cdcfc",
50+
"dleq": {
51+
"e": "b31e58ac6527f34975ffab13e70a48b6d2b0d35abc4b03f0151f09ee1a9763d4",
52+
"s": "8fbae004c59e754d71df67e392b6ae4e29293113ddc2ec86592a0431d16306d8",
53+
"r": "a6d13fcd7a18442e6076f5e1e7c887ad5de40a019824bdfa9fe740d302e8d861"
54+
}
55+
}
56+
```

0 commit comments

Comments
 (0)