Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PSDK-187] Server Signer Support #42

Merged
merged 9 commits into from
Jun 3, 2024
Merged

Conversation

John-peterson-coinbase
Copy link
Contributor

@John-peterson-coinbase John-peterson-coinbase commented May 31, 2024

What changed? Why?

  • Adds support for server signers.
  • Adds CoinbaseOptions and CoinbaseConfigureFromJsonOptions types to pass to SDK initializers

Qualified Impact

@John-peterson-coinbase John-peterson-coinbase changed the title 🚧[WIP] [PSDK-187] Server Signer Support 🚧 [PSDK-187] Server Signer Support Jun 3, 2024
@John-peterson-coinbase John-peterson-coinbase marked this pull request as ready for review June 3, 2024 03:09
@jazz-cb jazz-cb requested review from erdimaden and alex-stone June 3, 2024 14:12
```

Another way to initialize the SDK is by sourcing the API key from the json file that contains your API key, downloaded from CDP portal.

```typescript
const coinbase = Coinbase.configureFromJson("path/to/your/api-key.json");
const coinbase = Coinbase.configureFromJson({ filePath: "path/to/your/api-key.json" });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should fix this in docs as well if this is the case @erdimaden

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed, we need to update the docs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 docs need to be updated to use new paradigm

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@John-peterson-coinbase let's use privateKey instead of apiKeyPrivateKey so we can just use

Suggested change
const coinbase = Coinbase.configureFromJson({ filePath: "path/to/your/api-key.json" });
const coinbase = new Coinbase({ apiKeyName, privateKey });

@@ -52,23 +51,28 @@ export class Coinbase {
*/
static apiKeyPrivateKey: string;

/**
* Whether to use server signer or not.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: whether to use a server signer to manage private keys.

const broadcastTransferRequest = {
signed_payload: signedPayload,
};
if (!Coinbase.useServerSigner) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we just need to return the transfer here if(Coinbase.useServerSigner)

https://github.com/coinbase/coinbase-sdk-ruby/blob/v0.0.6/lib/coinbase/address.rb#L89

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use native async/await primitives on node.js side so we cannot just return the transfer.


const startTime = Date.now();
while (Date.now() - startTime < timeoutSeconds * 1000) {
const status = await updatedTransfer.getStatus();
await transfer.reload();
const status = transfer.getStatus();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to call transfer.reload() for if(Coinbase.useServerSigner)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes because that is how we update the state of the transfer

Comment on lines 69 to 74
constructor(options: CoinbaseOptions) {
const apiKeyName = options.apiKeyName ?? "";
const privateKey = options.privateKey ?? "";
const useServerSigner = options.useServerSigner === true;
const debugging = options.debugging === true;
const basePath = options.basePath ?? BASE_PATH;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
constructor(options: CoinbaseOptions) {
const apiKeyName = options.apiKeyName ?? "";
const privateKey = options.privateKey ?? "";
const useServerSigner = options.useServerSigner === true;
const debugging = options.debugging === true;
const basePath = options.basePath ?? BASE_PATH;
constructor({apiKeyName, privateKey, useServerSigner, useServerSigner, debugging = true, basePath= BASE_PATH}: CoinbaseOptions) {

debugging: boolean = false,
basePath: string = BASE_PATH,
): Coinbase {
static configureFromJson(options: CoinbaseConfigureFromJsonOptions): Coinbase {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the same object destructuring can be here

Comment on lines +104 to +111
const startTime = Date.now();
while (Date.now() - startTime < timeoutSeconds * 1000) {
const response = await Coinbase.apiClients.wallet!.getWallet(walletId);
if (response?.data.server_signer_status === ServerSignerStatus.ACTIVE) {
return;
}
await delay(intervalSeconds);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we have a generic util function for this logic? we use the exactly same in address class.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes lets follow up with this change since it'll add scope outside of server signer support to change in transfers etc

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to splitting out the logic however

```

Another way to initialize the SDK is by sourcing the API key from the json file that contains your API key, downloaded from CDP portal.

```typescript
const coinbase = Coinbase.configureFromJson("path/to/your/api-key.json");
const coinbase = Coinbase.configureFromJson({ filePath: "path/to/your/api-key.json" });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed, we need to update the docs.

@John-peterson-coinbase John-peterson-coinbase merged commit 048c586 into v0.0.6 Jun 3, 2024
3 checks passed
@erdimaden erdimaden deleted the feat/serversigner branch June 21, 2024 18:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants