-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
307 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package nut10 | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
|
||
"github.com/elnosh/gonuts/cashu" | ||
) | ||
|
||
type WellKnownSecret struct { | ||
Nonce string `json:"nonce"` | ||
Data string `json:"data"` | ||
Tags [][]string `json:"tags"` | ||
} | ||
|
||
// SerializeSecret returns the json string to be put in the secret field of a proof | ||
func SerializeSecret(kind cashu.SecretKind, secretData WellKnownSecret) (string, error) { | ||
jsonSecret, err := json.Marshal(secretData) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
secretKind := kind.String() | ||
secret := fmt.Sprintf("[\"%s\", %v]", secretKind, string(jsonSecret)) | ||
|
||
return secret, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package nut11 | ||
|
||
import ( | ||
"crypto/rand" | ||
"encoding/hex" | ||
|
||
"github.com/elnosh/gonuts/cashu" | ||
"github.com/elnosh/gonuts/cashu/nuts/nut10" | ||
) | ||
|
||
type P2PKWitness struct { | ||
Signatures []string `json:"signatures"` | ||
} | ||
|
||
// P2PKSecret returns a secret with a spending condition | ||
// that will lock ecash to a public key | ||
func P2PKSecret(pubkey string) (string, error) { | ||
// generate random nonce | ||
nonceBytes := make([]byte, 32) | ||
_, err := rand.Read(nonceBytes) | ||
if err != nil { | ||
return "", err | ||
} | ||
nonce := hex.EncodeToString(nonceBytes) | ||
|
||
secretData := nut10.WellKnownSecret{ | ||
Nonce: nonce, | ||
Data: pubkey, | ||
} | ||
|
||
secret, err := nut10.SerializeSecret(cashu.P2PK, secretData) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
return secret, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package wallet | ||
|
||
import ( | ||
"github.com/btcsuite/btcd/btcec/v2" | ||
"github.com/btcsuite/btcd/btcutil/hdkeychain" | ||
) | ||
|
||
// Derive key that wallet will use to receive locked ecash | ||
func DeriveP2PK(key *hdkeychain.ExtendedKey) (*btcec.PrivateKey, error) { | ||
// m/129372 | ||
purpose, err := key.Derive(hdkeychain.HardenedKeyStart + 129372) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// m/129372'/0' | ||
coinType, err := purpose.Derive(hdkeychain.HardenedKeyStart + 0) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// m/129372'/0'/1' | ||
first, err := coinType.Derive(hdkeychain.HardenedKeyStart + 1) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// m/129372'/0'/1'/0 | ||
extKey, err := first.Derive(0) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
pk, err := extKey.ECPrivKey() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return pk, nil | ||
} |
Oops, something went wrong.