Skip to content

Commit

Permalink
chore!: account and signer updates
Browse files Browse the repository at this point in the history
BREAKING CHANGE: uses BigInt and Faster Hashing
  • Loading branch information
dhruvkelawala committed Jan 6, 2023
1 parent 6c35f61 commit be0cbe8
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 61 deletions.
8 changes: 4 additions & 4 deletions src/account/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ export class Account extends Provider implements AccountInterface {
constructor(
providerOrOptions: ProviderOptions | ProviderInterface,
address: string,
keyPairOrSigner: Uint8Array | string | SignerInterface
pkOrSigner: Uint8Array | string | SignerInterface
) {
super(providerOrOptions);
this.address = address.toLowerCase();
this.signer =
typeof keyPairOrSigner === 'string' || keyPairOrSigner instanceof Uint8Array
? new Signer(keyPairOrSigner)
: keyPairOrSigner;
typeof pkOrSigner === 'string' || pkOrSigner instanceof Uint8Array
? new Signer(pkOrSigner)
: pkOrSigner;
}

public async getNonce(blockIdentifier?: BlockIdentifier): Promise<BigNumberish> {
Expand Down
2 changes: 1 addition & 1 deletion www/docs/API/account.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ This API is the primary way to interact with an account contract on StarkNet.

To create a new instance of the Account, first an account contract must be deployed. Also there needs to be a Provider instance that will be passed in the constructor and key pair for the account.

`new starknet.Account(Provider, address, starkKeyPair)`
`new starknet.Account(Provider, address, pk)`

## Properties

Expand Down
2 changes: 1 addition & 1 deletion www/docs/API/signer.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ The **Signer** API allows you to sign transactions and messages, and also allows

## Creating an instance

`new starknet.Signer(keyPair)`
`new starknet.Signer(pk)`

## Methods

Expand Down
64 changes: 9 additions & 55 deletions www/docs/API/utils.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,11 @@ Various hashing helpers.

### starknetKeccak

`starknetKeccak(value: string): BN`
`starknetKeccak(value: string): bigint`

Function to get the starknet keccak hash from a string. Returns starknet keccak hash as BigNumber.
Function to get the starknet keccak hash from a string. Returns starknet keccak hash as bigint.

Returns starknet keccak hash as BigNumber.
Returns starknet keccak hash as bigint.

### getSelectorFromName

Expand All @@ -246,7 +246,7 @@ Returns hex selector of given abi function name.

### pedersen

`pedersen(input: [BigNumberish, BigNumberish])`
`pedersen(input: BigNumberish, BigNumberish)`

Function to get the Pedersen hash for two arguments.

Expand Down Expand Up @@ -301,61 +301,15 @@ Function that calculates contract address from hash.

Returns a string.

---

## **ellipticCurve**

Wrapper around the javascript `elliptic` library with additional functionality.

### genKeyPair

`ec.genKeyPair()`

Generate a random key pair.

### getKeyPair

`getKeyPair(pk: BigNumberish): KeyPair`

Get a key pair from a private key.

### getStarkKey

`getStarkKey(keyPair: KeyPair): string`

Public key defined over a Stark-friendly elliptic curve that is different from the standard Ethereum elliptic curve

### getKeyPairFromPublicKey
### computeContractClassHash

`getKeyPairFromPublicKey(publicKey: BigNumberish): KeyPair`
`computeContractClassHash(contract: CompiledContract | string)`

Takes a public key and casts it into `elliptic` KeyPair format.
Function that computes Class hash of a compiled contract

Returns keyPair with public key only, which can be used to verify signatures, but can't sign anything.

### sign

`sign(keyPair: KeyPair, msgHash: string): Signature`

Signs a message using the provided key.

keyPair should be an KeyPair with a valid private key.

Returns an Signature.

### verify

`verify(keyPair: KeyPair | KeyPair[], msgHash: string, sig: Signature): boolean`

Verifies a message using the provided key.

keyPair should be an KeyPair with a valid public key.

sig should be an Signature.

Returns true if the verification succeeds.
Returns a string.

<hr />
---

## **calldata**

Expand Down

0 comments on commit be0cbe8

Please sign in to comment.