Skip to content

Commit 45aea22

Browse files
authored
[SDK] Remove password arg from Lock() (#516)
* passwordless Lock() * update wasm wrapper * update index.html
1 parent e0e8ff1 commit 45aea22

File tree

10 files changed

+15
-31
lines changed

10 files changed

+15
-31
lines changed

pkg/client-sdk/ark_sdk.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ type ArkClient interface {
1515
InitWithWallet(ctx context.Context, args InitWithWalletArgs) error
1616
IsLocked(ctx context.Context) bool
1717
Unlock(ctx context.Context, password string) error
18-
Lock(ctx context.Context, password string) error
18+
Lock(ctx context.Context) error
1919
Balance(ctx context.Context, computeExpiryDetails bool) (*Balance, error)
2020
Receive(ctx context.Context) (offchainAddr, boardingAddr string, err error)
2121
SendOffChain(

pkg/client-sdk/client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ func (a *arkClient) Unlock(ctx context.Context, pasword string) error {
7979
return err
8080
}
8181

82-
func (a *arkClient) Lock(ctx context.Context, pasword string) error {
83-
return a.wallet.Lock(ctx, pasword)
82+
func (a *arkClient) Lock(ctx context.Context) error {
83+
return a.wallet.Lock(ctx)
8484
}
8585

8686
func (a *arkClient) IsLocked(ctx context.Context) bool {

pkg/client-sdk/example/covenant/alice_to_bob.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func main() {
3838
log.Fatal(err)
3939
}
4040
//nolint:all
41-
defer aliceArkClient.Lock(ctx, password)
41+
defer aliceArkClient.Lock(ctx)
4242

4343
log.Info("alice is acquiring onchain funds...")
4444
_, aliceBoardingAddr, err := aliceArkClient.Receive(ctx)
@@ -82,7 +82,7 @@ func main() {
8282
log.Fatal(err)
8383
}
8484
//nolint:all
85-
defer bobArkClient.Lock(ctx, password)
85+
defer bobArkClient.Lock(ctx)
8686

8787
bobOffchainAddr, _, err := bobArkClient.Receive(ctx)
8888
if err != nil {

pkg/client-sdk/example/covenant/wasm/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
} catch (err) {
8686
logMessage("Send error: " + err.message);
8787
} finally {
88-
await lock(password);
88+
await lock();
8989
}
9090
}
9191

@@ -133,7 +133,7 @@
133133
} catch (err) {
134134
logMessage("Onboard error: " + err.message);
135135
} finally {
136-
await lock(password);
136+
await lock();
137137
}
138138

139139
}

pkg/client-sdk/example/covenantless/alice_to_bob.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func main() {
5959
log.Fatal(err)
6060
}
6161
//nolint:all
62-
defer aliceArkClient.Lock(ctx, password)
62+
defer aliceArkClient.Lock(ctx)
6363

6464
log.Info("alice is acquiring onchain funds...")
6565
_, boardingAddress, err := aliceArkClient.Receive(ctx)
@@ -105,7 +105,7 @@ func main() {
105105
log.Fatal(err)
106106
}
107107
//nolint:all
108-
defer bobArkClient.Lock(ctx, password)
108+
defer bobArkClient.Lock(ctx)
109109

110110
bobOffchainAddr, _, err := bobArkClient.Receive(ctx)
111111
if err != nil {

pkg/client-sdk/example/covenantless/wasm/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
} catch (err) {
8787
logMessage("Send error: " + err.message);
8888
} finally {
89-
await lock(password);
89+
await lock();
9090
}
9191
}
9292

@@ -104,7 +104,7 @@
104104
} catch (err) {
105105
logMessage("Settle error: " + err.message);
106106
} finally {
107-
await lock(password);
107+
await lock();
108108
}
109109
}
110110

pkg/client-sdk/wallet/singlekey/wallet.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func (w *singlekeyWallet) Create(
6666
return hex.EncodeToString(privateKey.Serialize()), nil
6767
}
6868

69-
func (w *singlekeyWallet) Lock(_ context.Context, password string) error {
69+
func (w *singlekeyWallet) Lock(context.Context) error {
7070
if w.walletData == nil {
7171
return fmt.Errorf("wallet not initialized")
7272
}
@@ -75,13 +75,6 @@ func (w *singlekeyWallet) Lock(_ context.Context, password string) error {
7575
return nil
7676
}
7777

78-
pwd := []byte(password)
79-
currentPassHash := utils.HashPassword(pwd)
80-
81-
if !bytes.Equal(w.walletData.PasswordHash, currentPassHash) {
82-
return fmt.Errorf("invalid password")
83-
}
84-
8578
w.privateKey = nil
8679
return nil
8780
}

pkg/client-sdk/wallet/wallet.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type WalletService interface {
2121
Create(
2222
ctx context.Context, password, seed string,
2323
) (walletSeed string, err error)
24-
Lock(ctx context.Context, password string) (err error)
24+
Lock(ctx context.Context) (err error)
2525
Unlock(ctx context.Context, password string) (alreadyUnlocked bool, err error)
2626
IsLocked() bool
2727
GetAddresses(

pkg/client-sdk/wallet/wallet_test.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,7 @@ func TestWallet(t *testing.T) {
131131
require.NoError(t, err)
132132
require.True(t, alreadyUnlocked)
133133

134-
// Check no password is required to lock if wallet is already locked.
135-
err = walletSvc.Lock(ctx, password)
136-
require.NoError(t, err)
137-
138-
err = walletSvc.Lock(ctx, "")
134+
err = walletSvc.Lock(ctx)
139135
require.NoError(t, err)
140136

141137
locked := walletSvc.IsLocked()

pkg/client-sdk/wasm/browser/wrappers.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,7 @@ func UnlockWrapper() js.Func {
105105

106106
func LockWrapper() js.Func {
107107
return JSPromise(func(args []js.Value) (interface{}, error) {
108-
if len(args) != 1 {
109-
return nil, errors.New("invalid number of args")
110-
}
111-
password := args[0].String()
112-
113-
err := arkSdkClient.Lock(context.Background(), password)
108+
err := arkSdkClient.Lock(context.Background())
114109
return nil, err
115110
})
116111
}

0 commit comments

Comments
 (0)