repo_name
string
dataset
string
owner
string
lang
string
func_name
string
code
string
docstring
string
url
string
sha
string
js-wallet-sdk
github_2023
okx
typescript
Deserializer.deserializeU64
deserializeU64(): Uint64 { const low = this.deserializeU32(); const high = this.deserializeU32(); // combine the two 32-bit values and return (little endian) return BigInt((BigInt(high) << BigInt(32)) | BigInt(low)); }
/** * Deserializes a uint64 number. * * BCS layout for "uint64": Eight bytes. Binary format in little-endian representation. * @example * ```ts * const deserializer = new Deserializer(new Uint8Array([0x00, 0xEF, 0xCD, 0xAB, 0x78, 0x56, 0x34, 0x12])); * assert(deserializer.deserializeU...
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/bcs/deserializer.ts#L139-L145
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
Deserializer.deserializeU128
deserializeU128(): Uint128 { const low = this.deserializeU64(); const high = this.deserializeU64(); // combine the two 64-bit values and return (little endian) return BigInt((high << BigInt(64)) | low); }
/** * Deserializes a uint128 number. * * BCS layout for "uint128": Sixteen bytes. Binary format in little-endian representation. */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/bcs/deserializer.ts#L152-L158
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
Deserializer.deserializeU256
deserializeU256(): Uint256 { const low = this.deserializeU128(); const high = this.deserializeU128(); // combine the two 128-bit values and return (little endian) return BigInt((high << BigInt(128)) | low); }
/** * Deserializes a uint256 number. * * BCS layout for "uint256": Thirty-two bytes. Binary format in little-endian representation. */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/bcs/deserializer.ts#L165-L171
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
Deserializer.deserializeUleb128AsU32
deserializeUleb128AsU32(): Uint32 { let value: bigint = BigInt(0); let shift = 0; while (value < MAX_U32_NUMBER) { const byte = this.deserializeU8(); value |= BigInt(byte & 0x7f) << BigInt(shift); if ((byte & 0x80) === 0) { break; ...
/** * Deserializes a uleb128 encoded uint32 number. * * BCS use uleb128 encoding in two cases: (1) lengths of variable-length sequences and (2) tags of enum values */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/bcs/deserializer.ts#L178-L197
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
Deserializer.deserialize
deserialize<T>(cls: Deserializable<T>): T { // NOTE: `deserialize` in `cls.deserialize(this)` here is a static method defined in `cls`, // It is separate from the `deserialize` instance method defined here in Deserializer. return cls.deserialize(this); }
/** * Helper function that primarily exists to support alternative syntax for deserialization. * That is, if we have a `const deserializer: new Deserializer(...)`, instead of having to use * `MyClass.deserialize(deserializer)`, we can call `deserializer.deserialize(MyClass)`. * * @example const...
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/bcs/deserializer.ts#L212-L216
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
Deserializer.deserializeVector
deserializeVector<T>(cls: Deserializable<T>): Array<T> { const length = this.deserializeUleb128AsU32(); const vector = new Array<T>(); for (let i = 0; i < length; i += 1) { vector.push(this.deserialize(cls)); } return vector; }
/** * Deserializes an array of BCS Deserializable values given an existing Deserializer * instance with a loaded byte buffer. * * @param cls The BCS-deserializable class to deserialize the buffered bytes into. * @example * // serialize a vector of addresses * const addresses = new Arr...
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/bcs/deserializer.ts#L241-L248
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
Serializer.constructor
constructor(length: number = 64) { if (length <= 0) { throw new Error("Length needs to be greater than 0"); } this.buffer = new ArrayBuffer(length); this.offset = 0; }
// `length` must be greater than 0.
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/bcs/serializer.ts#L51-L57
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
Serializer.serializeStr
serializeStr(value: string) { const textEncoder = new TextEncoder(); this.serializeBytes(textEncoder.encode(value)); }
/** * Serializes a string. UTF8 string is supported. * * The number of bytes in the string content is serialized first, as a uleb128-encoded u32 integer. * Then the string content is serialized as UTF8 encoded bytes. * * BCS layout for "string": string_length | string_content * where string_length ...
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/bcs/serializer.ts#L100-L103
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
Serializer.serializeBytes
serializeBytes(value: Uint8Array) { this.serializeU32AsUleb128(value.length); this.appendToBuffer(value); }
/** * Serializes an array of bytes. * * BCS layout for "bytes": bytes_length | bytes * where bytes_length is a u32 integer encoded as a uleb128 integer, equal to the length of the bytes array. */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/bcs/serializer.ts#L111-L114
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
Serializer.serializeFixedBytes
serializeFixedBytes(value: Uint8Array) { this.appendToBuffer(value); }
/** * Serializes an array of bytes with known length. Therefore, length doesn't need to be * serialized to help deserialization. * * When deserializing, the number of bytes to deserialize needs to be passed in. */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/bcs/serializer.ts#L122-L124
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
Serializer.serializeBool
serializeBool(value: boolean) { ensureBoolean(value); const byteValue = value ? 1 : 0; this.appendToBuffer(new Uint8Array([byteValue])); }
/** * Serializes a boolean value. * * BCS layout for "boolean": One byte. "0x01" for true and "0x00" for false. */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/bcs/serializer.ts#L131-L135
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
Serializer.toUint8Array
toUint8Array(): Uint8Array { return new Uint8Array(this.buffer).slice(0, this.offset); }
/** * Returns the buffered bytes */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/bcs/serializer.ts#L250-L252
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
Serializer.serialize
serialize<T extends Serializable>(value: T): void { // NOTE: The `serialize` method called by `value` is defined in `value`'s // Serializable interface, not the one defined in this class. value.serialize(this); }
/** * Serializes a `Serializable` value, facilitating composable serialization. * * @param value The Serializable value to serialize * * @example * // Define the MoveStruct class that implements the Serializable interface * class MoveStruct extends Serializable { * constructor( * ...
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/bcs/serializer.ts#L289-L293
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
Serializer.serializeVector
serializeVector<T extends Serializable>(values: Array<T>): void { this.serializeU32AsUleb128(values.length); values.forEach((item) => { item.serialize(this); }); }
/** * Serializes an array of BCS Serializable values to a serializer instance. * Note that this does not return anything. The bytes are added to the serializer instance's byte buffer. * * @param values The array of BCS Serializable values * @example * const addresses = new Array<AccountAddress>( * ...
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/bcs/serializer.ts#L314-L319
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
checkNumberRange
function checkNumberRange<T extends AnyNumber>(minValue: T, maxValue: T) { return (target: unknown, propertyKey: string, descriptor: PropertyDescriptor) => { const childFunction = descriptor.value; // eslint-disable-next-line no-param-reassign descriptor.value = function deco(value: AnyNumber) { val...
/** * A decorator to ensure the input argument for a function is within a range. * @param minValue The input argument must be >= minValue * @param maxValue The input argument must be <= maxValue */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/bcs/serializer.ts#L343-L354
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
EntryFunctionBytes.serialize
serialize(serializer: Serializer): void { serializer.serialize(this.value); }
// representation.
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/bcs/serializable/entryFunctionBytes.ts#L35-L37
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
EntryFunctionBytes.serializeForEntryFunction
serializeForEntryFunction(serializer: Serializer): void { serializer.serializeU32AsUleb128(this.value.value.length); serializer.serialize(this); }
// class and FixedBytes.
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/bcs/serializable/entryFunctionBytes.ts#L44-L47
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
EntryFunctionBytes.deserialize
static deserialize(deserializer: Deserializer, length: number): EntryFunctionBytes { const fixedBytes = FixedBytes.deserialize(deserializer, length); return new EntryFunctionBytes(fixedBytes.value); }
/** * The only way to create an instance of this class is to use this static method. * * This function should only be used when deserializing a sequence of EntryFunctionPayload arguments. * @param deserializer the deserializer instance with the buffered bytes * @param length the length of the bytes to de...
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/bcs/serializable/entryFunctionBytes.ts#L57-L60
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
MoveVector.serializeForScriptFunction
serializeForScriptFunction(serializer: Serializer): void { // runtime check to ensure that you can't serialize anything other than vector<u8> const isU8 = this.values[0] instanceof U8; // if the inner array is length 0, we can't check the type because it has no instance, so we assume it's a u8 // it may...
/** * NOTE: This function will only work when the inner values in the `MoveVector` are `U8`s. * @param serializer */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/bcs/serializable/moveStructs.ts#L69-L80
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
MoveVector.U8
static U8(values: Array<number> | HexInput): MoveVector<U8> { let numbers: Array<number>; if (Array.isArray(values) && typeof values[0] === "number") { numbers = values; } else if (typeof values === "string") { const hex = Hex.fromHexInput(values); numbers = Array.from(hex.toUint8Array())...
/** * Factory method to generate a MoveVector of U8s from an array of numbers. * * @example * const v = MoveVector.U8([1, 2, 3, 4]); * @params values: an array of `numbers` to convert to U8s * @returns a `MoveVector<U8>` */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/bcs/serializable/moveStructs.ts#L90-L105
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
MoveVector.U16
static U16(values: Array<number>): MoveVector<U16> { return new MoveVector<U16>(values.map((v) => new U16(v))); }
/** * Factory method to generate a MoveVector of U16s from an array of numbers. * * @example * const v = MoveVector.U16([1, 2, 3, 4]); * @params values: an array of `numbers` to convert to U16s * @returns a `MoveVector<U16>` */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/bcs/serializable/moveStructs.ts#L115-L117
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
MoveVector.U32
static U32(values: Array<number>): MoveVector<U32> { return new MoveVector<U32>(values.map((v) => new U32(v))); }
/** * Factory method to generate a MoveVector of U32s from an array of numbers. * * @example * const v = MoveVector.U32([1, 2, 3, 4]); * @params values: an array of `numbers` to convert to U32s * @returns a `MoveVector<U32>` */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/bcs/serializable/moveStructs.ts#L127-L129
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
MoveVector.U64
static U64(values: Array<AnyNumber>): MoveVector<U64> { return new MoveVector<U64>(values.map((v) => new U64(v))); }
/** * Factory method to generate a MoveVector of U64s from an array of numbers or bigints. * * @example * const v = MoveVector.U64([1, 2, 3, 4]); * @params values: an array of numbers of type `number | bigint` to convert to U64s * @returns a `MoveVector<U64>` */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/bcs/serializable/moveStructs.ts#L139-L141
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
MoveVector.U128
static U128(values: Array<AnyNumber>): MoveVector<U128> { return new MoveVector<U128>(values.map((v) => new U128(v))); }
/** * Factory method to generate a MoveVector of U128s from an array of numbers or bigints. * * @example * const v = MoveVector.U128([1, 2, 3, 4]); * @params values: an array of numbers of type `number | bigint` to convert to U128s * @returns a `MoveVector<U128>` */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/bcs/serializable/moveStructs.ts#L151-L153
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
MoveVector.U256
static U256(values: Array<AnyNumber>): MoveVector<U256> { return new MoveVector<U256>(values.map((v) => new U256(v))); }
/** * Factory method to generate a MoveVector of U256s from an array of numbers or bigints. * * @example * const v = MoveVector.U256([1, 2, 3, 4]); * @params values: an array of numbers of type `number | bigint` to convert to U256s * @returns a `MoveVector<U256>` */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/bcs/serializable/moveStructs.ts#L163-L165
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
MoveVector.Bool
static Bool(values: Array<boolean>): MoveVector<Bool> { return new MoveVector<Bool>(values.map((v) => new Bool(v))); }
/** * Factory method to generate a MoveVector of Bools from an array of booleans. * * @example * const v = MoveVector.Bool([true, false, true, false]); * @params values: an array of `bools` to convert to Bools * @returns a `MoveVector<Bool>` */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/bcs/serializable/moveStructs.ts#L175-L177
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
MoveVector.MoveString
static MoveString(values: Array<string>): MoveVector<MoveString> { return new MoveVector<MoveString>(values.map((v) => new MoveString(v))); }
/** * Factory method to generate a MoveVector of MoveStrings from an array of strings. * * @example * const v = MoveVector.MoveString(["hello", "world"]); * @params values: an array of `strings` to convert to MoveStrings * @returns a `MoveVector<MoveString>` */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/bcs/serializable/moveStructs.ts#L187-L189
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
MoveVector.deserialize
static deserialize<T extends Serializable & EntryFunctionArgument>( deserializer: Deserializer, cls: Deserializable<T>, ): MoveVector<T> { const length = deserializer.deserializeUleb128AsU32(); const values = new Array<T>(); for (let i = 0; i < length; i += 1) { values.push(cls.deserialize(d...
/** * Deserialize a MoveVector of type T, specifically where T is a Serializable and Deserializable type. * * NOTE: This only works with a depth of one. Generics will not work. * * NOTE: This will not work with types that aren't of the Serializable class. * * If you're looking for a more flexible d...
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/bcs/serializable/moveStructs.ts#L212-L222
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
MoveOption.unwrap
unwrap(): T { if (!this.isSome()) { throw new Error("Called unwrap on a MoveOption with no value"); } else { return this.vec.values[0]; } }
/** * Retrieves the inner value of the MoveOption. * * This method is inspired by Rust's `Option<T>.unwrap()`. * In Rust, attempting to unwrap a `None` value results in a panic. * * Similarly, this method will throw an error if the value is not present. * * @example * const option = new MoveO...
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/bcs/serializable/moveStructs.ts#L295-L301
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
MoveOption.isSome
isSome(): boolean { return this.vec.values.length === 1; }
// Check if the MoveOption has a value.
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/bcs/serializable/moveStructs.ts#L304-L306
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
MoveOption.U8
static U8(value?: number | null): MoveOption<U8> { return new MoveOption<U8>(value !== null && value !== undefined ? new U8(value) : undefined); }
/** * Factory method to generate a MoveOption<U8> from a `number` or `undefined`. * * @example * MoveOption.U8(1).isSome() === true; * MoveOption.U8().isSome() === false; * MoveOption.U8(undefined).isSome() === false; * @params value: the value used to fill the MoveOption. If `value` is undefined ...
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/bcs/serializable/moveStructs.ts#L325-L327
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
MoveOption.U16
static U16(value?: number | null): MoveOption<U16> { return new MoveOption<U16>(value !== null && value !== undefined ? new U16(value) : undefined); }
/** * Factory method to generate a MoveOption<U16> from a `number` or `undefined`. * * @example * MoveOption.U16(1).isSome() === true; * MoveOption.U16().isSome() === false; * MoveOption.U16(undefined).isSome() === false; * @params value: the value used to fill the MoveOption. If `value` is undefin...
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/bcs/serializable/moveStructs.ts#L340-L342
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
MoveOption.U32
static U32(value?: number | null): MoveOption<U32> { return new MoveOption<U32>(value !== null && value !== undefined ? new U32(value) : undefined); }
/** * Factory method to generate a MoveOption<U32> from a `number` or `undefined`. * * @example * MoveOption.U32(1).isSome() === true; * MoveOption.U32().isSome() === false; * MoveOption.U32(undefined).isSome() === false; * @params value: the value used to fill the MoveOption. If `value` is undefin...
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/bcs/serializable/moveStructs.ts#L355-L357
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
MoveOption.U64
static U64(value?: AnyNumber | null): MoveOption<U64> { return new MoveOption<U64>(value !== null && value !== undefined ? new U64(value) : undefined); }
/** * Factory method to generate a MoveOption<U64> from a `number` or a `bigint` or `undefined`. * * @example * MoveOption.U64(1).isSome() === true; * MoveOption.U64().isSome() === false; * MoveOption.U64(undefined).isSome() === false; * @params value: the value used to fill the MoveOption. If `val...
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/bcs/serializable/moveStructs.ts#L370-L372
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
MoveOption.U128
static U128(value?: AnyNumber | null): MoveOption<U128> { return new MoveOption<U128>(value !== null && value !== undefined ? new U128(value) : undefined); }
/** * Factory method to generate a MoveOption<U128> from a `number` or a `bigint` or `undefined`. * * @example * MoveOption.U128(1).isSome() === true; * MoveOption.U128().isSome() === false; * MoveOption.U128(undefined).isSome() === false; * @params value: the value used to fill the MoveOption. If ...
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/bcs/serializable/moveStructs.ts#L385-L387
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
MoveOption.U256
static U256(value?: AnyNumber | null): MoveOption<U256> { return new MoveOption<U256>(value !== null && value !== undefined ? new U256(value) : undefined); }
/** * Factory method to generate a MoveOption<U256> from a `number` or a `bigint` or `undefined`. * * @example * MoveOption.U256(1).isSome() === true; * MoveOption.U256().isSome() === false; * MoveOption.U256(undefined).isSome() === false; * @params value: the value used to fill the MoveOption. If ...
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/bcs/serializable/moveStructs.ts#L400-L402
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
MoveOption.Bool
static Bool(value?: boolean | null): MoveOption<Bool> { return new MoveOption<Bool>(value !== null && value !== undefined ? new Bool(value) : undefined); }
/** * Factory method to generate a MoveOption<Bool> from a `boolean` or `undefined`. * * @example * MoveOption.Bool(true).isSome() === true; * MoveOption.Bool().isSome() === false; * MoveOption.Bool(undefined).isSome() === false; * @params value: the value used to fill the MoveOption. If `value` is...
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/bcs/serializable/moveStructs.ts#L415-L417
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
MoveOption.MoveString
static MoveString(value?: string | null): MoveOption<MoveString> { return new MoveOption<MoveString>(value !== null && value !== undefined ? new MoveString(value) : undefined); }
/** * Factory method to generate a MoveOption<MoveString> from a `string` or `undefined`. * * @example * MoveOption.MoveString("hello").isSome() === true; * MoveOption.MoveString("").isSome() === true; * MoveOption.MoveString().isSome() === false; * MoveOption.MoveString(undefined).isSome() === fal...
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/bcs/serializable/moveStructs.ts#L431-L433
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
AccountAddress.constructor
constructor(input: Uint8Array) { super(); if (input.length !== AccountAddress.LENGTH) { throw new ParsingError( "AccountAddress data should be exactly 32 bytes long", AddressInvalidReason.INCORRECT_NUMBER_OF_BYTES, ); } this.data = input; }
/** * Creates an instance of AccountAddress from a Uint8Array. * * @param args.data A Uint8Array representing an account address. */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/core/accountAddress.ts#L73-L82
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
AccountAddress.isSpecial
isSpecial(): boolean { return ( this.data.slice(0, this.data.length - 1).every((byte) => byte === 0) && this.data[this.data.length - 1] < 0b10000 ); }
/** * Returns whether an address is special, where special is defined as 0x0 to 0xf * inclusive. In other words, the last byte of the address must be < 0b10000 (16) * and every other byte must be zero. * * For more information on how special addresses are defined see AIP-40: * https://github.com/aptos...
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/core/accountAddress.ts#L94-L98
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
AccountAddress.toString
toString(): `0x${string}` { return `0x${this.toStringWithoutPrefix()}`; }
/** * Return the AccountAddress as a string as per AIP-40. * https://github.com/aptos-foundation/AIPs/blob/main/aips/aip-40.md. * * In short, it means that special addresses are represented in SHORT form, meaning * 0x0 through to 0xf inclusive, and every other address is represented in LONG form, * me...
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/core/accountAddress.ts#L114-L116
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
AccountAddress.toStringWithoutPrefix
toStringWithoutPrefix(): string { let hex = bytesToHex(this.data); if (this.isSpecial()) { hex = hex[hex.length - 1]; } return hex; }
/** * NOTE: Prefer to use `toString` where possible. * * Return the AccountAddress as a string as per AIP-40 but without the leading 0x. * * Learn more by reading the docstring of `toString`. * * @returns AccountAddress as a string conforming to AIP-40 but without the leading 0x. */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/core/accountAddress.ts#L127-L133
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
AccountAddress.toStringLong
toStringLong(): `0x${string}` { return `0x${this.toStringLongWithoutPrefix()}`; }
/** * NOTE: Prefer to use `toString` where possible. * * Whereas toString will format special addresses (as defined by isSpecial) using the * SHORT form (no leading 0s), this format the address in the LONG format * unconditionally. * * This means it will be 0x + 64 hex characters. * * @return...
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/core/accountAddress.ts#L146-L148
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
AccountAddress.toStringLongWithoutPrefix
toStringLongWithoutPrefix(): string { return bytesToHex(this.data); }
/** * NOTE: Prefer to use `toString` where possible. * * Whereas toString will format special addresses (as defined by isSpecial) using the * SHORT form (no leading 0s), this function will include leading zeroes. The string * will not have a leading zero. * * This means it will be 64 hex characters...
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/core/accountAddress.ts#L161-L163
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
AccountAddress.toUint8Array
toUint8Array(): Uint8Array { return this.data; }
/** * Get the inner hex data. The inner data is already a Uint8Array so no conversion * is taking place here, it just returns the inner data. * * @returns Hex data as Uint8Array */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/core/accountAddress.ts#L171-L173
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
AccountAddress.serialize
serialize(serializer: Serializer): void { serializer.serializeFixedBytes(this.data); }
/** * Serialize the AccountAddress to a Serializer instance's data buffer. * @param serializer The serializer to serialize the AccountAddress to. * @returns void * @example * const serializer = new Serializer(); * const address = AccountAddress.fromString("0x1"); * address.serialize(serializer); ...
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/core/accountAddress.ts#L186-L188
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
AccountAddress.deserialize
static deserialize(deserializer: Deserializer): AccountAddress { const bytes = deserializer.deserializeFixedBytes(AccountAddress.LENGTH); return new AccountAddress(bytes); }
/** * Deserialize an AccountAddress from the byte buffer in a Deserializer instance. * @param deserializer The deserializer to deserialize the AccountAddress from. * @returns An instance of AccountAddress. * @example * const bytes = hexToBytes("0x0102030405060708091011121314151617181920212223242526272829...
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/core/accountAddress.ts#L210-L213
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
AccountAddress.fromStringStrict
static fromStringStrict(input: string): AccountAddress { // Assert the string starts with 0x. if (!input.startsWith("0x")) { throw new ParsingError("Hex string must start with a leading 0x.", AddressInvalidReason.LEADING_ZERO_X_REQUIRED); } const address = AccountAddress.fromString(input); /...
/** * NOTE: This function has strict parsing behavior. For relaxed behavior, please use * the `fromString` function. * * Creates an instance of AccountAddress from a hex string. * * This function allows only the strictest formats defined by AIP-40. In short this * means only the following formats a...
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/core/accountAddress.ts#L246-L273
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
AccountAddress.fromString
static fromString(input: string): AccountAddress { let parsedInput = input; // Remove leading 0x for parsing. if (input.startsWith("0x")) { parsedInput = input.slice(2); } // Ensure the address string is at least 1 character long. if (parsedInput.length === 0) { throw new ParsingErr...
/** * NOTE: This function has relaxed parsing behavior. For strict behavior, please use * the `fromStringStrict` function. Where possible use `fromStringStrict` rather than this * function, `fromString` is only provided for backwards compatibility. * * Creates an instance of AccountAddress from a hex str...
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/core/accountAddress.ts#L300-L336
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
AccountAddress.from
static from(input: AccountAddressInput): AccountAddress { if (input instanceof AccountAddress) { return input; } if (input instanceof Uint8Array) { return new AccountAddress(input); } return AccountAddress.fromString(input); }
/** * Convenience method for creating an AccountAddress from all known inputs. * * This handles, Uint8array, string, and AccountAddress itself * @param input */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/core/accountAddress.ts#L344-L352
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
AccountAddress.fromStrict
static fromStrict(input: AccountAddressInput): AccountAddress { if (input instanceof AccountAddress) { return input; } if (input instanceof Uint8Array) { return new AccountAddress(input); } return AccountAddress.fromStringStrict(input); }
/** * Convenience method for creating an AccountAddress from all known inputs. * * This handles, Uint8array, string, and AccountAddress itself * @param input */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/core/accountAddress.ts#L360-L368
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
AccountAddress.isValid
static isValid(args: { input: AccountAddressInput; strict?: boolean }): ParsingResult<AddressInvalidReason> { try { if (args.strict) { AccountAddress.fromStrict(args.input); } else { AccountAddress.from(args.input); } return { valid: true }; } catch (error: any) { r...
/** * Check if the string is a valid AccountAddress. * * @param args.input A hex string representing an account address. * @param args.strict If true, use strict parsing behavior. If false, use relaxed parsing behavior. * * @returns valid = true if the string is valid, valid = false if not. If the str...
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/core/accountAddress.ts#L383-L398
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
AccountAddress.equals
equals(other: AccountAddress): boolean { if (this.data.length !== other.data.length) return false; return this.data.every((value, index) => value === other.data[index]); }
/** * Return whether AccountAddresses are equal. AccountAddresses are considered equal * if their underlying byte data is identical. * * @param other The AccountAddress to compare to. * @returns true if the AccountAddresses are equal, false if not. */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/core/accountAddress.ts#L407-L410
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
AuthenticationKey.deserialize
static deserialize(deserializer: Deserializer): AuthenticationKey { const bytes = deserializer.deserializeFixedBytes(AuthenticationKey.LENGTH); return new AuthenticationKey({ data: bytes }); }
/** * Deserialize an AuthenticationKey from the byte buffer in a Deserializer instance. * @param deserializer The deserializer to deserialize the AuthenticationKey from. * @returns An instance of AuthenticationKey. */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/core/authenticationKey.ts#L51-L54
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
AuthenticationKey.fromPublicKeyAndScheme
public static fromPublicKeyAndScheme(args: { publicKey: AccountPublicKey; scheme: AuthenticationKeyScheme }) { const { publicKey } = args; return publicKey.authKey(); }
/** * @deprecated Use `fromPublicKey` instead * Derives an AuthenticationKey from the public key seed bytes and an explicit derivation scheme. * * This facilitates targeting a specific scheme for deriving an authentication key from a public key. * * @param args - the public key and scheme to use for t...
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/core/authenticationKey.ts#L82-L85
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
AuthenticationKey.fromPublicKey
static fromPublicKey(args: { publicKey: AccountPublicKey }): AuthenticationKey { const { publicKey } = args; return publicKey.authKey(); }
/** * Converts a PublicKey(s) to an AuthenticationKey, using the derivation scheme inferred from the * instance of the PublicKey type passed in. * * @param args.publicKey * @returns AuthenticationKey */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/core/authenticationKey.ts#L94-L97
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
AuthenticationKey.derivedAddress
derivedAddress(): AccountAddress { return new AccountAddress(this.data.toUint8Array()); }
/** * Derives an account address from an AuthenticationKey. Since an AccountAddress is also 32 bytes, * the AuthenticationKey bytes are directly translated to an AccountAddress. * * @returns AccountAddress */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/core/authenticationKey.ts#L105-L107
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
Hex.constructor
constructor(data: Uint8Array) { this.data = data; }
/** * Create a new Hex instance from a Uint8Array. * * @param data Uint8Array */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/core/hex.ts#L51-L53
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
Hex.toUint8Array
toUint8Array(): Uint8Array { return this.data; }
/** * Get the inner hex data. The inner data is already a Uint8Array so no conversion * is taking place here, it just returns the inner data. * * @returns Hex data as Uint8Array */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/core/hex.ts#L65-L67
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
Hex.toStringWithoutPrefix
toStringWithoutPrefix(): string { return bytesToHex(this.data); }
/** * Get the hex data as a string without the 0x prefix. * * @returns Hex string without 0x prefix */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/core/hex.ts#L74-L76
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
Hex.toString
toString(): string { return `0x${this.toStringWithoutPrefix()}`; }
/** * Get the hex data as a string with the 0x prefix. * * @returns Hex string with 0x prefix */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/core/hex.ts#L83-L85
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
Hex.fromHexString
static fromHexString(str: string): Hex { let input = str; if (input.startsWith("0x")) { input = input.slice(2); } if (input.length === 0) { throw new ParsingError( "Hex string is too short, must be at least 1 char long, excluding the optional leading 0x.", HexInvalidReason....
/** * Static method to convert a hex string to Hex * * @param str A hex string, with or without the 0x prefix * * @returns Hex */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/core/hex.ts#L98-L124
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
Hex.fromHexInput
static fromHexInput(hexInput: HexInput): Hex { if (hexInput instanceof Uint8Array) return new Hex(hexInput); return Hex.fromHexString(hexInput); }
/** * Static method to convert an instance of HexInput to Hex * * @param hexInput A HexInput (string or Uint8Array) * * @returns Hex */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/core/hex.ts#L133-L136
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
Hex.isValid
static isValid(str: string): ParsingResult<HexInvalidReason> { try { Hex.fromHexString(str); return { valid: true }; } catch (error: any) { return { valid: false, invalidReason: error?.invalidReason, invalidReasonMessage: error?.message, }; } }
/** * Check if the string is valid hex. * * @param str A hex string representing byte data. * * @returns valid = true if the string is valid, false if not. If the string is not * valid, invalidReason and invalidReasonMessage will be set explaining why it is * invalid. */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/core/hex.ts#L151-L162
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
Hex.equals
equals(other: Hex): boolean { if (this.data.length !== other.data.length) return false; return this.data.every((value, index) => value === other.data[index]); }
/** * Return whether Hex instances are equal. Hex instances are considered equal if * their underlying byte data is identical. * * @param other The Hex instance to compare to. * @returns true if the Hex instances are equal, false if not. */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/core/hex.ts#L171-L174
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
Ed25519PublicKey.constructor
constructor(hexInput: HexInput) { super(); const hex = Hex.fromHexInput(hexInput); if (hex.toUint8Array().length !== Ed25519PublicKey.LENGTH) { throw new Error(`PublicKey length should be ${Ed25519PublicKey.LENGTH}`); } this.key = hex; }
/** * Create a new PublicKey instance from a Uint8Array or String. * * @param hexInput A HexInput (string or Uint8Array) */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/core/crypto/ed25519.ts#L50-L58
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
Ed25519PublicKey.verifySignature
verifySignature(args: VerifySignatureArgs): boolean { const { message, signature } = args; if (!(signature instanceof Ed25519Signature)) { return false; } const messageToVerify = convertSigningMessage(message); const messageBytes = Hex.fromHexInput(messageToVerify).toUint8Array(); const si...
/** * Verifies a signed data with a public key * @param args.message a signed message as a Hex string or Uint8Array * @param args.signature the signature of the message */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/core/crypto/ed25519.ts#L67-L82
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
Ed25519PublicKey.toUint8Array
toUint8Array(): Uint8Array { return this.key.toUint8Array(); }
/** * Get the public key in bytes (Uint8Array). * * @returns Uint8Array representation of the public key */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/core/crypto/ed25519.ts#L96-L98
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
Ed25519PublicKey.serialize
serialize(serializer: Serializer): void { serializer.serializeBytes(this.key.toUint8Array()); }
// region Serializable
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/core/crypto/ed25519.ts#L104-L106
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
Ed25519PublicKey.isPublicKey
static isPublicKey(publicKey: AccountPublicKey): publicKey is Ed25519PublicKey { return publicKey instanceof Ed25519PublicKey; }
/** * @deprecated use `instanceof Ed25519PublicKey` instead. */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/core/crypto/ed25519.ts#L118-L120
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
Ed25519PrivateKey.constructor
constructor(hexInput: HexInput) { super(); const privateKeyHex = Hex.fromHexInput(hexInput); if (privateKeyHex.toUint8Array().length !== Ed25519PrivateKey.LENGTH) { throw new Error(`PrivateKey length should be ${Ed25519PrivateKey.LENGTH}`); } // Create keyPair from Private key in Uint8Array ...
/** * Create a new PrivateKey instance from a Uint8Array or String. * * @param hexInput HexInput (string or Uint8Array) */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/core/crypto/ed25519.ts#L151-L161
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
Ed25519PrivateKey.generate
static generate(): Ed25519PrivateKey { const keyPair = ed25519.utils.randomPrivateKey(); return new Ed25519PrivateKey(keyPair); }
/** * Generate a new random private key. * * @returns Ed25519PrivateKey */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/core/crypto/ed25519.ts#L168-L171
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
Ed25519PrivateKey.fromDerivationPath
static fromDerivationPath(path: string, mnemonics: string): Ed25519PrivateKey { if (!isValidHardenedPath(path)) { throw new Error(`Invalid derivation path ${path}`); } return Ed25519PrivateKey.fromDerivationPathInner(path, mnemonicToSeed(mnemonics)); }
/** * Derives a private key from a mnemonic seed phrase. * * To derive multiple keys from the same phrase, change the path * * IMPORTANT: Ed25519 supports hardened derivation only (since it lacks a key homomorphism, * so non-hardened derivation cannot work) * * @param path the BIP44 path * @p...
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/core/crypto/ed25519.ts#L184-L189
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
Ed25519PrivateKey.fromDerivationPathInner
private static fromDerivationPathInner(path: string, seed: Uint8Array, offset = HARDENED_OFFSET): Ed25519PrivateKey { const { key, chainCode } = deriveKey(Ed25519PrivateKey.SLIP_0010_SEED, seed); const segments = splitPath(path).map((el) => parseInt(el, 10)); // Derive the child key based on the path ...
/** * A private inner function so we can separate from the main fromDerivationPath() method * to add tests to verify we create the keys correctly. * * @param path the BIP44 path * @param seed the seed phrase created by the mnemonics * @param offset the offset used for key derivation, defaults to 0x800...
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/core/crypto/ed25519.ts#L200-L211
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
Ed25519PrivateKey.publicKey
publicKey(): Ed25519PublicKey { const bytes = ed25519.getPublicKey(this.signingKey.toUint8Array()); return new Ed25519PublicKey(bytes); }
/** * Derive the Ed25519PublicKey for this private key. * * @returns Ed25519PublicKey */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/core/crypto/ed25519.ts#L222-L225
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
Ed25519PrivateKey.sign
sign(message: HexInput): Ed25519Signature { const messageToSign = convertSigningMessage(message); const messageBytes = Hex.fromHexInput(messageToSign).toUint8Array(); const signatureBytes = ed25519.sign(messageBytes, this.signingKey.toUint8Array()); return new Ed25519Signature(signatureBytes); }
/** * Sign the given message with the private key. * * @param message a message as a string or Uint8Array * @returns Signature */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/core/crypto/ed25519.ts#L233-L238
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
Ed25519PrivateKey.toUint8Array
toUint8Array(): Uint8Array { return this.signingKey.toUint8Array(); }
/** * Get the private key in bytes (Uint8Array). * * @returns Uint8Array representation of the private key */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/core/crypto/ed25519.ts#L245-L247
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
Ed25519PrivateKey.toString
toString(): string { return this.signingKey.toString(); }
/** * Get the private key as a hex string with the 0x prefix. * * @returns string representation of the private key */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/core/crypto/ed25519.ts#L254-L256
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
Ed25519PrivateKey.serialize
serialize(serializer: Serializer): void { serializer.serializeBytes(this.toUint8Array()); }
// region Serializable
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/core/crypto/ed25519.ts#L262-L264
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
Ed25519PrivateKey.isPrivateKey
static isPrivateKey(privateKey: PrivateKey): privateKey is Ed25519PrivateKey { return privateKey instanceof Ed25519PrivateKey; }
/** * @deprecated use `instanceof Ed25519PrivateKey` instead. */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/core/crypto/ed25519.ts#L276-L278
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
Ed25519Signature.constructor
constructor(hexInput: HexInput) { super(); const data = Hex.fromHexInput(hexInput); if (data.toUint8Array().length !== Ed25519Signature.LENGTH) { throw new Error(`Signature length should be ${Ed25519Signature.LENGTH}`); } this.data = data; }
// region Constructors
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/core/crypto/ed25519.ts#L298-L305
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
Ed25519Signature.toUint8Array
toUint8Array(): Uint8Array { return this.data.toUint8Array(); }
// region Signature
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/core/crypto/ed25519.ts#L311-L313
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
Ed25519Signature.serialize
serialize(serializer: Serializer): void { serializer.serializeBytes(this.data.toUint8Array()); }
// region Serializable
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/core/crypto/ed25519.ts#L319-L321
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
Ed25519Signature.isCanonicalSignature
isCanonicalSignature(): boolean { const s = this.toUint8Array().slice(32); for (let i = s.length - 1; i >= 0; i -= 1) { if (s[i] < L[i]) { return true; } if (s[i] > L[i]) { return false; } } // As this stage S == L which implies a non-canonical S. return fals...
/** * Checks if an ED25519 signature is non-canonical. * * Comes from Aptos Core * https://github.com/aptos-labs/aptos-core/blob/main/crates/aptos-crypto/src/ed25519/ed25519_sigs.rs#L47-L85 */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/core/crypto/ed25519.ts#L334-L347
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
MultiEd25519PublicKey.constructor
constructor(args: { publicKeys: Ed25519PublicKey[]; threshold: number }) { super(); const { publicKeys, threshold } = args; // Validate number of public keys if (publicKeys.length > MultiEd25519PublicKey.MAX_KEYS || publicKeys.length < MultiEd25519PublicKey.MIN_KEYS) { throw new Error( `M...
/** * Public key for a K-of-N multi-sig transaction. A K-of-N multi-sig transaction means that for such a * transaction to be executed, at least K out of the N authorized signers have signed the transaction * and passed the check conducted by the chain. * * @see {@link * https://aptos.dev/integration/...
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/core/crypto/multiEd25519.ts#L51-L72
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
MultiEd25519PublicKey.verifySignature
verifySignature(args: VerifySignatureArgs): boolean { const { message, signature } = args; if (!(signature instanceof MultiEd25519Signature)) { return false; } const indices: number[] = []; for (let i = 0; i < 4; i += 1) { for (let j = 0; j < 8; j += 1) { // eslint-disable-next-...
// region AccountPublicKey
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/core/crypto/multiEd25519.ts#L76-L109
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
MultiEd25519PublicKey.toUint8Array
toUint8Array(): Uint8Array { const bytes = new Uint8Array(this.publicKeys.length * Ed25519PublicKey.LENGTH + 1); this.publicKeys.forEach((k: Ed25519PublicKey, i: number) => { bytes.set(k.toUint8Array(), i * Ed25519PublicKey.LENGTH); }); bytes[this.publicKeys.length * Ed25519PublicKey.LENGTH] = th...
/** * Converts a PublicKeys into Uint8Array (bytes) with: bytes = p1_bytes | ... | pn_bytes | threshold */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/core/crypto/multiEd25519.ts#L121-L130
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
MultiEd25519PublicKey.serialize
serialize(serializer: Serializer): void { serializer.serializeBytes(this.toUint8Array()); }
// region Serializable
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/core/crypto/multiEd25519.ts#L136-L138
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
MultiEd25519Signature.constructor
constructor(args: { signatures: Ed25519Signature[]; bitmap: Uint8Array | number[] }) { super(); const { signatures, bitmap } = args; if (signatures.length > MultiEd25519Signature.MAX_SIGNATURES_SUPPORTED) { throw new Error( `The number of signatures cannot be greater than ${MultiEd25519Signat...
/** * Signature for a K-of-N multi-sig transaction. * * @see {@link * https://aptos.dev/integration/creating-a-signed-transaction/#multisignature-transactions | Creating a Signed Transaction} * * @param args.signatures A list of signatures * @param args.bitmap 4 bytes, at most 32 signatures are sup...
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/core/crypto/multiEd25519.ts#L195-L213
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
MultiEd25519Signature.toUint8Array
toUint8Array(): Uint8Array { const bytes = new Uint8Array(this.signatures.length * Ed25519Signature.LENGTH + MultiEd25519Signature.BITMAP_LEN); this.signatures.forEach((k: Ed25519Signature, i: number) => { bytes.set(k.toUint8Array(), i * Ed25519Signature.LENGTH); }); bytes.set(this.bitmap, this.s...
/** * Converts a MultiSignature into Uint8Array (bytes) with `bytes = s1_bytes | ... | sn_bytes | bitmap` */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/core/crypto/multiEd25519.ts#L220-L229
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
MultiEd25519Signature.createBitmap
static createBitmap(args: { bits: number[] }): Uint8Array { const { bits } = args; // Bits are read from left to right. e.g. 0b10000000 represents the first bit is set in one byte. // The decimal value of 0b10000000 is 128. const firstBitInByte = 128; const bitmap = new Uint8Array([0, 0, 0, 0]); ...
/** * Helper method to create a bitmap out of the specified bit positions * @param args.bits The bitmap positions that should be set. A position starts at index 0. * Valid position should range between 0 and 31. * @example * Here's an example of valid `bits` * ``` * [0, 2, 31] * ``` * `[0, 2,...
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/core/crypto/multiEd25519.ts#L268-L304
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
bitCount
function bitCount(byte: number) { let n = byte; n -= (n >> 1) & 0x55555555; n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return (((n + (n >> 4)) & 0xf0f0f0f) * 0x1010101) >> 24; }
/* eslint-disable no-bitwise */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/core/crypto/multiKey.ts#L11-L16
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
MultiKey.constructor
constructor(args: { publicKeys: Array<PublicKey>; signaturesRequired: number }) { super(); const { publicKeys, signaturesRequired } = args; // Validate number of public keys is greater than signature required if (signaturesRequired < 1) { throw new Error("The number of required signatures needs t...
// region Constructors
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/core/crypto/multiKey.ts#L40-L62
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
MultiKey.verifySignature
verifySignature(args: VerifySignatureArgs): boolean { throw new Error("not implemented"); }
// eslint-disable-next-line class-methods-use-this, @typescript-eslint/no-unused-vars
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/core/crypto/multiKey.ts#L69-L71
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
MultiKey.serialize
serialize(serializer: Serializer): void { serializer.serializeVector(this.publicKeys); serializer.serializeU8(this.signaturesRequired); }
// region Serializable
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/core/crypto/multiKey.ts#L88-L91
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
MultiKey.createBitmap
createBitmap(args: { bits: number[] }): Uint8Array { const { bits } = args; // Bits are read from left to right. e.g. 0b10000000 represents the first bit is set in one byte. // The decimal value of 0b10000000 is 128. const firstBitInByte = 128; const bitmap = new Uint8Array([0, 0, 0, 0]); // Ch...
/** * Create a bitmap that holds the mapping from the original public keys * to the signatures passed in * * @param args.bits array of the index mapping to the matching public keys * @returns Uint8array bit map */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/core/crypto/multiKey.ts#L109-L141
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
MultiKey.getIndex
getIndex(publicKey: PublicKey): number { const anyPublicKey = publicKey instanceof AnyPublicKey ? publicKey : new AnyPublicKey(publicKey); const index = this.publicKeys.findIndex((pk) => pk.toString() === anyPublicKey.toString()); if (index !== -1) { return index; } throw new Error("Public ke...
/** * Get the index of the provided public key. * * @param publicKey array of the index mapping to the matching public keys * @returns the corresponding index of the publicKey, if it exists */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/core/crypto/multiKey.ts#L149-L157
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
MultiKeySignature.constructor
constructor(args: { signatures: Array<Signature | AnySignature>; bitmap: Uint8Array | number[] }) { super(); const { signatures, bitmap } = args; if (signatures.length > MultiKeySignature.MAX_SIGNATURES_SUPPORTED) { throw new Error(`The number of signatures cannot be greater than ${MultiKeySignature....
/** * Signature for a K-of-N multi-sig transaction. * * @see {@link * https://aptos.dev/integration/creating-a-signed-transaction/#multisignature-transactions | Creating a Signed Transaction} * * @param args.signatures A list of signatures * @param args.bitmap 4 bytes, at most 32 signatures are sup...
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/core/crypto/multiKey.ts#L193-L218
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
MultiKeySignature.createBitmap
static createBitmap(args: { bits: number[] }): Uint8Array { const { bits } = args; // Bits are read from left to right. e.g. 0b10000000 represents the first bit is set in one byte. // The decimal value of 0b10000000 is 128. const firstBitInByte = 128; const bitmap = new Uint8Array([0, 0, 0, 0]); ...
/** * Helper method to create a bitmap out of the specified bit positions * @param args.bits The bitmap positions that should be set. A position starts at index 0. * Valid position should range between 0 and 31. * @example * Here's an example of valid `bits` * ``` * [0, 2, 31] * ``` * `[0, 2,...
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/core/crypto/multiKey.ts#L234-L266
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
MultiKeySignature.toUint8Array
toUint8Array(): Uint8Array { return this.bcsToBytes(); }
// region Signature
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-aptos/src/v2/core/crypto/multiKey.ts#L80-L82
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89