Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NUT-07: Token state check with Y #93

Merged
merged 4 commits into from
Mar 12, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 11 additions & 12 deletions 07.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ A proof can be in one of the following states

**Note:** Before deleting spent proofs from their database, wallets can check if the proof is `SPENT` to make sure that they don't accidentally delete an unspent proof. Beware that this behavior can make it easier for the mint to correlate the sender to the receiver.

**Important:** Mints **MUST** remember which proofs are currently `PENDING` to avoid reuse of the same token in multiple concurrent transactions. This can be achieved with for example mutex lock whose key is the proof's `secret`.
**Important:** Mints **MUST** remember which proofs are currently `PENDING` to avoid reuse of the same token in multiple concurrent transactions. This can be achieved with for example mutex lock whose key is the `Proof`'s `Y`.

## Use cases

Expand All @@ -38,14 +38,14 @@ With the data being of the form `PostCheckStateRequest`:

```json
{
"secrets": [
<secret_str>,
"Ys": [
<Array[hex_str]>,
...
]
}
callebtc marked this conversation as resolved.
Show resolved Hide resolved
```

`secret_str` corresponds to `secret` of the `Proof` to check (see [NUT-00][00]).
Where the elements of the array in `Ys` are the hexadecimal representation of the compressed point `Y = hash_to_curve(secret)` of the `Proof` to check (see [NUT-00][00]).

**Response** of `Bob`:

Expand All @@ -55,7 +55,7 @@ With the data being of the form `PostCheckStateRequest`:
{
"states": [
{
"secret": <str>,
"Y": <hex_str>,
"state": <str_enum[STATE]>,
"witness": <str|null>,
},
Expand All @@ -64,8 +64,7 @@ With the data being of the form `PostCheckStateRequest`:
}
```

- `secret` corresponds to the proof to check in the request.

- `Y` corresponds to the `Proof` checked in the request.
- `state` is an enum string field with possible values `"UNSPENT"`, `"PENDING"`, `"SPENT"`
- `witness` is the serialized witness data that was used to spend the `Proof` if the token required it such as in the case of P2PK (see [NUT-11][11]).

Expand All @@ -75,8 +74,8 @@ With curl:

```bash
curl -X POST https://mint.host:3338/v1/checkstate -H 'Content-Type: application/json' -d '{
"secrets": [
"[\"P2PK\", {\"data\": \"027a0486a237d985cff2dcbec2c7f472136bc0af6399f28881f7fa5eb1a2244c3e\", \"nonce\": \"4a07f7ce5f9a416a67523a643f1944a5\", \"tags\": [[\"locktime\", \"1704459125\"], [\"sigflag\", \"SIG_ALL\"]]}]"
"Ys": [
"02599b9ea0a1ad4143706c2a5a4a568ce442dd4313e1cf1f7f0b58a317c1a355ee"
]
}'
```
Expand All @@ -87,16 +86,16 @@ curl -X POST https://mint.host:3338/v1/checkstate -H 'Content-Type: application/
{
"states": [
{
"secret": "[\"P2PK\", {\"data\": \"027a0486a237d985cff2dcbec2c7f472136bc0af6399f28881f7fa5eb1a2244c3e\", \"nonce\": \"4a07f7ce5f9a416a67523a643f1944a5\", \"tags\": [[\"locktime\", \"1704459125\"], [\"sigflag\", \"SIG_ALL\"]]}]",
"Y": "02599b9ea0a1ad4143706c2a5a4a568ce442dd4313e1cf1f7f0b58a317c1a355ee",
"state": "SPENT",
"witness": "{\"signatures\": [\"c92521e6922da68dbb05b7fb3f3c8004707d57d4379c021e97a9505d875ca100020f85493595578f66e950f383a7671b5d8edaefff5aadb379934cb524744023\"]}"
"witness": "{\"signatures\": [\"b2cf120a49cb1ac3cb32e1bf5ccb6425e0a8372affdc1d41912ca35c13908062f269c0caa53607d4e1ac4c8563246c4c8a869e6ee124ea826fd4746f3515dc1e\"]}"
}
]
}
```


Where `secret` belongs to the provided `Proof` to check in the request, `state` indicates its state, and `witness` is the witness data that was potentially provided in a previous spend operation (can be empty).
Where `Y` belongs to the provided `Proof` to check in the request, `state` indicates its state, and `witness` is the witness data that was potentially provided in a previous spend operation (can be empty).

[00]: 00.md
[01]: 01.md
Expand Down