Skip to main content

PrivateKey

o1js / Modules / PrivateKey

Class: PrivateKey

A signing key. You can generate one via random.

Hierarchy

Table of contents

Constructors

Properties

Methods

Constructors

constructor

new PrivateKey(s)

Parameters

NameType
sScalar

Overrides

CircuitValue.constructor

Defined in

lib/signature.ts:31

Properties

s

s: Scalar

Defined in

lib/signature.ts:29

Methods

assertEquals

assertEquals(x): void

Parameters

NameType
xPrivateKey

Returns

void

Inherited from

CircuitValue.assertEquals

Defined in

lib/circuit-value.ts:167


equals

equals(x): Bool

Parameters

NameType
xPrivateKey

Returns

Bool

Inherited from

CircuitValue.equals

Defined in

lib/circuit-value.ts:163


isConstant

isConstant(): boolean

Returns

boolean

Inherited from

CircuitValue.isConstant

Defined in

lib/circuit-value.ts:171


toBase58

toBase58(): string

Encodes a PrivateKey into a base58 string.

Returns

string

a base58 encoded string

Defined in

lib/signature.ts:111


toBigInt

toBigInt(): bigint

Convert this PrivateKey to a bigint

Returns

bigint

Defined in

lib/signature.ts:74


toConstant

toConstant(): PrivateKey

Returns

PrivateKey

Inherited from

CircuitValue.toConstant

Defined in

lib/circuit-value.ts:159


toFields

toFields(): Field[]

Returns

Field[]

Inherited from

CircuitValue.toFields

Defined in

lib/circuit-value.ts:151


toJSON

toJSON(): any

Returns

any

Inherited from

CircuitValue.toJSON

Defined in

lib/circuit-value.ts:155


toPublicKey

toPublicKey(): PublicKey

Derives the associated public key.

Returns

PublicKey

a PublicKey.

Defined in

lib/signature.ts:93


check

Static check\<T>(this, v): void

Type parameters

NameType
Textends AnyConstructor

Parameters

NameType
thisT
vInstanceType\<T>

Returns

void

Inherited from

CircuitValue.check

Defined in

lib/circuit-value.ts:200


empty

Static empty\<T>(): InstanceType\<T>

Type parameters

NameType
Textends AnyConstructor

Returns

InstanceType\<T>

Inherited from

CircuitValue.empty

Defined in

lib/circuit-value.ts:255


fromBase58

Static fromBase58(privateKeyBase58): PrivateKey

Decodes a base58 string into a PrivateKey.

Parameters

NameType
privateKeyBase58string

Returns

PrivateKey

a PrivateKey.

Defined in

lib/signature.ts:102


fromBigInt

Static fromBigInt(sk): PrivateKey

Create a PrivateKey from a bigint

Warning: Private keys should be sampled from secure randomness with sufficient entropy. Be careful that you don't use this method to create private keys that were sampled insecurely.

Parameters

NameType
skbigint

Returns

PrivateKey

Defined in

lib/signature.ts:84


fromBits

Static fromBits(bs): PrivateKey

Deserializes a list of bits into a PrivateKey.

Parameters

NameTypeDescription
bsBool[]a list of Bool.

Returns

PrivateKey

a PrivateKey.

Defined in

lib/signature.ts:67


fromFields

Static fromFields\<T>(this, xs): InstanceType\<T>

Type parameters

NameType
Textends AnyConstructor

Parameters

NameType
thisT
xsField[]

Returns

InstanceType\<T>

Inherited from

CircuitValue.fromFields

Defined in

lib/circuit-value.ts:175


fromJSON

Static fromJSON\<T>(this, value): InstanceType\<T>

Type parameters

NameType
Textends AnyConstructor

Parameters

NameType
thisT
valueany

Returns

InstanceType\<T>

Inherited from

CircuitValue.fromJSON

Defined in

lib/circuit-value.ts:233


fromObject

Static fromObject\<T>(this, value): InstanceType\<T>

Type parameters

NameType
Textends AnyConstructor

Parameters

NameType
thisT
valueNonMethods\<InstanceType\<T>>

Returns

InstanceType\<T>

Inherited from

CircuitValue.fromObject

Defined in

lib/circuit-value.ts:96


random

Static random(): PrivateKey

Generate a random private key.

You can obtain the associated public key via toPublicKey. And generate signatures via create.

Note: This uses node or browser built-in APIs to obtain cryptographically strong randomness, and can be safely used to generate a real private key.

Returns

PrivateKey

a new PrivateKey.

Defined in

lib/signature.ts:46


randomKeypair

Static randomKeypair(): Object

Create a random keypair { privateKey: PrivateKey, publicKey: PublicKey }.

Note: This uses node or browser built-in APIs to obtain cryptographically strong randomness, and can be safely used to generate a real keypair.

Returns

Object

NameType
privateKeyPrivateKey
publicKeyPublicKey

Defined in

lib/signature.ts:56


sizeInFields

Static sizeInFields(): number

Returns

number

Inherited from

CircuitValue.sizeInFields

Defined in

lib/circuit-value.ts:103


toAuxiliary

Static toAuxiliary(): []

Returns

[]

Inherited from

CircuitValue.toAuxiliary

Defined in

lib/circuit-value.ts:125


toBase58

Static toBase58(privateKey): string

Static method to encode a PrivateKey into a base58 string.

Parameters

NameType
privateKeyObject
privateKey.sScalar

Returns

string

a base58 encoded string

Defined in

lib/signature.ts:120


toConstant

Static toConstant\<T>(this, t): InstanceType\<T>

Type parameters

NameType
Textends AnyConstructor

Parameters

NameType
thisT
tInstanceType\<T>

Returns

InstanceType\<T>

Inherited from

CircuitValue.toConstant

Defined in

lib/circuit-value.ts:214


toFields

Static toFields\<T>(this, v): Field[]

Type parameters

NameType
Textends AnyConstructor

Parameters

NameType
thisT
vInstanceType\<T>

Returns

Field[]

Inherited from

CircuitValue.toFields

Defined in

lib/circuit-value.ts:108


toInput

Static toInput\<T>(this, v): HashInput

Type parameters

NameType
Textends AnyConstructor

Parameters

NameType
thisT
vInstanceType\<T>

Returns

HashInput

Inherited from

CircuitValue.toInput

Defined in

lib/circuit-value.ts:129


toJSON

Static toJSON\<T>(this, v): any

Type parameters

NameType
Textends AnyConstructor

Parameters

NameType
thisT
vInstanceType\<T>

Returns

any

Inherited from

CircuitValue.toJSON

Defined in

lib/circuit-value.ts:222