Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.24.3

require (
github.com/bsv-blockchain/go-bsv-middleware v0.11.0
github.com/bsv-blockchain/go-sdk v1.2.11
github.com/bsv-blockchain/go-sdk v1.2.12
github.com/bsv-blockchain/universal-test-vectors v0.6.1
github.com/filecoin-project/go-jsonrpc v0.9.0
github.com/go-co-op/gocron-gorm-lock/v2 v2.1.0
Expand Down Expand Up @@ -58,13 +58,13 @@ require (
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
go.yaml.in/yaml/v3 v3.0.4 // indirect
golang.org/x/crypto v0.43.0 // indirect
golang.org/x/mod v0.28.0 // indirect
golang.org/x/net v0.46.0 // indirect
golang.org/x/sync v0.17.0 // indirect
golang.org/x/sys v0.37.0 // indirect
golang.org/x/text v0.30.0 // indirect
golang.org/x/tools v0.37.0 // indirect
golang.org/x/crypto v0.44.0 // indirect
golang.org/x/mod v0.29.0 // indirect
golang.org/x/net v0.47.0 // indirect
golang.org/x/sync v0.18.0 // indirect
golang.org/x/sys v0.38.0 // indirect
golang.org/x/text v0.31.0 // indirect
golang.org/x/tools v0.38.0 // indirect
golang.org/x/xerrors v0.0.0-20240903120638-7835f813f4da // indirect
gorm.io/hints v1.1.2 // indirect
)
Expand Down
32 changes: 16 additions & 16 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERo
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
github.com/bsv-blockchain/go-bsv-middleware v0.11.0 h1:IZPxqIUB7K8Zq5Ys8HfRwh55J6noqoV8GiQ3BmkYbSg=
github.com/bsv-blockchain/go-bsv-middleware v0.11.0/go.mod h1:iUyYAvciHPNOj3vVgak6aUpJ90GRr3lG1iV+KnU9pbo=
github.com/bsv-blockchain/go-sdk v1.2.11 h1:SK8kDuDZNP3ubvx0AL0bR/I8tXWljJICyUsiF4y9ZkQ=
github.com/bsv-blockchain/go-sdk v1.2.11/go.mod h1:S+8iokWX2la9G4mzwHIeCvYkADRzcdfk1AprN0z5MDI=
github.com/bsv-blockchain/go-sdk v1.2.12 h1:t/50ONqCTgumJH82YbQ8iqdo30ezIACyuFgvyHbkX9A=
github.com/bsv-blockchain/go-sdk v1.2.12/go.mod h1:1FWCWH+x6xc1kH9r6tuyRQqUomfrLBOQfdPesJZK/1k=
github.com/bsv-blockchain/universal-test-vectors v0.6.1 h1:6mRV8T4ug8456p/rufoDselui3eKY6kr9mRYx8e87Rw=
github.com/bsv-blockchain/universal-test-vectors v0.6.1/go.mod h1:aNNGIH9aN/aCQ9vw0gTiQiOajkyBQIPJM9O6nHhhF5g=
github.com/cenkalti/backoff/v4 v4.2.1 h1:y4OZtCnogmCPw98Zjyt5a6+QwPLGkiQsYW5oUqylYbM=
Expand Down Expand Up @@ -239,48 +239,48 @@ go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc=
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.43.0 h1:dduJYIi3A3KOfdGOHX8AVZ/jGiyPa3IbBozJ5kNuE04=
golang.org/x/crypto v0.43.0/go.mod h1:BFbav4mRNlXJL4wNeejLpWxB7wMbc79PdRGhWKncxR0=
golang.org/x/crypto v0.44.0 h1:A97SsFvM3AIwEEmTBiaxPPTYpDC47w720rdiiUvgoAU=
golang.org/x/crypto v0.44.0/go.mod h1:013i+Nw79BMiQiMsOPcVCB5ZIJbYkerPrGnOa00tvmc=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/mod v0.28.0 h1:gQBtGhjxykdjY9YhZpSlZIsbnaE2+PgjfLWUQTnoZ1U=
golang.org/x/mod v0.28.0/go.mod h1:yfB/L0NOf/kmEbXjzCPOx1iK1fRutOydrCMsqRhEBxI=
golang.org/x/mod v0.29.0 h1:HV8lRxZC4l2cr3Zq1LvtOsi/ThTgWnUk/y64QSs8GwA=
golang.org/x/mod v0.29.0/go.mod h1:NyhrlYXJ2H4eJiRy/WDBO6HMqZQ6q9nk4JzS3NuCK+w=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.46.0 h1:giFlY12I07fugqwPuWJi68oOnpfqFnJIJzaIIm2JVV4=
golang.org/x/net v0.46.0/go.mod h1:Q9BGdFy1y4nkUwiLvT5qtyhAnEHgnQ/zd8PfU6nc210=
golang.org/x/net v0.47.0 h1:Mx+4dIFzqraBXUugkia1OOvlD6LemFo1ALMHjrXDOhY=
golang.org/x/net v0.47.0/go.mod h1:/jNxtkgq5yWUGYkaZGqo27cfGZ1c5Nen03aYrrKpVRU=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.17.0 h1:l60nONMj9l5drqw6jlhIELNv9I0A4OFgRsG9k2oT9Ug=
golang.org/x/sync v0.17.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
golang.org/x/sync v0.18.0 h1:kr88TuHDroi+UVf+0hZnirlk8o8T+4MrK6mr60WkH/I=
golang.org/x/sync v0.18.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.37.0 h1:fdNQudmxPjkdUTPnLn5mdQv7Zwvbvpaxqs831goi9kQ=
golang.org/x/sys v0.37.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
golang.org/x/sys v0.38.0 h1:3yZWxaJjBmCWXqhN1qh02AkOnCQ1poK6oF+a7xWL6Gc=
golang.org/x/sys v0.38.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.30.0 h1:yznKA/E9zq54KzlzBEAWn1NXSQ8DIp/NYMy88xJjl4k=
golang.org/x/text v0.30.0/go.mod h1:yDdHFIX9t+tORqspjENWgzaCVXgk0yYnYuSZ8UzzBVM=
golang.org/x/text v0.31.0 h1:aC8ghyu4JhP8VojJ2lEHBnochRno1sgL6nEi9WGFGMM=
golang.org/x/text v0.31.0/go.mod h1:tKRAlv61yKIjGGHX/4tP1LTbc13YSec1pxVEWXzfoeM=
golang.org/x/time v0.6.0 h1:eTDhh4ZXt5Qf0augr54TN6suAUudPcawVZeIAPU7D4U=
golang.org/x/time v0.6.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
golang.org/x/tools v0.37.0 h1:DVSRzp7FwePZW356yEAChSdNcQo6Nsp+fex1SUW09lE=
golang.org/x/tools v0.37.0/go.mod h1:MBN5QPQtLMHVdvsbtarmTNukZDdgwdwlO5qGacAzF0w=
golang.org/x/tools v0.38.0 h1:Hx2Xv8hISq8Lm16jvBZ2VQf+RLmbd7wVUsALibYI/IQ=
golang.org/x/tools v0.38.0/go.mod h1:yEsQ/d/YK8cjh0L6rZlY8tgtlKiBNTL14pGDJPJpYQs=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20240903120638-7835f813f4da h1:noIWHXmPHxILtqtCOPIhSt0ABwskkZKjD3bXGnZGpNY=
golang.org/x/xerrors v0.0.0-20240903120638-7835f813f4da/go.mod h1:NDW/Ps6MPRej6fsCIbMTohpP40sJ/P/vI1MoTEGwX90=
Expand Down
35 changes: 35 additions & 0 deletions pkg/internal/validate/validate_discover_by_identity_key_args.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package validate

import (
"fmt"

sdk "github.com/bsv-blockchain/go-sdk/wallet"
"github.com/bsv-blockchain/go-wallet-toolbox/pkg/wdk/primitives"
)

// DiscoverByIdentityKeyArgs validates arguments for DiscoverByIdentityKey()
func DiscoverByIdentityKeyArgs(args sdk.DiscoverByIdentityKeyArgs) error {
if args.Limit != nil {
if *args.Limit < MinPaginationLimit {
return fmt.Errorf("limit must be greater than 0")
}
if *args.Limit > MaxPaginationLimit {
return fmt.Errorf("limit exceeds max allowed value of %d", MaxPaginationLimit)
}
}

if args.Offset != nil {
if *args.Offset > MaxPaginationOffset {
return fmt.Errorf("offset is too large")
}
}

if args.IdentityKey != nil {
hex := primitives.PubKeyHex(args.IdentityKey.ToDERHex())
if err := hex.Validate(); err != nil {

Check failure on line 29 in pkg/internal/validate/validate_discover_by_identity_key_args.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Check this error or remove the variable if the error can be safely ignored.

See more on https://sonarcloud.io/project/issues?id=bsv-blockchain_go-wallet-toolbox&issues=AZrHwIKscONpQyvoeBbA&open=AZrHwIKscONpQyvoeBbA&pullRequest=700

Check warning on line 29 in pkg/internal/validate/validate_discover_by_identity_key_args.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this unnecessary variable declaration and use the expression directly in the condition.

See more on https://sonarcloud.io/project/issues?id=bsv-blockchain_go-wallet-toolbox&issues=AZrHwIKscONpQyvoeBa_&open=AZrHwIKscONpQyvoeBa_&pullRequest=700
return fmt.Errorf("invalid verifier: failed validation check")
}
}

return nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package mapping

import (
"context"
"encoding/json"
"log/slog"

"github.com/bsv-blockchain/go-sdk/auth/certificates"
"github.com/bsv-blockchain/go-sdk/overlay/lookup"
"github.com/bsv-blockchain/go-sdk/transaction"
"github.com/bsv-blockchain/go-sdk/transaction/template/pushdrop"
"github.com/bsv-blockchain/go-sdk/wallet"
"github.com/bsv-blockchain/go-wallet-toolbox/pkg/internal/logging"
)

func MapLookupAnswerToVerifiableCertificates(ctx context.Context, logger *slog.Logger, lookupAns *lookup.LookupAnswer) []certificates.VerifiableCertificate {
if lookupAns.Type != lookup.AnswerTypeOutputList {
return nil
}

parsedCerts := make([]certificates.VerifiableCertificate, 0)

// On any error we do nothing and continue with other outputs as in TS
for _, output := range lookupAns.Outputs {
tx, err := transaction.NewTransactionFromBEEF(output.Beef)
if err != nil {
logger.Error("failed to create tx from output beef", slog.String("beef", string(output.Beef)), logging.Error(err))
continue
}

// Decode the Identity token fields from the Bitcoin outputScript
decodedOutput := pushdrop.Decode(tx.Outputs[output.OutputIndex].LockingScript)

// Parse out the certificate and relevant data
var verifiableCertificate certificates.VerifiableCertificate
err = json.Unmarshal(decodedOutput.Fields[0], &verifiableCertificate)
if err != nil {
logger.Error("failed to unmarshal decodedOutput field into a certificate: %w ", logging.Error(err))
continue
}

anyoneProtoWallet, err := wallet.NewCompletedProtoWallet(nil)
if err != nil {
logger.Error("failed to create anyone's proto wallet: %w ", logging.Error(err))
continue
}

decryptedFields, err := verifiableCertificate.DecryptFields(ctx,
anyoneProtoWallet,
false,
"")
if err != nil {
logger.Error("failed to decrypt verifiableCertificate fields: %w ", logging.Error(err))
continue
}

// Verify the certificate signature is correct
err = verifiableCertificate.Verify(ctx)
if err != nil {
logger.Error("failed to verify certificate's signature: %w ", logging.Error(err))
continue
}

verifiableCertificate.DecryptedFields = decryptedFields

parsedCerts = append(parsedCerts, verifiableCertificate)
}

return parsedCerts
}
17 changes: 17 additions & 0 deletions pkg/wallet/internal/mapping/mapping_overlay_network.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package mapping

import (
"github.com/bsv-blockchain/go-sdk/overlay"
"github.com/bsv-blockchain/go-wallet-toolbox/pkg/defs"
)

func MapToOverlayNetwork(chain defs.BSVNetwork) overlay.Network {
switch chain {
case defs.NetworkMainnet:
return overlay.NetworkMainnet
case defs.NetworkTestnet:
return overlay.NetworkTestnet
default:
return overlay.NetworkTestnet
}
}
57 changes: 57 additions & 0 deletions pkg/wallet/internal/mapping/mapping_verifiable_certificate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package mapping

import (
"encoding/base64"
"fmt"

"github.com/bsv-blockchain/go-sdk/auth/certificates"
ec "github.com/bsv-blockchain/go-sdk/primitives/ec"
"github.com/bsv-blockchain/go-sdk/wallet"
"github.com/go-softwarelab/common/pkg/to"
)

func MapVerifiableCertificateToCertificate(cert certificates.VerifiableCertificate) (wallet.Certificate, error) {
serialBytes, err := base64.StdEncoding.DecodeString(string(cert.SerialNumber))
if err != nil {
return wallet.Certificate{}, fmt.Errorf("failed to decode certificate serial number: %w", err)
}

var serial wallet.SerialNumber
if len(serialBytes) != len(serial) {
return wallet.Certificate{}, fmt.Errorf("serial bytes length: %d is not equal to wallet.SerialNumber bytes length: %d", len(serialBytes), len(serial))
}

copy(serial[:], serialBytes)

certTypeBytes, err := base64.StdEncoding.DecodeString(string(cert.Type))
if err != nil {
return wallet.Certificate{}, fmt.Errorf("failed to decode certificate type: %w", err)
}

var certType wallet.CertificateType
if len(certType) != len(certTypeBytes) {
return wallet.Certificate{}, fmt.Errorf("certificate type bytes length: %d is not equal to sdk.CertificateType bytes length: %d", len(certTypeBytes), len(certType))
}

copy(certType[:], certTypeBytes)

fields := make(map[string]string, len(cert.Fields))
for k, v := range cert.Fields {
fields[to.String(k)] = to.String(v)
}

signature, err := ec.ParseSignature(cert.Signature)
if err != nil {
return wallet.Certificate{}, fmt.Errorf("failed to parse signature: %w", err)
}

return wallet.Certificate{
Type: certType,
SerialNumber: serial,
Subject: to.Ptr(cert.Subject),
Certifier: to.Ptr(cert.Certifier),
RevocationOutpoint: cert.RevocationOutpoint,
Fields: fields,
Signature: signature,
}, nil
}
Loading
Loading