Class: CairoSecp256k1Point
Defined in: src/utils/cairoDataTypes/secp256k1Point.ts:63
A Cairo core::starknet::secp256k1::Secp256k1Point : a point on the secp256k1 curve, the one
Ethereum signs with.
A point is two 256-bit coordinates, x and y, and Cairo carries each of them as two 128-bit
limbs — so four felts in all, in the order xLow, xHigh, yLow, yHigh. The single number this
class accepts is the 512-bit concatenation x || y, x in the upper half : that is the shape an
uncompressed public key already has once its 04 prefix is dropped.
Both ways in are supported : one number, or the four limbs directly, which is how a response is read back.
Example
// one number, x in the upper 256 bits
const point = new CairoSecp256k1Point(1n);
point.toApiRequest(); // ["0", "0", "1", "0"] x = 0, y = 1
// the four limbs, as a call carries them
const same = new CairoSecp256k1Point(0, 0, 1, 0);
same.toBigInt(); // 1n
Constructors
Constructor
new CairoSecp256k1Point(
input):CairoSecp256k1Point
Defined in: src/utils/cairoDataTypes/secp256k1Point.ts:117
Build from the 512-bit number x || y, or from an object carrying the four limbs.
Parameters
input
unknown
Returns
CairoSecp256k1Point
Constructor
new CairoSecp256k1Point(
xLow,xHigh,yLow,yHigh):CairoSecp256k1Point
Defined in: src/utils/cairoDataTypes/secp256k1Point.ts:121
Build from the four limbs, in the order a contract response returns them.
Parameters
xLow
xHigh
yLow
yHigh
Returns
CairoSecp256k1Point
Properties
abiSelector
staticabiSelector:"core::starknet::secp256k1::Secp256k1Point"=Literal.Secp256k1Point
Defined in: src/utils/cairoDataTypes/secp256k1Point.ts:112
The abi type this class serializes.
Example
const result = CairoSecp256k1Point.abiSelector;
// result = "core::starknet::secp256k1::Secp256k1Point"
xLow
xLow:
bigint
Defined in: src/utils/cairoDataTypes/secp256k1Point.ts:72
The low 128 bits of the x coordinate.
Example
const result = new CairoSecp256k1Point({ xLow: 1, xHigh: 2, yLow: 3, yHigh: 4 }).xLow;
// result = 1n
xHigh
xHigh:
bigint
Defined in: src/utils/cairoDataTypes/secp256k1Point.ts:82
The high 128 bits of the x coordinate.
Example
const result = new CairoSecp256k1Point({ xLow: 1, xHigh: 2, yLow: 3, yHigh: 4 }).xHigh;
// result = 2n
yLow
yLow:
bigint
Defined in: src/utils/cairoDataTypes/secp256k1Point.ts:92
The low 128 bits of the y coordinate.
Example
const result = new CairoSecp256k1Point({ xLow: 1, xHigh: 2, yLow: 3, yHigh: 4 }).yLow;
// result = 3n
yHigh
yHigh:
bigint
Defined in: src/utils/cairoDataTypes/secp256k1Point.ts:102
The high 128 bits of the y coordinate.
Example
const result = new CairoSecp256k1Point({ xLow: 1, xHigh: 2, yLow: 3, yHigh: 4 }).yHigh;
// result = 4n
Methods
validate()
staticvalidate(input):bigint
Defined in: src/utils/cairoDataTypes/secp256k1Point.ts:205
Throw unless the value can be carried by a Secp256k1Point, and return it as a number.
Unlike the other classes here this one gives the number back rather than returning nothing : the constructor needs it, and computing it twice would mean splitting a 512-bit value twice.
Parameters
input
unknown
the 512-bit value to check
Returns
bigint
the value, once checked
Throws
when the value is null, undefined, text, '0x', of an unread type, a decimal number, or outside [0, 2^512 - 1]
Example
const result = CairoSecp256k1Point.validate('0x1234');
// result = 4660n
CairoSecp256k1Point.validate(SECP256K1_POINT_MAX + 1n);
// throws Error("input is bigger than SECP256K1_POINT_MAX")
CairoSecp256k1Point.validate('abc');
// throws Error("Invalid input: a Secp256k1Point cannot be built from text")
CairoSecp256k1Point.validate(1.5);
// throws Error("Invalid input: decimal numbers are not supported, only integers")
validateProps()
staticvalidateProps(xLow,xHigh,yLow,yHigh):object
Defined in: src/utils/cairoDataTypes/secp256k1Point.ts:246
Throw unless the four limbs can each be carried by 128 bits, and return them as numbers.
Parameters
xLow
the low 128 bits of x
xHigh
the high 128 bits of x
yLow
the low 128 bits of y
yHigh
the high 128 bits of y
Returns
object
the four limbs, checked
xLow
xLow:
bigint
xHigh
xHigh:
bigint
yLow
yLow:
bigint
yHigh
yHigh:
bigint
Throws
when a limb is null, undefined, text, '0x', not a number, a decimal number, negative, or wider than 128 bits
Example
const result = CairoSecp256k1Point.validateProps(1, 2, 3, 4);
// result = { xLow: 1n, xHigh: 2n, yLow: 3n, yHigh: 4n }
CairoSecp256k1Point.validateProps(1, 2, 3, 2n ** 128n);
// throws Error("yHigh must fit in 128 bits")
CairoSecp256k1Point.validateProps(1.5, 2, 3, 4);
// throws Error("xLow must be an integer")
CairoSecp256k1Point.validateProps('abc', 2, 3, 4);
// throws Error("xLow cannot be built from text")
is()
staticis(data):boolean
Defined in: src/utils/cairoDataTypes/secp256k1Point.ts:288
Can this value be carried by a Secp256k1Point?
The non-throwing form of CairoSecp256k1Point.validate, so it answers false for every input that one refuses, whatever the reason.
Parameters
data
any
the value to test
Returns
boolean
true when the value fits in 512 bits
Example
const result = CairoSecp256k1Point.is(SECP256K1_POINT_MAX);
// result = true
const result2 = CairoSecp256k1Point.is(SECP256K1_POINT_MAX + 1n);
// result2 = false
isAbiType()
staticisAbiType(abiType):boolean
Defined in: src/utils/cairoDataTypes/secp256k1Point.ts:309
Is this abi type the one this class serializes?
Parameters
abiType
string
the abi type to test
Returns
boolean
true for core::starknet::secp256k1::Secp256k1Point
Example
const result = CairoSecp256k1Point.isAbiType('core::starknet::secp256k1::Secp256k1Point');
// result = true
const result2 = CairoSecp256k1Point.isAbiType('core::felt252');
// result2 = false
factoryFromApiResponse()
staticfactoryFromApiResponse(responseIterator):CairoSecp256k1Point
Defined in: src/utils/cairoDataTypes/secp256k1Point.ts:324
Read one point off a contract response, advancing the iterator past its four felts.
Parameters
responseIterator
Iterator<string>
the response felts, positioned on this point
Returns
CairoSecp256k1Point
the point that was read
Example
const response = ['0x0', '0x0', '0x1', '0x0'];
const result = CairoSecp256k1Point.factoryFromApiResponse(response.values()).toBigInt();
// result = 1n
fromHex()
staticfromHex(hexString):CairoSecp256k1Point
Defined in: src/utils/cairoDataTypes/secp256k1Point.ts:415
Build from a hexadecimal string spelling the 512-bit value.
A shorter string is left-padded to the 128 hex digits a point occupies, so a small value is read as a point whose upper limbs are zero. A longer one is refused rather than truncated.
Parameters
hexString
string
the value, 0x-prefixed or not, at most 128 hex digits
Returns
CairoSecp256k1Point
the point the string spells
Throws
when the string holds more than 128 hex digits
Example
const result = CairoSecp256k1Point.fromHex('0x1').toApiRequest();
// result = ["0", "0", "1", "0"]
toBigInt()
toBigInt():
bigint
Defined in: src/utils/cairoDataTypes/secp256k1Point.ts:346
The point as the single 512-bit number x || y.
The inverse of what the constructor does with one number, so a point built that way comes back unchanged.
Returns
bigint
the two coordinates concatenated, x in the upper 256 bits
Example
const result = new CairoSecp256k1Point(1n).toBigInt();
// result = 1n
const result2 = new CairoSecp256k1Point(0, 0, 3, 0).toBigInt();
// result2 = 3n
toStruct()
toStruct():
Secp256k1PointStruct
Defined in: src/utils/cairoDataTypes/secp256k1Point.ts:361
The four limbs as hexadecimal strings.
Returns
the limbs, each 0x-prefixed and unpadded
Example
const result = new CairoSecp256k1Point({ xLow: 1, xHigh: 2, yLow: 3, yHigh: 4 }).toStruct();
// result = { xLow: "0x1", xHigh: "0x2", yLow: "0x3", yHigh: "0x4" }
toHexString()
toHexString():
string
Defined in: src/utils/cairoDataTypes/secp256k1Point.ts:379
The point in hexadecimal, without padding.
Returns
string
the 512-bit value as a 0x-prefixed hex string
Example
const result = new CairoSecp256k1Point(4660n).toHexString();
// result = "0x1234"
toApiRequest()
toApiRequest():
string[]
Defined in: src/utils/cairoDataTypes/secp256k1Point.ts:392
Serialize to the four felts a contract call carries.
Returns
string[]
the limbs as decimal strings, [xLow, xHigh, yLow, yHigh], flagged as compiled
Example
const result = new CairoSecp256k1Point({ xLow: 1, xHigh: 2, yLow: 3, yHigh: 4 }).toApiRequest();
// result = ["1", "2", "3", "4"]