Skip to content

Commit 1692121

Browse files
committed
Unify overlay and wallet Outpoint
1 parent e635525 commit 1692121

File tree

12 files changed

+43
-149
lines changed

12 files changed

+43
-149
lines changed

auth/certificates/certificate.go

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"context"
1010
"errors"
1111
"fmt"
12-
"github.com/bsv-blockchain/go-sdk/overlay"
1312
ec "github.com/bsv-blockchain/go-sdk/primitives/ec"
1413
"github.com/bsv-blockchain/go-sdk/wallet"
1514
"github.com/bsv-blockchain/go-sdk/wallet/serializer"
@@ -37,7 +36,7 @@ type Certificate struct {
3736
Certifier ec.PublicKey `json:"certifier"`
3837

3938
// The outpoint used to confirm that the certificate has not been revoked
40-
RevocationOutpoint *overlay.Outpoint `json:"revocationOutpoint"`
39+
RevocationOutpoint *wallet.Outpoint `json:"revocationOutpoint"`
4140

4241
// All the fields present in the certificate, with field names as keys and encrypted field values as strings
4342
Fields map[wallet.CertificateFieldNameUnder50Bytes]wallet.StringBase64 `json:"fields"`
@@ -52,7 +51,7 @@ func NewCertificate(
5251
serialNumber wallet.StringBase64,
5352
subject ec.PublicKey,
5453
certifier ec.PublicKey,
55-
revocationOutpoint *overlay.Outpoint,
54+
revocationOutpoint *wallet.Outpoint,
5655
fields map[wallet.CertificateFieldNameUnder50Bytes]wallet.StringBase64,
5756
signature []byte,
5857
) *Certificate {
@@ -219,15 +218,6 @@ func (c *Certificate) ToWalletCertificate() (*wallet.Certificate, error) {
219218
return nil, fmt.Errorf("invalid serial number: %w", err)
220219
}
221220

222-
// Convert overlay.Outpoint to wallet.Outpoint
223-
var revocationOutpoint *wallet.Outpoint
224-
if c.RevocationOutpoint != nil {
225-
revocationOutpoint = &wallet.Outpoint{
226-
Txid: c.RevocationOutpoint.Txid,
227-
Index: c.RevocationOutpoint.OutputIndex,
228-
}
229-
}
230-
231221
// Convert Fields map from map[CertificateFieldNameUnder50Bytes]StringBase64 to map[string]string
232222
fields := make(map[string]string)
233223
for fieldName, fieldValue := range c.Fields {
@@ -247,7 +237,7 @@ func (c *Certificate) ToWalletCertificate() (*wallet.Certificate, error) {
247237
SerialNumber: serialNumber,
248238
Subject: &c.Subject, // Convert value type to pointer
249239
Certifier: &c.Certifier, // Convert value type to pointer
250-
RevocationOutpoint: revocationOutpoint,
240+
RevocationOutpoint: c.RevocationOutpoint,
251241
Fields: fields,
252242
Signature: signature,
253243
}, nil
@@ -273,15 +263,6 @@ func FromWalletCertificate(walletCert *wallet.Certificate) (*Certificate, error)
273263
certifier = *walletCert.Certifier
274264
}
275265

276-
// Convert wallet.Outpoint to overlay.Outpoint
277-
var revocationOutpoint *overlay.Outpoint
278-
if walletCert.RevocationOutpoint != nil {
279-
revocationOutpoint = &overlay.Outpoint{
280-
Txid: walletCert.RevocationOutpoint.Txid,
281-
OutputIndex: walletCert.RevocationOutpoint.Index,
282-
}
283-
}
284-
285266
// Convert fields map from map[string]string to map[CertificateFieldNameUnder50Bytes]StringBase64
286267
fields := make(map[wallet.CertificateFieldNameUnder50Bytes]wallet.StringBase64)
287268
for fieldName, fieldValue := range walletCert.Fields {
@@ -298,7 +279,7 @@ func FromWalletCertificate(walletCert *wallet.Certificate) (*Certificate, error)
298279
SerialNumber: serialNumber,
299280
Subject: subject,
300281
Certifier: certifier,
301-
RevocationOutpoint: revocationOutpoint,
282+
RevocationOutpoint: walletCert.RevocationOutpoint,
302283
Fields: fields,
303284
Signature: signature,
304285
}, nil

auth/certificates/certificate_test.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"encoding/base64"
55
"testing"
66

7-
"github.com/bsv-blockchain/go-sdk/overlay"
87
ec "github.com/bsv-blockchain/go-sdk/primitives/ec"
98
tu "github.com/bsv-blockchain/go-sdk/util/test_util"
109
"github.com/bsv-blockchain/go-sdk/wallet"
@@ -31,9 +30,9 @@ func TestCertificate(t *testing.T) {
3130

3231
// Create a revocation outpoint
3332
txid := make([]byte, 32)
34-
var outpoint overlay.Outpoint
33+
var outpoint wallet.Outpoint
3534
copy(outpoint.Txid[:], txid)
36-
outpoint.OutputIndex = 1
35+
outpoint.Index = 1
3736
sampleRevocationOutpoint := &outpoint
3837

3938
// Convert string maps to the proper types
@@ -418,7 +417,7 @@ func TestCertificate(t *testing.T) {
418417
// Check revocation outpoint conversion
419418
assert.NotNil(t, walletCert.RevocationOutpoint)
420419
assert.Equal(t, certificate.RevocationOutpoint.Txid, walletCert.RevocationOutpoint.Txid)
421-
assert.Equal(t, certificate.RevocationOutpoint.OutputIndex, walletCert.RevocationOutpoint.Index)
420+
assert.Equal(t, certificate.RevocationOutpoint.Index, walletCert.RevocationOutpoint.Index)
422421
})
423422

424423
t.Run("ToWalletCertificate should handle certificate with signature", func(t *testing.T) {
@@ -460,7 +459,7 @@ func TestCertificate(t *testing.T) {
460459
Certifier: sampleCertifierPubKey,
461460
RevocationOutpoint: &wallet.Outpoint{
462461
Txid: sampleRevocationOutpoint.Txid,
463-
Index: sampleRevocationOutpoint.OutputIndex,
462+
Index: sampleRevocationOutpoint.Index,
464463
},
465464
Fields: map[string]string{
466465
"name": "Alice",
@@ -494,7 +493,7 @@ func TestCertificate(t *testing.T) {
494493
// Check revocation outpoint conversion
495494
assert.NotNil(t, certificate.RevocationOutpoint)
496495
assert.Equal(t, walletCert.RevocationOutpoint.Txid, certificate.RevocationOutpoint.Txid)
497-
assert.Equal(t, walletCert.RevocationOutpoint.Index, certificate.RevocationOutpoint.OutputIndex)
496+
assert.Equal(t, walletCert.RevocationOutpoint.Index, certificate.RevocationOutpoint.Index)
498497
})
499498

500499
t.Run("ToWalletCertificate and FromWalletCertificate should be round-trip compatible", func(t *testing.T) {

auth/certificates/master.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"errors"
88
"fmt"
99

10-
"github.com/bsv-blockchain/go-sdk/overlay"
1110
ec "github.com/bsv-blockchain/go-sdk/primitives/ec"
1211
"github.com/bsv-blockchain/go-sdk/wallet"
1312
)
@@ -127,7 +126,7 @@ func IssueCertificateForSubject(
127126
subject wallet.Counterparty,
128127
plainFields map[string]string, // Plaintext fields
129128
certificateType string,
130-
getRevocationOutpoint func(string) (*overlay.Outpoint, error), // Optional func
129+
getRevocationOutpoint func(string) (*wallet.Outpoint, error), // Optional func
131130
serialNumberStr string, // Optional serial number as StringBase64
132131
) (*MasterCertificate, error) {
133132

@@ -173,15 +172,15 @@ func IssueCertificateForSubject(
173172
}
174173

175174
// 4. Get revocation outpoint
176-
var revocationOutpoint *overlay.Outpoint
175+
var revocationOutpoint *wallet.Outpoint
177176
if getRevocationOutpoint != nil {
178177
revocationOutpoint, err = getRevocationOutpoint(string(serialNumber))
179178
if err != nil {
180179
return nil, fmt.Errorf("failed to get revocation outpoint: %w", err)
181180
}
182181
} else {
183182
// Default to empty outpoint (matching TS behavior where undefined becomes empty string)
184-
revocationOutpoint = &overlay.Outpoint{} // Assuming empty TXID and index 0 is the placeholder
183+
revocationOutpoint = &wallet.Outpoint{} // Assuming empty TXID and index 0 is the placeholder
185184
}
186185

187186
// 5. Create the base Certificate struct

auth/certificates/master_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"github.com/bsv-blockchain/go-sdk/auth/certificates"
1414
"github.com/bsv-blockchain/go-sdk/auth/utils"
1515
"github.com/bsv-blockchain/go-sdk/chainhash"
16-
"github.com/bsv-blockchain/go-sdk/overlay"
1716
ec "github.com/bsv-blockchain/go-sdk/primitives/ec"
1817
"github.com/bsv-blockchain/go-sdk/wallet"
1918
)
@@ -23,9 +22,9 @@ func TestMasterCertificate(t *testing.T) {
2322
certifierPrivateKey, _ := ec.NewPrivateKey()
2423
ctx := t.Context()
2524

26-
mockRevocationOutpoint := &overlay.Outpoint{
27-
Txid: chainhash.HashH([]byte("deadbeefdeadbeefdeadbeefdeadbeef00000000000000000000000000000000.1")),
28-
OutputIndex: 1,
25+
mockRevocationOutpoint := &wallet.Outpoint{
26+
Txid: chainhash.HashH([]byte("deadbeefdeadbeefdeadbeefdeadbeef00000000000000000000000000000000.1")),
27+
Index: 1,
2928
}
3029

3130
// Use CompletedProtoWallet for testing
@@ -405,7 +404,7 @@ func TestMasterCertificate(t *testing.T) {
405404
}
406405

407406
revocationFuncCalled := false
408-
mockRevocationFunc := func(serial string) (*overlay.Outpoint, error) {
407+
mockRevocationFunc := func(serial string) (*wallet.Outpoint, error) {
409408
revocationFuncCalled = true
410409
return mockRevocationOutpoint, nil
411410
}

auth/certificates/verifiable_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"testing"
88

99
"github.com/bsv-blockchain/go-sdk/chainhash"
10-
"github.com/bsv-blockchain/go-sdk/overlay"
1110
ec "github.com/bsv-blockchain/go-sdk/primitives/ec"
1211
"github.com/bsv-blockchain/go-sdk/wallet"
1312
"github.com/stretchr/testify/require"
@@ -29,9 +28,9 @@ func TestVerifiableCertificate(t *testing.T) {
2928
// Sample data
3029
sampleType := wallet.StringBase64(base64.StdEncoding.EncodeToString(bytes.Repeat([]byte{1}, 32)))
3130
sampleSerialNumber := wallet.StringBase64(base64.StdEncoding.EncodeToString(bytes.Repeat([]byte{2}, 32)))
32-
sampleRevocationOutpoint := &overlay.Outpoint{
33-
Txid: chainhash.HashH([]byte("deadbeefdeadbeefdeadbeefdeadbeef00000000000000000000000000000000.1")),
34-
OutputIndex: 1,
31+
sampleRevocationOutpoint := &wallet.Outpoint{
32+
Txid: chainhash.HashH([]byte("deadbeefdeadbeefdeadbeefdeadbeef00000000000000000000000000000000.1")),
33+
Index: 1,
3534
}
3635

3736
// Plaintext fields to encrypt

auth/utils/get_verifiable_certificates_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"encoding/base64"
88
"testing"
99

10-
"github.com/bsv-blockchain/go-sdk/overlay"
1110
ec "github.com/bsv-blockchain/go-sdk/primitives/ec"
1211
tu "github.com/bsv-blockchain/go-sdk/util/test_util"
1312
"github.com/bsv-blockchain/go-sdk/wallet"
@@ -58,7 +57,7 @@ func TestGetVerifiableCertificates(t *testing.T) {
5857
certifier, _ := ec.PublicKeyFromBytes([]byte{0x07, 0x08, 0x09})
5958

6059
// Mock wallet.ListCertificates response with base64-encoded values
61-
revocationOutpoint, _ := overlay.NewOutpointFromString("abcd1234:0")
60+
revocationOutpoint, _ := wallet.OutpointFromString("abcd1234:0")
6261
mockListResult := &wallet.ListCertificatesResult{
6362
Certificates: []wallet.CertificateResult{
6463
{
@@ -104,7 +103,7 @@ func TestGetVerifiableCertificates(t *testing.T) {
104103
require.Equal(t, expectedSerialBase64, cert.SerialNumber)
105104
require.NotNil(t, cert.RevocationOutpoint)
106105
if cert.RevocationOutpoint != nil && revocationOutpoint != nil {
107-
require.Equal(t, revocationOutpoint.OutputIndex, cert.RevocationOutpoint.OutputIndex)
106+
require.Equal(t, revocationOutpoint.Index, cert.RevocationOutpoint.Index)
108107
}
109108
}
110109
})

auth/validate_certificates_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"github.com/bsv-blockchain/go-sdk/auth/certificates"
88
"github.com/bsv-blockchain/go-sdk/auth/utils"
99
"github.com/bsv-blockchain/go-sdk/chainhash"
10-
"github.com/bsv-blockchain/go-sdk/overlay"
1110
ec "github.com/bsv-blockchain/go-sdk/primitives/ec"
1211
tu "github.com/bsv-blockchain/go-sdk/util/test_util"
1312
"github.com/bsv-blockchain/go-sdk/wallet"
@@ -79,9 +78,9 @@ func TestValidateCertificates(t *testing.T) {
7978
}
8079

8180
// Create revocation outpoint
82-
revocationOutpoint := &overlay.Outpoint{
83-
Txid: chainhash.HashH([]byte("test_txid_000000000000000000000000000000000000000000000000000000000000")),
84-
OutputIndex: 0,
81+
revocationOutpoint := &wallet.Outpoint{
82+
Txid: chainhash.HashH([]byte("test_txid_000000000000000000000000000000000000000000000000000000000000")),
83+
Index: 0,
8584
}
8685

8786
// Issue certificate
@@ -91,7 +90,7 @@ func TestValidateCertificates(t *testing.T) {
9190
subjectCounterparty,
9291
plaintextFields,
9392
string(utils.RandomBase64(32)), // certificate type
94-
func(serial string) (*overlay.Outpoint, error) {
93+
func(serial string) (*wallet.Outpoint, error) {
9594
return revocationOutpoint, nil
9695
},
9796
"", // auto-generate serial number

overlay/lookup/types.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ package lookup
22

33
import (
44
"encoding/json"
5-
6-
"github.com/bsv-blockchain/go-sdk/overlay"
5+
"github.com/bsv-blockchain/go-sdk/wallet"
76
)
87

98
// AnswerType represents the type of answer returned by a lookup service
@@ -29,7 +28,7 @@ type LookupQuestion struct {
2928

3029
// LookupFormula represents a formula for computing lookup results
3130
type LookupFormula struct {
32-
Outpoint *overlay.Outpoint
31+
Outpoint *wallet.Outpoint
3332
History func(beef []byte, outputIndex uint32, currentDepth uint32) bool
3433
// HistoryDepth uint32
3534
}

overlay/overlay.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package overlay
88

99
import (
1010
"github.com/bsv-blockchain/go-sdk/chainhash"
11+
"github.com/bsv-blockchain/go-sdk/wallet"
1112
)
1213

1314
// Protocol represents the overlay protocol type (SHIP or SLAP)
@@ -33,7 +34,7 @@ type AppliedTransaction struct {
3334
// TopicData represents data associated with an overlay topic including dependencies
3435
type TopicData struct {
3536
Data any
36-
Deps []*Outpoint
37+
Deps []*wallet.Outpoint
3738
}
3839

3940
// AdmittanceInstructions specify which outputs to admit and which coins to retain when submitting to overlay topics

wallet/encoding_json.go

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -478,24 +478,6 @@ func (cr *CertificateResult) UnmarshalJSON(data []byte) error {
478478
return nil
479479
}
480480

481-
func (o *Outpoint) MarshalJSON() ([]byte, error) {
482-
return json.Marshal(o.String())
483-
}
484-
485-
func (o *Outpoint) UnmarshalJSON(data []byte) error {
486-
var outpointStr string
487-
if err := json.Unmarshal(data, &outpointStr); err != nil {
488-
return fmt.Errorf("error unmarshaling outpoint string: %w", err)
489-
}
490-
outpoint, err := OutpointFromString(outpointStr)
491-
if err != nil {
492-
return fmt.Errorf("error parsing outpoint string: %w", err)
493-
}
494-
o.Txid = outpoint.Txid
495-
o.Index = outpoint.Index
496-
return nil
497-
}
498-
499481
// Custom marshalling for RevealCounterpartyKeyLinkageResult
500482
type aliasRevealCounterpartyKeyLinkageResult RevealCounterpartyKeyLinkageResult
501483
type jsonRevealCounterpartyKeyLinkageResult struct {

0 commit comments

Comments
 (0)