-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
[SDK] sdk v2 account classes #10005
[SDK] sdk v2 account classes #10005
Conversation
return authKey.data; | ||
} | ||
|
||
sign(data: Uint8Array): Hex { |
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 was hesitating whether I want this data input to be Uint8Array
or HexInput
* @returns Hex - public key of the account | ||
*/ | ||
get publicKey(): Hex { | ||
return new Hex({ data: this._signingKey.publicKey }); |
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 using obj for argument for a single input param seems odd. Personally I would love to see single input param without obj
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 we all mentioned it at some point... decided to keep it as is and later, when we actually test the sdk_v2 and use it we can decide how it is from a dev user perspective
c0bf162
to
109d06b
Compare
static fromPrivateKey(privateKey: HexInput): Account { | ||
const privatekeyHex = Hex.fromHexInput({ hexInput: privateKey }); |
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 see there are many places where we have to build the Hex
from HexInput
. I wonder if we can just accept the Hex
type as argument?
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.
Hex is not a type but a Class. The whole idea is to use HexInput and then transform it to the desired format, this enables the greatest flexibility for the developer.
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.
Beyond that, please make this take in an object as the argument. I know it's weird but we agreed we'd try this lol, let's see how it goes.
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.
Yep gotcha!
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.
Looking good! I'd love to see examples in all of the doc comments on the public constructor methods.
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import nacl from "tweetnacl"; | ||
import * as bip39 from "@scure/bip39"; |
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.
Any reason we don't just import bip39 and do bip39.blah
? I feel like it'd be more readable, I'd rather we avoid import * from x
.
import { HexInput } from "../types"; | ||
|
||
/** | ||
* Class for creating and managing account on Aptos network |
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.
* Class for creating and managing account on Aptos network | |
* Class for creating and managing an account on Aptos network |
import { HexInput } from "../types"; | ||
|
||
/** | ||
* Class for creating and managing account on Aptos network |
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 you clarify that creating an instance of this account doesn't create an instance of the account on the network. Some more examples in the doc comment here would be nice, e.g. how to use this to create an account on the network, getting account address, etc.
*/ | ||
export class Account { | ||
/** | ||
* signing key of the account, which holds the public and private key |
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.
* signing key of the account, which holds the public and private key | |
* Signing key of the account, which holds the public and private key |
private readonly _signingKey: nacl.SignKeyPair; | ||
|
||
/** | ||
* Account address associated with the account |
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.
Maybe some more information and a link to the docs site explaining why this is necessary and can't just be derived from the private / public keys (because of rotation).
* | ||
* @returns Hex - private key of the account | ||
*/ | ||
get privateKey(): Hex { |
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.
Personally I think getters suck, I prefer just a good old function. Do we have guidelines on this Maayan?
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.
Yeah I am thinking of using getter here b/c that private and public key came from _signingKey
. Not sure if we want to make the signingKey
as public. Any thoughts?
static fromPrivateKey(privateKey: HexInput): Account { | ||
const privatekeyHex = Hex.fromHexInput({ hexInput: privateKey }); |
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.
Beyond that, please make this take in an object as the argument. I know it's weird but we agreed we'd try this lol, let's see how it goes.
* Creates new account with provided private key and address | ||
* This is intended to be used for account that has it's key rotated |
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.
* Creates new account with provided private key and address | |
* This is intended to be used for account that has it's key rotated | |
* Creates a new account with the provided private key and address. | |
* This is intended to be used for an account that has had it's key rotated. |
* Creates new account with bip44 path and mnemonics, | ||
* @param path. (e.g. m/44'/637'/0'/0'/0') |
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.
* Creates new account with bip44 path and mnemonics, | |
* @param path. (e.g. m/44'/637'/0'/0'/0') | |
* Creates new account with bip44 path and mnemonics. | |
* | |
* @param path. (e.g. m/44'/637'/0'/0'/0') |
* Creates new account with bip44 path and mnemonics, | ||
* @param path. (e.g. m/44'/637'/0'/0'/0') | ||
* Detailed description: {@link https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki} | ||
* @param mnemonics. |
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.
More information about the mnemonics argument would be very helpful. If you could include examples in the doc comment that'd be great too.
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.
Make sure to use objects as parameters across the board.
} | ||
|
||
/** | ||
* Check's if the derive path is valid |
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.
* Check's if the derive path is valid | |
* Checks if the derive path is valid. |
return authKey.data; | ||
} | ||
|
||
sign(data: HexInput): Hex { |
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.
Doc comments on this and veryifySignature please captain!
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.
There seems to be a lot of duplication with #9889. If this is a stack, could you stack them properly?
This is an old PR. for the new ones, please refer to #10210 |
Description
Previous stack (Crypto classs): #9889
Account class updated to the following
Instance Method
Getter
Static Creator Methods
Static Helpers
Test Plan
PASS tests/unit/hex.test.ts
PASS tests/unit/deserializer.test.ts
PASS tests/unit/serializer.test.ts
PASS tests/unit/account_address.test.ts
PASS tests/unit/aptos_config.test.ts
PASS tests/e2e/api/account.test.ts
----------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
----------|---------|----------|---------|---------|-------------------
All files | 0 | 0 | 0 | 0 |
----------|---------|----------|---------|---------|-------------------
Test Suites: 6 passed, 6 total
Tests: 106 passed, 106 total
Snapshots: 0 total
Time: 1.748 s, estimated 34 s