-
Notifications
You must be signed in to change notification settings - Fork 42
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
Conversation
164ea2e
to
673afc8
Compare
31ef3d7
to
f118dc4
Compare
f118dc4
to
827eb68
Compare
``` | ||
|
||
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" }); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
const coinbase = Coinbase.configureFromJson({ filePath: "path/to/your/api-key.json" }); | |
const coinbase = new Coinbase({ apiKeyName, privateKey }); |
src/coinbase/coinbase.ts
Outdated
@@ -52,23 +51,28 @@ export class Coinbase { | |||
*/ | |||
static apiKeyPrivateKey: string; | |||
|
|||
/** | |||
* Whether to use server signer or not. |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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
src/coinbase/coinbase.ts
Outdated
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) { |
src/coinbase/coinbase.ts
Outdated
debugging: boolean = false, | ||
basePath: string = BASE_PATH, | ||
): Coinbase { | ||
static configureFromJson(options: CoinbaseConfigureFromJsonOptions): Coinbase { |
There was a problem hiding this comment.
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
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); | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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" }); |
There was a problem hiding this comment.
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.
What changed? Why?
CoinbaseOptions
andCoinbaseConfigureFromJsonOptions
types to pass to SDK initializersQualified Impact