mirror of
https://github.com/aljazceru/ark.git
synced 2025-12-18 12:44:19 +01:00
Ark Notes (#379)
* ark credits * rename "ecash" --> "ark credit" * rework note_test.go * NewFromString * create several notes * note repo: rename "push" to "add" * RegisterInputsForNextRoundRequest: move "notes" to field #3 * use uint64 as note ID * rename to voucher * add nostr notification * nostr notification test and fixes * bump badger to 4.3 * allow npub to be registered * rename poolTxID * add default relays * Update server/internal/config/config.go Co-authored-by: Marco Argentieri <3596602+tiero@users.noreply.github.com> * fix RedeemVouchers test * notification = voucher * WASM wrappers * fix arkd voucher cmd * test_utils.go ignore gosec rule G101 * fix permissions * rename ALL to notes * add URI prefix * note.go : fix signature encoding * fix decode note.Data * Update server/internal/infrastructure/notifier/nostr/nostr.go Co-authored-by: Pietralberto Mazza <18440657+altafan@users.noreply.github.com> * Update pkg/client-sdk/wasm/browser/wrappers.go Co-authored-by: Pietralberto Mazza <18440657+altafan@users.noreply.github.com> * Update server/internal/infrastructure/notifier/nostr/nostr.go Co-authored-by: Pietralberto Mazza <18440657+altafan@users.noreply.github.com> * rework note and entity db + sqlite implementations * NOTIFICATION_PREFIX -> NOTE_URI_PREFIX * validate NOTE_URI_PREFIX * Update defaults to convenant-less mainnet (#2) * config: defaults to convenant-less tx builder * Drop env var for blockchain scanner --------- Co-authored-by: altafan <18440657+altafan@users.noreply.github.com> * add // before URI prefix * add URI prefix in admin CreateNote * Fixes * rework nonces encoding (#4) * rework nonces encoding * add a check in Musig2Nonce decode function * musig2_test: increase number of signers to 20 * musig2.json: add a test case with a 35 leaves tree * GetEventStream REST rework * fix round phases time intervals * [SDK] Use server-side streams in rest client * Fix history * make the URI optional * Updates * Fix settled txs in history * fix e2e test * go work sync in sdk unit test * fix signMessage in btc and liquid sdk wallets --------- Co-authored-by: Marco Argentieri <3596602+tiero@users.noreply.github.com> Co-authored-by: Pietralberto Mazza <18440657+altafan@users.noreply.github.com>
This commit is contained in:
72
server/internal/core/application/proof.go
Normal file
72
server/internal/core/application/proof.go
Normal file
@@ -0,0 +1,72 @@
|
||||
package application
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"encoding/binary"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
|
||||
"github.com/ark-network/ark/common/bitcointree"
|
||||
"github.com/ark-network/ark/common/tree"
|
||||
"github.com/ark-network/ark/server/internal/core/domain"
|
||||
"github.com/btcsuite/btcd/btcec/v2/schnorr"
|
||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
"github.com/btcsuite/btcd/txscript"
|
||||
"github.com/decred/dcrd/dcrec/secp256k1/v4"
|
||||
)
|
||||
|
||||
// OwnershipProof is a proof that the owner of a vtxo has the secret key able to sign the forfeit leaf.
|
||||
type OwnershipProof struct {
|
||||
ControlBlock *txscript.ControlBlock
|
||||
Script []byte
|
||||
Signature *schnorr.Signature
|
||||
}
|
||||
|
||||
func (p OwnershipProof) validate(vtxo domain.Vtxo) error {
|
||||
// verify revealed script and extract user public key
|
||||
pubkey, err := decodeForfeitClosure(p.Script)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// verify control block
|
||||
rootHash := p.ControlBlock.RootHash(p.Script)
|
||||
vtxoTapKey := txscript.ComputeTaprootOutputKey(bitcointree.UnspendableKey(), rootHash)
|
||||
|
||||
if hex.EncodeToString(schnorr.SerializePubKey(vtxoTapKey)) != vtxo.Pubkey {
|
||||
return fmt.Errorf("invalid control block")
|
||||
}
|
||||
|
||||
// verify signature
|
||||
txhash, err := chainhash.NewHashFromStr(vtxo.Txid)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
voutBytes := make([]byte, 4)
|
||||
binary.BigEndian.PutUint32(voutBytes, vtxo.VOut)
|
||||
|
||||
outpointBytes := append(txhash[:], voutBytes...)
|
||||
sigMsg := sha256.Sum256(outpointBytes)
|
||||
|
||||
if !p.Signature.Verify(sigMsg[:], pubkey) {
|
||||
return fmt.Errorf("invalid signature")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func decodeForfeitClosure(script []byte) (*secp256k1.PublicKey, error) {
|
||||
var covenantLessForfeitClosure bitcointree.MultisigClosure
|
||||
|
||||
if valid, err := covenantLessForfeitClosure.Decode(script); err == nil && valid {
|
||||
return covenantLessForfeitClosure.Pubkey, nil
|
||||
}
|
||||
|
||||
var covenantForfeitClosure tree.CSVSigClosure
|
||||
if valid, err := covenantForfeitClosure.Decode(script); err == nil && valid {
|
||||
return covenantForfeitClosure.Pubkey, nil
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("invalid forfeit closure script")
|
||||
}
|
||||
Reference in New Issue
Block a user