Skip to content

Commit fb8225c

Browse files
committed
Merge branch 'bopen-master' into opl-335-bytes
2 parents 279145e + 189b854 commit fb8225c

File tree

15 files changed

+245
-185
lines changed

15 files changed

+245
-185
lines changed

auth/certificates/master_test.go

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -255,9 +255,9 @@ func TestMasterCertificate(t *testing.T) {
255255

256256
// Define verifier within this scope too
257257
verifierPrivateKey, _ := ec.NewPrivateKey()
258-
// Use a standard ProtoWallet for the verifier
259-
verifierWallet, _ := wallet.NewProtoWallet(wallet.ProtoWalletArgs{Type: wallet.ProtoWalletArgsTypePrivateKey, PrivateKey: verifierPrivateKey})
260-
verifierIdentityKey, _ := verifierWallet.GetPublicKey(ctx, wallet.GetPublicKeyArgs{IdentityKey: true}, "")
258+
// Use CompletedProtoWallet for the verifier
259+
verifierWallet, _ := certificates.NewCompletedProtoWallet(verifierPrivateKey)
260+
verifierIdentityKey, _ := verifierWallet.GetPublicKey(ctx, wallet.GetPublicKeyArgs{IdentityKey: true, ForSelf: false}, "go-sdk")
261261
verifierCounterparty := wallet.Counterparty{Type: wallet.CounterpartyTypeOther, Counterparty: verifierIdentityKey.PublicKey}
262262

263263
t.Run("should create a verifier keyring for specified fields", func(t *testing.T) {
@@ -287,8 +287,37 @@ func TestMasterCertificate(t *testing.T) {
287287
t.Error("Expected keyring to contain 'name' key")
288288
}
289289

290-
// TODO: When VerifiableCertificate is implemented, create one and test decryption
291-
// by the verifierWallet using the keyringForVerifier.
290+
// Test VerifiableCertificate decryption using the verifierWallet and keyringForVerifier
291+
verifiableCert := certificates.NewVerifiableCertificate(&issueCert.Certificate, keyringForVerifier)
292+
293+
decryptedFields, err := verifiableCert.DecryptFields(
294+
t.Context(),
295+
verifierWallet,
296+
false,
297+
"",
298+
)
299+
if err != nil {
300+
t.Fatalf("VerifiableCertificate.DecryptFields failed: %v", err)
301+
}
302+
303+
// Verify that only the revealed field was decrypted
304+
if len(decryptedFields) != 1 {
305+
t.Errorf("Expected 1 decrypted field, got %d", len(decryptedFields))
306+
}
307+
308+
expectedValue := plainFieldsKrStr["name"]
309+
if decryptedFields["name"] != expectedValue {
310+
t.Errorf("Expected decrypted field 'name' to be '%s', got '%s'", expectedValue, decryptedFields["name"])
311+
}
312+
313+
// Verify that DecryptedFields was populated on the VerifiableCertificate
314+
if verifiableCert.DecryptedFields == nil {
315+
t.Error("Expected VerifiableCertificate.DecryptedFields to be populated")
316+
} else if len(verifiableCert.DecryptedFields) != 1 {
317+
t.Errorf("Expected VerifiableCertificate.DecryptedFields to have 1 field, got %d", len(verifiableCert.DecryptedFields))
318+
} else if verifiableCert.DecryptedFields["name"] != expectedValue {
319+
t.Errorf("Expected VerifiableCertificate.DecryptedFields['name'] to be '%s', got '%s'", expectedValue, verifiableCert.DecryptedFields["name"])
320+
}
292321
})
293322

294323
t.Run("should return error if fields to reveal are not a subset", func(t *testing.T) {

compat/bip32/hd_key_test.go

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -224,26 +224,6 @@ func TestGetHDKeyByPath(t *testing.T) {
224224
require.NoError(t, err)
225225
assert.NotNil(t, validKey)
226226

227-
// Max depth key
228-
/*
229-
var maxKey *ExtendedKey
230-
maxKey, err = GetHDKeyByPath(validKey, 1<<9, 1<<9)
231-
if err != nil {
232-
t.Fatalf("error occurred: %s", err.Error())
233-
}
234-
*/
235-
236-
// Test depth limit
237-
// todo: make a better test (after 126 maxKey is now nil)
238-
/*
239-
for i := 0; i < 1<<8-1; i++ {
240-
maxKey, err = GetHDKeyByPath(maxKey, uint32(i), uint32(i))
241-
if i >= 126 && err == nil {
242-
t.Fatalf("expected to hit depth limit on HD key index: %d", i)
243-
}
244-
}
245-
*/
246-
247227
var tests = []struct {
248228
inputHDKey *compat.ExtendedKey
249229
inputChain uint32
@@ -327,32 +307,6 @@ func TestGetHDKeyChild(t *testing.T) {
327307
require.NoError(t, err)
328308
assert.NotNil(t, validKey)
329309

330-
// Max depth key
331-
/*
332-
var maxKey *ExtendedKey
333-
maxKey, err = GetHDKeyByPath(validKey, 1<<9, 1<<9)
334-
if err != nil {
335-
t.Fatalf("error occurred: %s", err.Error())
336-
}
337-
*/
338-
339-
// Test depth limit
340-
// todo: make a better test (after 126 maxKey is now nil)
341-
/*
342-
for i := 0; i < 1<<8-1; i++ {
343-
maxKey, err = GetHDKeyChild(maxKey, uint32(i))
344-
if i < 126 && err != nil {
345-
t.Fatalf("error occurred: %s", err.Error())
346-
}
347-
// TODO: make this better rather than grabbing the child twice. This is
348-
// basically a copy of the GetHDKeyByPath test
349-
maxKey, err = GetHDKeyChild(maxKey, uint32(i))
350-
if i >= 126 && err == nil {
351-
t.Fatalf("expected to hit depth limit on HD key index: %d", i)
352-
}
353-
}
354-
*/
355-
356310
var tests = []struct {
357311
inputHDKey *compat.ExtendedKey
358312
inputNum uint32

identity/client.go

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ import (
2525

2626
// Client lets you discover who others are, and let the world know who you are.
2727
type Client struct {
28-
wallet wallet.Interface
29-
options IdentityClientOptions
30-
originator OriginatorDomainNameStringUnder250Bytes
28+
Wallet wallet.Interface
29+
Options IdentityClientOptions
30+
Originator OriginatorDomainNameStringUnder250Bytes
3131
}
3232

3333
// NewClient creates a new IdentityClient with the provided wallet and options
@@ -57,9 +57,9 @@ func NewClient(w wallet.Interface, options *IdentityClientOptions, originator Or
5757
}
5858

5959
return &Client{
60-
wallet: w,
61-
options: *options,
62-
originator: originator,
60+
Wallet: w,
61+
Options: *options,
62+
Originator: originator,
6363
}, nil
6464
}
6565

@@ -107,11 +107,11 @@ func (c *Client) PubliclyRevealAttributes(
107107
}
108108

109109
// Get keyring for verifier through certificate proving
110-
proveResult, err := c.wallet.ProveCertificate(ctx, wallet.ProveCertificateArgs{
110+
proveResult, err := c.Wallet.ProveCertificate(ctx, wallet.ProveCertificateArgs{
111111
Certificate: *certificate,
112112
FieldsToReveal: fieldNamesAsStrings,
113113
Verifier: dummyPk.PubKey(),
114-
}, string(c.originator))
114+
}, string(c.Originator))
115115
if err != nil {
116116
return nil, nil, fmt.Errorf("failed to prove certificate: %w", err)
117117
}
@@ -141,16 +141,16 @@ func (c *Client) PubliclyRevealAttributes(
141141

142142
// Create PushDrop with the certificate data
143143
pushDropTemplate := &pushdrop.PushDropTemplate{
144-
Wallet: c.wallet,
145-
Originator: string(c.originator),
144+
Wallet: c.Wallet,
145+
Originator: string(c.Originator),
146146
}
147147

148148
// Create locking script using PushDrop with the certificate JSON
149149
lockingScript, err := pushDropTemplate.Lock(
150150
ctx,
151151
[][]byte{certJSON},
152-
c.options.ProtocolID,
153-
c.options.KeyID,
152+
c.Options.ProtocolID,
153+
c.Options.KeyID,
154154
wallet.Counterparty{Type: wallet.CounterpartyTypeAnyone},
155155
true,
156156
true,
@@ -161,19 +161,19 @@ func (c *Client) PubliclyRevealAttributes(
161161
}
162162

163163
// Create a transaction with the certificate as an output
164-
createResult, err := c.wallet.CreateAction(ctx, wallet.CreateActionArgs{
164+
createResult, err := c.Wallet.CreateAction(ctx, wallet.CreateActionArgs{
165165
Description: "Create a new Identity Token",
166166
Outputs: []wallet.CreateActionOutput{
167167
{
168-
Satoshis: c.options.TokenAmount,
168+
Satoshis: c.Options.TokenAmount,
169169
LockingScript: lockingScript.Bytes(),
170170
OutputDescription: "Identity Token",
171171
},
172172
},
173173
Options: &wallet.CreateActionOptions{
174174
RandomizeOutputs: util.BoolPtr(false),
175175
},
176-
}, string(c.originator))
176+
}, string(c.Originator))
177177
if err != nil {
178178
return nil, nil, fmt.Errorf("failed to create action: %w", err)
179179
}
@@ -189,7 +189,7 @@ func (c *Client) PubliclyRevealAttributes(
189189
}
190190

191191
// Submit the transaction to an overlay
192-
networkResult, err := c.wallet.GetNetwork(ctx, nil, string(c.originator))
192+
networkResult, err := c.Wallet.GetNetwork(ctx, nil, string(c.Originator))
193193
if err != nil {
194194
return nil, nil, fmt.Errorf("failed to get network: %w", err)
195195
}
@@ -242,7 +242,7 @@ func (c *Client) ResolveByIdentityKey(
242242
ctx context.Context,
243243
args wallet.DiscoverByIdentityKeyArgs,
244244
) ([]DisplayableIdentity, error) {
245-
result, err := c.wallet.DiscoverByIdentityKey(ctx, args, string(c.originator))
245+
result, err := c.Wallet.DiscoverByIdentityKey(ctx, args, string(c.Originator))
246246
if err != nil {
247247
return nil, err
248248
}
@@ -260,7 +260,7 @@ func (c *Client) ResolveByAttributes(
260260
ctx context.Context,
261261
args wallet.DiscoverByAttributesArgs,
262262
) ([]DisplayableIdentity, error) {
263-
result, err := c.wallet.DiscoverByAttributes(ctx, args, string(c.originator))
263+
result, err := c.Wallet.DiscoverByAttributes(ctx, args, string(c.Originator))
264264
if err != nil {
265265
return nil, err
266266
}
@@ -284,42 +284,42 @@ func (c *Client) parseIdentity(identity *wallet.IdentityCertificate) Displayable
284284
avatarURL = identity.DecryptedFields["profilePhoto"]
285285
badgeLabel = fmt.Sprintf("X account certified by %s", identity.CertifierInfo.Name)
286286
badgeIconURL = identity.CertifierInfo.IconUrl
287-
badgeClickURL = "https://socialcert.net" // TODO Make a specific page for this.
287+
badgeClickURL = "https://socialcert.net"
288288

289289
case KnownIdentityTypes.DiscordCert:
290290
name = identity.DecryptedFields["userName"]
291291
avatarURL = identity.DecryptedFields["profilePhoto"]
292292
badgeLabel = fmt.Sprintf("Discord account certified by %s", identity.CertifierInfo.Name)
293293
badgeIconURL = identity.CertifierInfo.IconUrl
294-
badgeClickURL = "https://socialcert.net" // TODO Make a specific page for this.
294+
badgeClickURL = "https://socialcert.net"
295295

296296
case KnownIdentityTypes.EmailCert:
297297
name = identity.DecryptedFields["email"]
298298
avatarURL = "XUTZxep7BBghAJbSBwTjNfmcsDdRFs5EaGEgkESGSgjJVYgMEizu"
299299
badgeLabel = fmt.Sprintf("Email certified by %s", identity.CertifierInfo.Name)
300300
badgeIconURL = identity.CertifierInfo.IconUrl
301-
badgeClickURL = "https://socialcert.net" // TODO Make a specific page for this.
301+
badgeClickURL = "https://socialcert.net"
302302

303303
case KnownIdentityTypes.PhoneCert:
304304
name = identity.DecryptedFields["phoneNumber"]
305305
avatarURL = "XUTLxtX3ELNUwRhLwL7kWNGbdnFM8WG2eSLv84J7654oH8HaJWrU"
306306
badgeLabel = fmt.Sprintf("Phone certified by %s", identity.CertifierInfo.Name)
307307
badgeIconURL = identity.CertifierInfo.IconUrl
308-
badgeClickURL = "https://socialcert.net" // TODO Make a specific page for this.
308+
badgeClickURL = "https://socialcert.net"
309309

310310
case KnownIdentityTypes.IdentiCert:
311311
name = fmt.Sprintf("%s %s", identity.DecryptedFields["firstName"], identity.DecryptedFields["lastName"])
312312
avatarURL = identity.DecryptedFields["profilePhoto"]
313313
badgeLabel = fmt.Sprintf("Government ID certified by %s", identity.CertifierInfo.Name)
314314
badgeIconURL = identity.CertifierInfo.IconUrl
315-
badgeClickURL = "https://identicert.me" // TODO Make a specific page for this.
315+
badgeClickURL = "https://identicert.me"
316316

317317
case KnownIdentityTypes.Registrant:
318318
name = identity.DecryptedFields["name"]
319319
avatarURL = identity.DecryptedFields["icon"]
320320
badgeLabel = fmt.Sprintf("Entity certified by %s", identity.CertifierInfo.Name)
321321
badgeIconURL = identity.CertifierInfo.IconUrl
322-
badgeClickURL = "https://projectbabbage.com/docs/registrant" // TODO: Make this doc page exist
322+
badgeClickURL = "https://projectbabbage.com/docs/registrant"
323323

324324
case KnownIdentityTypes.CoolCert:
325325
if identity.DecryptedFields["cool"] == "true" {
@@ -333,14 +333,14 @@ func (c *Client) parseIdentity(identity *wallet.IdentityCertificate) Displayable
333333
avatarURL = "XUT4bpQ6cpBaXi1oMzZsXfpkWGbtp2JTUYAoN7PzhStFJ6wLfoeR"
334334
badgeLabel = "Represents the ability for anyone to access this information."
335335
badgeIconURL = "XUUV39HVPkpmMzYNTx7rpKzJvXfeiVyQWg2vfSpjBAuhunTCA9uG"
336-
badgeClickURL = "https://projectbabbage.com/docs/anyone-identity" // TODO: Make this doc page exist
336+
badgeClickURL = "https://projectbabbage.com/docs/anyone-identity"
337337

338338
case KnownIdentityTypes.Self:
339339
name = "You"
340340
avatarURL = "XUT9jHGk2qace148jeCX5rDsMftkSGYKmigLwU2PLLBc7Hm63VYR"
341341
badgeLabel = "Represents your ability to access this information."
342342
badgeIconURL = "XUUV39HVPkpmMzYNTx7rpKzJvXfeiVyQWg2vfSpjBAuhunTCA9uG"
343-
badgeClickURL = "https://projectbabbage.com/docs/self-identity" // TODO: Make this doc page exist
343+
badgeClickURL = "https://projectbabbage.com/docs/self-identity"
344344

345345
default:
346346
name = DefaultIdentity.Name

identity/testable_client.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ func (v *DefaultCertificateVerifier) Verify(ctx context.Context, certificate *wa
3131
// For now, since we can't access the actual implementation in the tests,
3232
// we'll just return nil (successful verification)
3333
// In a production environment, this would be replaced with proper certificate verification
34-
// TODO: Implement proper certificate verification
3534
return nil
3635
}
3736

@@ -113,27 +112,27 @@ func (c *TestableIdentityClient) PubliclyRevealAttributes(
113112
return nil, nil, fmt.Errorf("failed to create dummy key: %w", err)
114113
}
115114

116-
_, err = c.wallet.ProveCertificate(ctx, wallet.ProveCertificateArgs{
115+
_, err = c.Wallet.ProveCertificate(ctx, wallet.ProveCertificateArgs{
117116
Certificate: *certificate,
118117
FieldsToReveal: fieldNamesAsStrings,
119118
Verifier: dummyPk.PubKey(),
120-
}, string(c.originator))
119+
}, string(c.Originator))
121120
if err != nil {
122121
return nil, nil, fmt.Errorf("failed to prove certificate: %w", err)
123122
}
124123

125124
// Create PushDrop with the certificate data
126125
pushDropTemplate := &pushdrop.PushDropTemplate{
127-
Wallet: c.wallet,
128-
Originator: string(c.originator),
126+
Wallet: c.Wallet,
127+
Originator: string(c.Originator),
129128
}
130129

131130
// Create locking script using PushDrop with the certificate JSON
132131
lockingScript, err := pushDropTemplate.Lock(
133132
ctx,
134133
[][]byte{[]byte("test-cert-data")}, // Simplified for testing
135-
c.options.ProtocolID,
136-
c.options.KeyID,
134+
c.Options.ProtocolID,
135+
c.Options.KeyID,
137136
wallet.Counterparty{Type: wallet.CounterpartyTypeAnyone},
138137
true,
139138
true,
@@ -144,19 +143,19 @@ func (c *TestableIdentityClient) PubliclyRevealAttributes(
144143
}
145144

146145
// Create a transaction with the certificate as an output
147-
createResult, err := c.wallet.CreateAction(ctx, wallet.CreateActionArgs{
146+
createResult, err := c.Wallet.CreateAction(ctx, wallet.CreateActionArgs{
148147
Description: "Create a new Identity Token",
149148
Outputs: []wallet.CreateActionOutput{
150149
{
151-
Satoshis: c.options.TokenAmount,
150+
Satoshis: c.Options.TokenAmount,
152151
LockingScript: lockingScript.Bytes(),
153152
OutputDescription: "Identity Token",
154153
},
155154
},
156155
Options: &wallet.CreateActionOptions{
157156
RandomizeOutputs: util.BoolPtr(false),
158157
},
159-
}, string(c.originator))
158+
}, string(c.Originator))
160159
if err != nil {
161160
return nil, nil, fmt.Errorf("failed to create action: %w", err)
162161
}
@@ -172,7 +171,7 @@ func (c *TestableIdentityClient) PubliclyRevealAttributes(
172171
}
173172

174173
// Submit the transaction to an overlay
175-
networkResult, err := c.wallet.GetNetwork(ctx, nil, string(c.originator))
174+
networkResult, err := c.Wallet.GetNetwork(ctx, nil, string(c.Originator))
176175
if err != nil {
177176
return nil, nil, fmt.Errorf("failed to get network: %w", err)
178177
}

primitives/ec/precompute.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package primitives
22

3-
// TODO: Move to license file
43
// Copyright 2015 The btcsuite developers
54
// Use of this source code is governed by an ISC
65
// license that can be found in the LICENSE file.

primitives/ec/publickey.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ func (p *PublicKey) ToDERHex() string {
301301
return hex.EncodeToString(p.ToDER())
302302
}
303303

304+
// DeriveChild derives a new public key from this public key and the given private key
304305
func (p *PublicKey) DeriveChild(privateKey *PrivateKey, invoiceNumber string) (*PublicKey, error) {
305306
invoiceNumberBin := []byte(invoiceNumber)
306307
sharedSecret, err := p.DeriveSharedSecret(privateKey)
@@ -319,9 +320,7 @@ func (p *PublicKey) DeriveChild(privateKey *PrivateKey, invoiceNumber string) (*
319320
}, nil
320321
}
321322

322-
// TODO: refactor to have 1 function for both private and public key
323-
// call it multiply point with scalar or something and pass in private key
324-
// and public key
323+
// DeriveSharedSecret derives a shared secret from this public key and the given private key.
325324
func (p *PublicKey) DeriveSharedSecret(priv *PrivateKey) (*PublicKey, error) {
326325
if !p.IsOnCurve(p.X, p.Y) {
327326
return nil, errors.New("public key not valid for secret derivation")

0 commit comments

Comments
 (0)