Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit d1926de

Browse files
authored
WaaS Client Library v1.0.0 (#24)
1 parent 2e3b4c6 commit d1926de

File tree

61 files changed

+8813
-1792
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+8813
-1792
lines changed

auth/authenticator.go

-4
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,6 @@ func (a *Authenticator) BuildJWT(service, uri string) (string, error) {
3838
return "", fmt.Errorf("jwt: Could not decode private key")
3939
}
4040

41-
if block.Type != "ECDSA Private Key" {
42-
return "", fmt.Errorf("jwt: Bad private key type")
43-
}
44-
4541
key, err := x509.ParseECPrivateKey(block.Bytes)
4642
if err != nil {
4743
return "", fmt.Errorf("jwt: %w", err)

clients/v1/blockchain.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ func (b *BlockchainServiceClient) ListNetworks(
125125
return &networkIteratorImpl{iter: b.client.ListNetworks(ctx, req, opts...)}
126126
}
127127

128-
// GetAsset get an Asset.
128+
// GetAsset retrieves an Asset by resource name.
129129
func (b *BlockchainServiceClient) GetAsset(
130130
ctx context.Context,
131131
req *blockchainpb.GetAssetRequest,
@@ -186,3 +186,13 @@ func (b *BlockchainServiceClient) ListAssets(
186186
opts ...gax.CallOption) AssetIterator {
187187
return &assetIteratorImpl{b.client.ListAssets(ctx, req, opts...)}
188188
}
189+
190+
// BatchGetAssets returns the list of Assets indicated by the given request.
191+
func (b *BlockchainServiceClient) BatchGetAssets(
192+
ctx context.Context,
193+
req *blockchainpb.BatchGetAssetsRequest,
194+
opts ...gax.CallOption) (*blockchainpb.BatchGetAssetsResponse, error) {
195+
asset, err := b.client.BatchGetAssets(ctx, req, opts...)
196+
197+
return asset, clients.UnwrapError(err)
198+
}

clients/v1/mpc_keys.go

+221-2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ import (
55
"fmt"
66
"net/url"
77

8+
"github.com/googleapis/gax-go/v2"
9+
"google.golang.org/grpc"
10+
811
"github.com/coinbase/waas-client-library-go/clients"
912
innerClient "github.com/coinbase/waas-client-library-go/gen/go/coinbase/cloud/clients/v1"
1013
mpc_keyspb "github.com/coinbase/waas-client-library-go/gen/go/coinbase/cloud/mpc_keys/v1"
11-
"github.com/googleapis/gax-go/v2"
12-
"google.golang.org/grpc"
1314
)
1415

1516
const (
@@ -260,3 +261,221 @@ func (m *MPCKeyServiceClient) CreateSignatureOperation(name string) *WrappedCrea
260261
pathPrefix: m.pathPrefix,
261262
}
262263
}
264+
265+
// WrappedPrepareDeviceArchiveOperation wraps the long-running operation to handle
266+
// unwrapping errors and setting the LRO options.
267+
type WrappedPrepareDeviceArchiveOperation struct {
268+
*innerClient.PrepareDeviceArchiveOperation
269+
pathPrefix string
270+
}
271+
272+
// PathPrefix returns the path prefix for the operation to be used in HTTP requests.
273+
// E.g. if the path prefix is `/waas/mpc_keys`, then the request path would be:
274+
// `/waas/mpc_keys/v1/operations/<operationId>`.
275+
func (w *WrappedPrepareDeviceArchiveOperation) PathPrefix() string {
276+
return w.pathPrefix
277+
}
278+
279+
// Wait delegates to the wrapped longrunning PrepareDeviceArchiveOperation with the
280+
// override LRO options and handling unwrapping client errors.
281+
func (w *WrappedPrepareDeviceArchiveOperation) Wait(
282+
ctx context.Context,
283+
opts ...gax.CallOption,
284+
) (*mpc_keyspb.DeviceGroup, error) {
285+
deviceGroup, err := w.PrepareDeviceArchiveOperation.Wait(ctx, clients.LROOptions(w, version, opts)...)
286+
287+
return deviceGroup, clients.UnwrapError(err)
288+
}
289+
290+
// Poll delegates to the wrapped longrunning PrepareDeviceArchiveOperation with the
291+
// override LRO options and handling unwrapping client errors.
292+
func (w *WrappedPrepareDeviceArchiveOperation) Poll(
293+
ctx context.Context,
294+
opts ...gax.CallOption,
295+
) (*mpc_keyspb.DeviceGroup, error) {
296+
deviceGroup, err := w.PrepareDeviceArchiveOperation.Poll(ctx, clients.LROOptions(w, version, opts)...)
297+
298+
return deviceGroup, clients.UnwrapError(err)
299+
}
300+
301+
// PrepareDeviceArchive prepares an archive in the local storage of the given Device. The archive contains
302+
// cryptographic materials that can be used to export MPCKeys, which have the given DeviceGroup as their parent.
303+
// The Device specified in the request must be a member of this DeviceGroup and must participate
304+
// in the associated MPC operation for the archive to be prepared. After calling this,
305+
// use ListMPCOperations to poll for the pending PrepareDeviceArchive operation, and use the WaaS SDK's
306+
// ComputeMPCOperation to complete the operation. Once the operation completes, the Device can utilize the
307+
// WaaS SDK to export the private keys corresponding to each of the MPCKeys under this DeviceGroup.
308+
func (m *MPCKeyServiceClient) PrepareDeviceArchive(
309+
ctx context.Context,
310+
req *mpc_keyspb.PrepareDeviceArchiveRequest,
311+
opts ...gax.CallOption) (*WrappedPrepareDeviceArchiveOperation, error) {
312+
op, err := m.client.PrepareDeviceArchive(ctx, req, opts...)
313+
if err != nil {
314+
return nil, clients.UnwrapError(err)
315+
}
316+
317+
return &WrappedPrepareDeviceArchiveOperation{
318+
PrepareDeviceArchiveOperation: op,
319+
pathPrefix: m.pathPrefix,
320+
}, nil
321+
}
322+
323+
// PrepareDeviceArchiveOperation returns the PrepareDeviceArchiveOperation indicated by the given name.
324+
func (m *MPCKeyServiceClient) PrepareDeviceArchiveOperation(name string) *WrappedPrepareDeviceArchiveOperation {
325+
return &WrappedPrepareDeviceArchiveOperation{
326+
PrepareDeviceArchiveOperation: m.client.PrepareDeviceArchiveOperation(name),
327+
pathPrefix: m.pathPrefix,
328+
}
329+
}
330+
331+
// WrappedPrepareDeviceBackupOperation wraps the long-running operation to handle
332+
// unwrapping errors and setting the LRO options.
333+
type WrappedPrepareDeviceBackupOperation struct {
334+
*innerClient.PrepareDeviceBackupOperation
335+
pathPrefix string
336+
}
337+
338+
// PathPrefix returns the path prefix for the operation to be used in HTTP requests.
339+
// E.g. if the path prefix is `/waas/mpc_keys`, then the request path would be:
340+
// `/waas/mpc_keys/v1/operations/<operationId>`.
341+
func (w *WrappedPrepareDeviceBackupOperation) PathPrefix() string {
342+
return w.pathPrefix
343+
}
344+
345+
// Wait delegates to the wrapped longrunning PrepareDeviceBackupOperation with the
346+
// override LRO options and handling unwrapping client errors.
347+
func (w *WrappedPrepareDeviceBackupOperation) Wait(
348+
ctx context.Context,
349+
opts ...gax.CallOption,
350+
) (*mpc_keyspb.DeviceGroup, error) {
351+
deviceGroup, err := w.PrepareDeviceBackupOperation.Wait(ctx, clients.LROOptions(w, version, opts)...)
352+
353+
return deviceGroup, clients.UnwrapError(err)
354+
}
355+
356+
// Poll delegates to the wrapped longrunning PrepareDeviceBackupOperation with the
357+
// override LRO options and handling unwrapping client errors.
358+
func (w *WrappedPrepareDeviceBackupOperation) Poll(
359+
ctx context.Context,
360+
opts ...gax.CallOption,
361+
) (*mpc_keyspb.DeviceGroup, error) {
362+
deviceGroup, err := w.PrepareDeviceBackupOperation.Poll(ctx, clients.LROOptions(w, version, opts)...)
363+
364+
return deviceGroup, clients.UnwrapError(err)
365+
}
366+
367+
// PrepareDeviceBackup prepares a backup in the given Device. The backup contains certain
368+
// cryptographic materials that can be used to restore MPCKeys, which have the given DeviceGroup as their parent,
369+
// on a new Device. The Device specified in the request must be a member of this DeviceGroup and must participate
370+
// in the associated MPC operation for the backup to be prepared.
371+
// After calling this RPC, use ListMPCOperations to poll for the pending PrepareDeviceBackup operation,
372+
// and use the WaaS SDK's ComputeMPCOperation to complete the operation. Once the operation completes,
373+
// the Device can utilize WaaS SDK to download the backup bundle. We recommend storing this backup bundle securely
374+
// in a storage provider of your choice. If the user loses access to their existing Device and wants to recover
375+
// MPCKeys in the given DeviceGroup on a new Device, use AddDevice RPC on the MPCKeyService.
376+
func (m *MPCKeyServiceClient) PrepareDeviceBackup(
377+
ctx context.Context,
378+
req *mpc_keyspb.PrepareDeviceBackupRequest,
379+
opts ...gax.CallOption) (*WrappedPrepareDeviceBackupOperation, error) {
380+
op, err := m.client.PrepareDeviceBackup(ctx, req, opts...)
381+
if err != nil {
382+
return nil, clients.UnwrapError(err)
383+
}
384+
385+
return &WrappedPrepareDeviceBackupOperation{
386+
PrepareDeviceBackupOperation: op,
387+
pathPrefix: m.pathPrefix,
388+
}, nil
389+
}
390+
391+
// PrepareDeviceBackupOperation returns the PrepareDeviceBackupOperation indicated by the given name.
392+
func (m *MPCKeyServiceClient) PrepareDeviceBackupOperation(name string) *WrappedPrepareDeviceBackupOperation {
393+
return &WrappedPrepareDeviceBackupOperation{
394+
PrepareDeviceBackupOperation: m.client.PrepareDeviceBackupOperation(name),
395+
pathPrefix: m.pathPrefix,
396+
}
397+
}
398+
399+
// WrappedAddDeviceOperation wraps the long-running operation to handle
400+
// unwrapping errors and setting the LRO options.
401+
type WrappedAddDeviceOperation struct {
402+
*innerClient.AddDeviceOperation
403+
pathPrefix string
404+
}
405+
406+
// PathPrefix returns the path prefix for the operation to be used in HTTP requests.
407+
// E.g. if the path prefix is `/waas/mpc_keys`, then the request path would be:
408+
// `/waas/mpc_keys/v1/operations/<operationId>`.
409+
func (w *WrappedAddDeviceOperation) PathPrefix() string {
410+
return w.pathPrefix
411+
}
412+
413+
// Wait delegates to the wrapped longrunning AddDeviceOperation with the
414+
// override LRO options and handling unwrapping client errors.
415+
func (w *WrappedAddDeviceOperation) Wait(
416+
ctx context.Context,
417+
opts ...gax.CallOption,
418+
) (*mpc_keyspb.DeviceGroup, error) {
419+
deviceGroup, err := w.AddDeviceOperation.Wait(ctx, clients.LROOptions(w, version, opts)...)
420+
421+
return deviceGroup, clients.UnwrapError(err)
422+
}
423+
424+
// Poll delegates to the wrapped longrunning AddDeviceOperation with the
425+
// override LRO options and handling unwrapping client errors.
426+
func (w *WrappedAddDeviceOperation) Poll(
427+
ctx context.Context,
428+
opts ...gax.CallOption,
429+
) (*mpc_keyspb.DeviceGroup, error) {
430+
deviceGroup, err := w.AddDeviceOperation.Poll(ctx, clients.LROOptions(w, version, opts)...)
431+
432+
return deviceGroup, clients.UnwrapError(err)
433+
}
434+
435+
// AddDevice adds a Device to an existing DeviceGroup. Prior to this API being called, the Device must be registered using
436+
// RegisterDevice RPC. The Device must have access to the backup created with PrepareDeviceBackup RPC to compute this
437+
// operation. After calling this RPC, use ListMPCOperations to poll for the pending AddDevice operation,
438+
// and use the WaaS SDK's ComputeAddDeviceMPCOperation to complete the operation.
439+
// After the operation is computed on WaaS SDK, the Device will have access to cryptographic materials
440+
// required to process MPCOperations for this DeviceGroup.
441+
// Once the operation completes on MPCKeyService, the Device will be added to the given DeviceGroup as a new member
442+
// and all existing Devices in the DeviceGroup will stay functional.
443+
// MPCKeyService will expose RemoveDevice RPC in a future release that can remove any of the
444+
// existing Devices from the DeviceGroup.
445+
func (m *MPCKeyServiceClient) AddDevice(
446+
ctx context.Context,
447+
req *mpc_keyspb.AddDeviceRequest,
448+
opts ...gax.CallOption) (*WrappedAddDeviceOperation, error) {
449+
op, err := m.client.AddDevice(ctx, req, opts...)
450+
if err != nil {
451+
return nil, clients.UnwrapError(err)
452+
}
453+
454+
return &WrappedAddDeviceOperation{
455+
AddDeviceOperation: op,
456+
pathPrefix: m.pathPrefix,
457+
}, nil
458+
}
459+
460+
// AddDeviceOperation returns the AddDeviceOperation indicated by the given name.
461+
func (m *MPCKeyServiceClient) AddDeviceOperation(name string) *WrappedAddDeviceOperation {
462+
return &WrappedAddDeviceOperation{
463+
AddDeviceOperation: m.client.AddDeviceOperation(name),
464+
pathPrefix: m.pathPrefix,
465+
}
466+
}
467+
468+
// RevokeDevice revokes a registered Device. This operation removes the registered Device from all the DeviceGroups that it is a
469+
// part of. Once the Device is revoked, cryptographic materials in your physical Device are invalidated,
470+
// and the Device can no longer participate in any MPCOperations of the DeviceGroups it was a part of.
471+
// Use this API in scenarios such as losing the existing Device, switching to a new physical Device, etc.
472+
// Ensure that a new Device is successfully added to your DeviceGroups using the AddDevice RPC before invoking
473+
// the RevokeDevice RPC.
474+
func (m *MPCKeyServiceClient) RevokeDevice(
475+
ctx context.Context,
476+
req *mpc_keyspb.RevokeDeviceRequest,
477+
opts ...gax.CallOption) error {
478+
err := m.client.RevokeDevice(ctx, req, opts...)
479+
480+
return clients.UnwrapError(err)
481+
}

clients/v1/mpc_transactions.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@ func (w *WrappedCreateMPCTransactionOperation) Wait(
9292
ctx context.Context,
9393
opts ...gax.CallOption,
9494
) (*mpc_transactionspb.MPCTransaction, error) {
95-
deviceGroup, err := w.CreateMPCTransactionOperation.Wait(ctx, clients.LROOptions(w, version, opts)...)
95+
mpcTransaction, err := w.CreateMPCTransactionOperation.Wait(ctx, clients.LROOptions(w, version, opts)...)
9696

97-
return deviceGroup, clients.UnwrapError(err)
97+
return mpcTransaction, clients.UnwrapError(err)
9898
}
9999

100100
// Poll delegates to the wrapped longrunning CreateMPCTransactionOperation with the
@@ -103,9 +103,9 @@ func (w *WrappedCreateMPCTransactionOperation) Poll(
103103
ctx context.Context,
104104
opts ...gax.CallOption,
105105
) (*mpc_transactionspb.MPCTransaction, error) {
106-
deviceGroup, err := w.CreateMPCTransactionOperation.Poll(ctx, clients.LROOptions(w, version, opts)...)
106+
mpcTransaction, err := w.CreateMPCTransactionOperation.Poll(ctx, clients.LROOptions(w, version, opts)...)
107107

108-
return deviceGroup, clients.UnwrapError(err)
108+
return mpcTransaction, clients.UnwrapError(err)
109109
}
110110

111111
// CreateMPCTransaction creates an MPCTransaction. The long-running operation returned from this API will contain

clients/v1/mpc_wallets.go

+56-4
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@ func (w *WrappedCreateMPCWalletOperation) Wait(
9292
ctx context.Context,
9393
opts ...gax.CallOption,
9494
) (*mpc_walletspb.MPCWallet, error) {
95-
deviceGroup, err := w.CreateMPCWalletOperation.Wait(ctx, clients.LROOptions(w, version, opts)...)
95+
mpcWallet, err := w.CreateMPCWalletOperation.Wait(ctx, clients.LROOptions(w, version, opts)...)
9696

97-
return deviceGroup, clients.UnwrapError(err)
97+
return mpcWallet, clients.UnwrapError(err)
9898
}
9999

100100
// Poll delegates to the wrapped longrunning CreateMPCWalletOperation with the
@@ -103,9 +103,9 @@ func (w *WrappedCreateMPCWalletOperation) Poll(
103103
ctx context.Context,
104104
opts ...gax.CallOption,
105105
) (*mpc_walletspb.MPCWallet, error) {
106-
deviceGroup, err := w.CreateMPCWalletOperation.Poll(ctx, clients.LROOptions(w, version, opts)...)
106+
mpcWallet, err := w.CreateMPCWalletOperation.Poll(ctx, clients.LROOptions(w, version, opts)...)
107107

108-
return deviceGroup, clients.UnwrapError(err)
108+
return mpcWallet, clients.UnwrapError(err)
109109
}
110110

111111
// CreateMPCWallet creates an MPCWallet. The Device in the request must have been registered
@@ -322,3 +322,55 @@ func (m *MPCWalletServiceClient) ListBalances(
322322
opts ...gax.CallOption) BalanceIterator {
323323
return &balanceIteratorImpl{iter: m.client.ListBalances(ctx, req, opts...)}
324324
}
325+
326+
// BalanceDetailIterator is an interface for iterating through the response to ListBalanceDetails.
327+
type BalanceDetailIterator interface {
328+
// PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
329+
PageInfo() *iterator.PageInfo
330+
331+
// Next returns the next result. Its second return value is iterator.Done if there are no more
332+
// results. Once Next returns Done, all subsequent calls will return Done.
333+
Next() (*mpc_walletspb.BalanceDetail, error)
334+
335+
// Response is the raw response for the current page.
336+
// Calling Next() or InternalFetch() updates this value.
337+
Response() *mpc_walletspb.ListBalanceDetailsResponse
338+
}
339+
340+
// balanceDetailIteratorImpl is an implementation of BalanceDetailIterator that unwraps correctly.
341+
type balanceDetailIteratorImpl struct {
342+
iter *innerClient.BalanceDetailIterator
343+
}
344+
345+
// PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
346+
func (n *balanceDetailIteratorImpl) PageInfo() *iterator.PageInfo {
347+
return n.iter.PageInfo()
348+
}
349+
350+
// Next returns the next result. Its second return value is iterator.Done if there are no more
351+
// results. Once Next returns Done, all subsequent calls will return Done.
352+
func (n *balanceDetailIteratorImpl) Next() (*mpc_walletspb.BalanceDetail, error) {
353+
balanceDetail, err := n.iter.Next()
354+
355+
return balanceDetail, clients.UnwrapError(err)
356+
}
357+
358+
// Response is the raw response for the current page.
359+
// Calling Next() or InternalFetch() updates this value.
360+
func (n *balanceDetailIteratorImpl) Response() *mpc_walletspb.ListBalanceDetailsResponse {
361+
if n.iter.Response == nil {
362+
return nil
363+
}
364+
365+
response := n.iter.Response.(*mpc_walletspb.ListBalanceDetailsResponse)
366+
367+
return response
368+
}
369+
370+
// ListBalanceDetails lists BalanceDetails.
371+
func (m *MPCWalletServiceClient) ListBalanceDetails(
372+
ctx context.Context,
373+
req *mpc_walletspb.ListBalanceDetailsRequest,
374+
opts ...gax.CallOption) BalanceDetailIterator {
375+
return &balanceDetailIteratorImpl{iter: m.client.ListBalanceDetails(ctx, req, opts...)}
376+
}

clients/v1/protocols.go

+11
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,14 @@ func (b *ProtocolServiceClient) BroadcastTransaction(
9797

9898
return transaction, clients.UnwrapError(err)
9999
}
100+
101+
// EstimateFee estimates the current network fee for the specified Network. For EVM Networks, this
102+
// corresponds to the gas_price, max_fee_per_gas, and max_priority_fee_per_gas.
103+
func (b *ProtocolServiceClient) EstimateFee(
104+
ctx context.Context,
105+
req *protocolspb.EstimateFeeRequest,
106+
opts ...gax.CallOption) (*protocolspb.EstimateFeeResponse, error) {
107+
response, err := b.client.EstimateFee(ctx, req, opts...)
108+
109+
return response, clients.UnwrapError(err)
110+
}

0 commit comments

Comments
 (0)