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
EvmosWallet.supportEthSign
supportEthSign(): boolean { return true; }
// evmos use ethermint
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-cosmos/src/CosmosWallet.ts#L408-L410
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
Registry.constructor
public constructor(customTypes?: Iterable<[string, GeneratedType]>) { const { cosmosCoin, cosmosMsgSend } = defaultTypeUrls; this.types = customTypes ? new Map<string, GeneratedType>([...customTypes]) : new Map<string, GeneratedType>([ [cosmosCoin, Coin], [cosmosMsgSend, MsgSend]...
/** * Creates a new Registry for mapping protobuf type identifiers/type URLs to * actual implementations. Those implementations are typically generated with ts-base * but we also support protobuf.js as a type generator. * * If there is no parameter given, a `new Registry()` adds the types `Coin` and `Msg...
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-cosmos/src/registry.ts#L96-L104
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
Registry.lookupType
public lookupType(typeUrl: string): GeneratedType | undefined { return this.types.get(typeUrl); }
/** * Looks up a type that was previously added to the registry. * * The generator information (ts-base or pbjs) gets lost along the way. * If you need to work with the result type in TypeScript, you can use: * * ``` * import { assert } from "@cosmjs/util"; * * const Coin = registry.lookupTyp...
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-cosmos/src/registry.ts#L126-L128
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
Registry.encode
public encode(encodeObject: EncodeObject): Uint8Array { const { value, typeUrl } = encodeObject; if (isTxBodyEncodeObject(encodeObject)) { return this.encodeTxBody(value); } const type = this.lookupTypeWithError(typeUrl); let instance if (isTsProtoGeneratedType(type) || isTelescopeGenerate...
/** * Takes a typeUrl/value pair and encodes the value to protobuf if * the given type was previously registered. * * If the value has to be wrapped in an Any, this needs to be done * manually after this call. Or use `encodeAsAny` instead. */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-cosmos/src/registry.ts#L145-L158
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
Registry.encodeAsAny
public encodeAsAny(encodeObject: EncodeObject): Any { const binaryValue = this.encode(encodeObject); return Any.fromPartial({ typeUrl: encodeObject.typeUrl, value: binaryValue, }); }
/** * Takes a typeUrl/value pair and encodes the value to an Any if * the given type was previously registered. */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-cosmos/src/registry.ts#L164-L170
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
makeSignerInfos
function makeSignerInfos( signers: ReadonlyArray<{ readonly pubkey: Any; readonly sequence: number }>, signMode: SignMode, ): SignerInfo[] { return signers.map( ({ pubkey, sequence }): SignerInfo => ({ publicKey: pubkey, modeInfo: { single: { mode: signMode }, }...
/** * Create signer infos from the provided signers. * * This implementation does not support different signing modes for the different signers. */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-cosmos/src/tx.ts#L32-L45
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
negate
function negate(lowBits: number, highBits: number) { highBits = ~highBits; if (lowBits) { lowBits = ~lowBits + 1; } else { // If lowBits is 0, then bitwise-not is 0xFFFFFFFF, // adding 1 to that, results in 0x100000000, which leaves // the low bits 0x0 and simply adds one to ...
/** * Returns two's compliment negation of input. * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators#Signed_32-bit_integers */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-cosmos/src/varint.ts#L270-L281
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
decimalFrom1e7WithLeadingZeros
const decimalFrom1e7WithLeadingZeros = (digit1e7: number) => { const partial = String(digit1e7); return "0000000".slice(partial.length) + partial; };
/** * Returns decimal representation of digit1e7 with leading zeros. */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-cosmos/src/varint.ts#L286-L289
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
decodeUvarint
function decodeUvarint(reader: number[]): [number, number] { if (reader.length < 1) { throw new Error("Can't decode varint. EOF"); } if (reader[0] > 127) { throw new Error( "Decoding numbers > 127 is not supported here. Please tell those lazy CosmJS maintainers to port the binary.Varint implementati...
/** * Uvarint decoder for Amino. * @see https://github.com/tendermint/go-amino/blob/8e779b71f40d175/decoder.go#L64-76 * @returns varint as number, and bytes count occupied by varaint */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-cosmos/src/amino/encoding.ts#L92-L102
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
decodeMultisigPubkey
function decodeMultisigPubkey(data: Uint8Array): MultisigThresholdPubkey { const reader = Array.from(data); // remove multisig amino prefix; const prefixFromReader = reader.splice(0, pubkeyAminoPrefixMultisigThreshold.length); if (!arrayContentStartsWith(prefixFromReader, pubkeyAminoPrefixMultisigThreshold)) {...
/** * Decodes a multisig pubkey to type object. * Pubkey structure [ prefix + const + threshold + loop:(const + pubkeyLength + pubkey ) ] * [ 4b + 1b + varint + loop:(1b + varint + pubkeyLength bytes) ] * @param data encoded pubkey */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-cosmos/src/amino/encoding.ts#L110-L158
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
encodeUvarint
function encodeUvarint(value: number | string): number[] { const checked = math.Uint53.fromString(value.toString()).toNumber(); if (checked > 127) { throw new Error( "Encoding numbers > 127 is not supported here. Please tell those lazy CosmJS maintainers to port the binary.PutUvarint implementation from t...
/** * Uvarint encoder for Amino. This is the same encoding as `binary.PutUvarint` from the Go * standard library. * * @see https://github.com/tendermint/go-amino/blob/8e779b71f40d175/encoder.go#L77-L85 */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-cosmos/src/amino/encoding.ts#L166-L174
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
SerialBuffer.constructor
constructor(array?: Uint8Array) { this.array = array || new Uint8Array(1024); this.length = array ? array.length : 0; }
/** * @param __namedParameters * `array`: `null` if serializing, or binary data to deserialize * `textEncoder`: `TextEncoder` instance to use. Pass in `null` if running in a browser * `textDecoder`: `TextDecider` instance to use. Pass in `null` if running in a browser */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-eos/src/serialize.ts#L37-L40
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
SerialBuffer.reserve
public reserve(size: number): void { if (this.length + size <= this.array.length) { return; } let l = this.array.length; while (this.length + size > l) { l = Math.ceil(l * 1.5); } const newArray = new Uint8Array(l); newArray.set(this.array); this.array = newArray; }
/** Resize `array` if needed to have at least `size` bytes free */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-eos/src/serialize.ts#L43-L54
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
SerialBuffer.haveReadData
public haveReadData(): boolean { return this.readPos < this.length; }
/** Is there data available to read? */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-eos/src/serialize.ts#L57-L59
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
SerialBuffer.restartRead
public restartRead(): void { this.readPos = 0; }
/** Restart reading from the beginning */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-eos/src/serialize.ts#L62-L64
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
SerialBuffer.asUint8Array
public asUint8Array(): Uint8Array { return new Uint8Array( this.array.buffer, this.array.byteOffset, this.length, ); }
/** Return data with excess storage trimmed away */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-eos/src/serialize.ts#L67-L73
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
SerialBuffer.pushArray
public pushArray(v: number[] | Uint8Array): void { this.reserve(v.length); this.array.set(v, this.length); this.length += v.length; }
/** Append bytes */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-eos/src/serialize.ts#L76-L80
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
SerialBuffer.push
public push(...v: number[]): void { this.pushArray(v); }
/** Append bytes */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-eos/src/serialize.ts#L83-L85
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
SerialBuffer.get
public get(): number { if (this.readPos < this.length) { return this.array[this.readPos++]; } throw new Error('Read past end of buffer'); }
/** Get a single byte */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-eos/src/serialize.ts#L88-L93
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
SerialBuffer.pushUint8ArrayChecked
public pushUint8ArrayChecked(v: Uint8Array, len: number): void { if (v.length !== len) { throw new Error('Binary data has incorrect size'); } this.pushArray(v); }
/** Append bytes in `v`. Throws if `len` doesn't match `v.length` */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-eos/src/serialize.ts#L96-L101
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
SerialBuffer.getUint8Array
public getUint8Array(len: number): Uint8Array { if (this.readPos + len > this.length) { throw new Error('Read past end of buffer'); } const result = new Uint8Array( this.array.buffer, this.array.byteOffset + this.readPos, len, ); this.readPos += len; return result; }
/** Get `len` bytes */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-eos/src/serialize.ts#L104-L115
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
SerialBuffer.skip
public skip(len: number): void { if (this.readPos + len > this.length) { throw new Error('Read past end of buffer'); } this.readPos += len; }
/** Skip `len` bytes */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-eos/src/serialize.ts#L118-L123
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
SerialBuffer.pushUint16
public pushUint16(v: number): void { this.push((v >> 0) & 0xff, (v >> 8) & 0xff); }
/** Append a `uint16` */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-eos/src/serialize.ts#L126-L128
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
SerialBuffer.getUint16
public getUint16(): number { let v = 0; v |= this.get() << 0; v |= this.get() << 8; return v; }
/** Get a `uint16` */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-eos/src/serialize.ts#L131-L136
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
SerialBuffer.pushUint32
public pushUint32(v: number): void { this.push( (v >> 0) & 0xff, (v >> 8) & 0xff, (v >> 16) & 0xff, (v >> 24) & 0xff, ); }
/** Append a `uint32` */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-eos/src/serialize.ts#L139-L146
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
SerialBuffer.getUint32
public getUint32(): number { let v = 0; v |= this.get() << 0; v |= this.get() << 8; v |= this.get() << 16; v |= this.get() << 24; return v >>> 0; }
/** Get a `uint32` */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-eos/src/serialize.ts#L149-L156
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
SerialBuffer.pushNumberAsUint64
public pushNumberAsUint64(v: number): void { this.pushUint32(v >>> 0); this.pushUint32(Math.floor(v / 0x10000_0000) >>> 0); }
/** Append a `uint64`. *Caution*: `number` only has 53 bits of precision */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-eos/src/serialize.ts#L159-L162
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
SerialBuffer.getUint64AsNumber
public getUint64AsNumber(): number { const low = this.getUint32(); const high = this.getUint32(); return (high >>> 0) * 0x10000_0000 + (low >>> 0); }
/** * Get a `uint64` as a `number`. *Caution*: `number` only has 53 bits of precision; some values will change. * `numeric.binaryToDecimal(serialBuffer.getUint8Array(8))` recommended instead */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-eos/src/serialize.ts#L168-L172
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
SerialBuffer.pushVaruint32
public pushVaruint32(v: number): void { while (true) { if (v >>> 7) { this.push(0x80 | (v & 0x7f)); v = v >>> 7; } else { this.push(v); break; } } }
/** Append a `varuint32` */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-eos/src/serialize.ts#L175-L185
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
SerialBuffer.getVaruint32
public getVaruint32(): number { let v = 0; let bit = 0; while (true) { const b = this.get(); v |= (b & 0x7f) << bit; bit += 7; if (!(b & 0x80)) { break; } } return v >>> 0; }
/** Get a `varuint32` */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-eos/src/serialize.ts#L188-L200
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
SerialBuffer.pushVarint32
public pushVarint32(v: number): void { this.pushVaruint32((v << 1) ^ (v >> 31)); }
/** Append a `varint32` */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-eos/src/serialize.ts#L203-L205
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
SerialBuffer.getVarint32
public getVarint32(): number { const v = this.getVaruint32(); if (v & 1) { return (~v >> 1) | 0x8000_0000; } else { return v >>> 1; } }
/** Get a `varint32` */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-eos/src/serialize.ts#L208-L215
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
SerialBuffer.pushFloat32
public pushFloat32(v: number): void { this.pushArray(new Uint8Array(new Float32Array([v]).buffer)); }
/** Append a `float32` */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-eos/src/serialize.ts#L218-L220
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
SerialBuffer.getFloat32
public getFloat32(): number { return new Float32Array(this.getUint8Array(4).slice().buffer)[0]; }
/** Get a `float32` */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-eos/src/serialize.ts#L223-L225
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
SerialBuffer.pushFloat64
public pushFloat64(v: number): void { this.pushArray(new Uint8Array(new Float64Array([v]).buffer)); }
/** Append a `float64` */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-eos/src/serialize.ts#L228-L230
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
SerialBuffer.getFloat64
public getFloat64(): number { return new Float64Array(this.getUint8Array(8).slice().buffer)[0]; }
/** Get a `float64` */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-eos/src/serialize.ts#L233-L235
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
SerialBuffer.pushName
public pushName(s: string): void { const regex = new RegExp(/^[.1-5a-z]{0,12}[.1-5a-j]?$/); if (!regex.test(s)) { throw new Error( 'Name should be less than 13 characters, or less than 14 if last character is between 1-5 or a-j, and only contain the following symbols .12345abcdefghijklmnopqrstuvwx...
/** Append a `name` */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-eos/src/serialize.ts#L238-L269
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
SerialBuffer.getName
public getName(): string { const a = this.getUint8Array(8); let result = ''; for (let bit = 63; bit >= 0; ) { let c = 0; for (let i = 0; i < 5; ++i) { if (bit >= 0) { c = (c << 1) | ((a[Math.floor(bit / 8)] >> bit % 8) & 1); --bit; } } if (c >= 6) ...
/** Get a `name` */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-eos/src/serialize.ts#L272-L295
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
SerialBuffer.pushBytes
public pushBytes(v: number[] | Uint8Array): void { this.pushVaruint32(v.length); this.pushArray(v); }
/** Append length-prefixed binary data */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-eos/src/serialize.ts#L298-L301
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
SerialBuffer.getBytes
public getBytes(): Uint8Array { return this.getUint8Array(this.getVaruint32()); }
/** Get length-prefixed binary data */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-eos/src/serialize.ts#L304-L306
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
SerialBuffer.pushString
public pushString(v: string): void { this.pushBytes(textEncoder.encode(v)); }
/** Append a string */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-eos/src/serialize.ts#L309-L311
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
SerialBuffer.getString
public getString(): string { return textDecoder.decode(this.getBytes()); }
/** Get a string */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-eos/src/serialize.ts#L314-L316
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
SerialBuffer.pushSymbolCode
public pushSymbolCode(name: string): void { const a = []; a.push(...textEncoder.encode(name)); while (a.length < 8) { a.push(0); } this.pushArray(a.slice(0, 8)); }
/** Append a `symbol_code`. Unlike `symbol`, `symbol_code` doesn't include a precision. */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-eos/src/serialize.ts#L319-L326
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
SerialBuffer.getSymbolCode
public getSymbolCode(): string { const a = this.getUint8Array(8); let len; for (len = 0; len < a.length; ++len) { if (!a[len]) { break; } } return textDecoder.decode(new Uint8Array(a.buffer, a.byteOffset, len)); }
/** Get a `symbol_code`. Unlike `symbol`, `symbol_code` doesn't include a precision. */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-eos/src/serialize.ts#L329-L338
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
SerialBuffer.pushSymbol
public pushSymbol({ name, precision, }: { name: string; precision: number; }): void { if (!/^[A-Z]{1,7}$/.test(name)) { throw new Error( 'Expected symbol to be A-Z and between one and seven characters', ); } const a = [precision & 0xff]; a.push(...textEncoder.enco...
/** Append a `symbol` */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-eos/src/serialize.ts#L341-L359
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
SerialBuffer.getSymbol
public getSymbol(): { name: string; precision: number } { const precision = this.get(); const a = this.getUint8Array(7); let len; for (len = 0; len < a.length; ++len) { if (!a[len]) { break; } } const name = textDecoder.decode( new Uint8Array(a.buffer, a.byteOffset, len...
/** Get a `symbol` */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-eos/src/serialize.ts#L362-L375
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
SerialBuffer.pushAsset
public pushAsset(s: string): void { s = s.trim(); let pos = 0; let amount = ''; let precision = 0; if (s[pos] === '-') { amount += '-'; ++pos; } let foundDigit = false; while ( pos < s.length && s.charCodeAt(pos) >= '0'.charCodeAt(0) && s.charCodeAt(pos) <= ...
/** Append an asset */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-eos/src/serialize.ts#L378-L415
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
SerialBuffer.getAsset
public getAsset(): string { const amount = this.getUint8Array(8); const { name, precision } = this.getSymbol(); let s = numeric.signedBinaryToDecimal(amount, precision + 1); if (precision) { s = s.substr(0, s.length - precision) + '.' + s.substr(s.length - precision); }...
/** Get an asset */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-eos/src/serialize.ts#L418-L429
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
SerialBuffer.pushPublicKey
public pushPublicKey(s: string): void { const key = numeric.stringToPublicKey(s); this.push(key.type); this.pushArray(key.data); }
/** Append a public key */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-eos/src/serialize.ts#L432-L436
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
SerialBuffer.getPublicKey
public getPublicKey(): string { const type = this.get(); let data: Uint8Array; if (type === KeyType.wa) { const begin = this.readPos; this.skip(34); this.skip(this.getVaruint32()); data = new Uint8Array( this.array.buffer, this.array.byteOffset + begin, this.r...
/** Get a public key */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-eos/src/serialize.ts#L439-L455
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
SerialBuffer.pushPrivateKey
public pushPrivateKey(s: string): void { const key = numeric.stringToPrivateKey(s); this.push(key.type); this.pushArray(key.data); }
/** Append a private key */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-eos/src/serialize.ts#L458-L462
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
SerialBuffer.getPrivateKey
public getPrivateKey(): string { const type = this.get(); const data = this.getUint8Array(privateKeyDataSize); return numeric.privateKeyToString({ type, data }); }
/** Get a private key */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-eos/src/serialize.ts#L465-L469
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
SerialBuffer.pushSignature
public pushSignature(s: string): void { const key = numeric.stringToSignature(s); this.push(key.type); this.pushArray(key.data); }
/** Append a signature */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-eos/src/serialize.ts#L472-L476
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
SerialBuffer.getSignature
public getSignature(): string { const type = this.get(); let data: Uint8Array; if (type === KeyType.wa) { const begin = this.readPos; this.skip(65); this.skip(this.getVaruint32()); this.skip(this.getVaruint32()); data = new Uint8Array( this.array.buffer, this.ar...
/** Get a signature */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-eos/src/serialize.ts#L479-L496
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
TxBuilder.constructor
constructor(chainId: string) { this.chainId = chainId; this.abiTypes = getTypesFromAbi(createAbiTypes()); this.transactionTypes = getTypesFromAbi(createTransactionTypes()); }
/** * * `rpc`: Issues RPC calls * * `authorityProvider`: Get public keys needed to meet authorities in a transaction * * `abiProvider`: Supplies ABIs in raw form (binary) * * `signatureProvider`: Signs transactions * * `chainId`: Identifies chain * * `textEncoder`: `TextEncoder` instance to use. Pass ...
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-eos/src/txBuilder.ts#L52-L56
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
TxBuilder.getTransactionAbiMap
public getTransactionAbiMap(transaction: Transaction, abiMap: Map<string, string>): Map<string, Abi> { const actions = (transaction.context_free_actions || []).concat(transaction.actions); const accounts: string[] = actions.map((action: Action): string => action.account); const uniqueAccounts: Set<string> =...
/** Get abis needed by a transaction */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-eos/src/txBuilder.ts#L59-L72
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
TxBuilder.serializeTransactionExtensions
public serializeTransactionExtensions(transaction: Transaction, resource_payer?: ResourcePayer): [number, string][] { let transaction_extensions: [number, string][] = []; if (resource_payer) { const extensionBuffer = new SerialBuffer(); const types = getTypesFromAbi(createTransactionExtensionTypes()...
// Order of adding to transaction_extension is transaction_extension id ascending
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-eos/src/txBuilder.ts
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
TxBuilder.serializeActions
public serializeActions(actions: Action[], abiMap: Map<string, Abi>): SerializedAction[] { const actionArray = [] for (const {account, name, authorization, data} of actions) { const abi = abiMap.get(account) if(abi) { const contract = this.getContract(abi) const sa = serializeAction(...
/** Convert actions to hex */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-eos/src/txBuilder.ts#L87-L98
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
TxBuilder.getContract
public getContract(abi: Abi): Contract { const types = getTypesFromAbi(createInitialTypes(), abi); const actions = new Map<string, Type>(); for (const { name, type } of abi.actions) { actions.set(name, getType(types, type)); } return { types, actions }; }
/** Get data needed to serialize actions in a contract */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-eos/src/txBuilder.ts#L101-L108
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
TxBuilder.rawAbiToJson
public rawAbiToJson(rawAbi: Uint8Array): Abi { const buffer = new SerialBuffer(rawAbi); if (!supportedAbiVersion(buffer.getString())) { throw new Error('Unsupported abi version'); } buffer.restartRead(); return this.abiTypes.get('abi_def')!.deserialize(buffer); }
/** Decodes an abi as Uint8Array into json. */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-eos/src/txBuilder.ts#L111-L118
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
TxBuilder.serializeTransaction
public serializeTransaction(transaction: Transaction): Uint8Array { const buffer = new SerialBuffer(); this.serialize(buffer, 'transaction', { max_net_usage_words: 0, max_cpu_usage_ms: 0, delay_sec: 0, context_free_actions: [], transaction_extensions: [], ...transaction, ...
/** Convert a transaction to binary */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-eos/src/txBuilder.ts#L121-L132
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
TxBuilder.serialize
public serialize(buffer: SerialBuffer, type: string, value: any): void { this.transactionTypes.get(type)!.serialize(buffer, value); }
/** Convert `value` to binary form. `type` must be a built-in abi type or in `transaction.abi.json`. */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-eos/src/txBuilder.ts#L135-L137
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
TxBuilder.serializeContextFreeData
public serializeContextFreeData(contextFreeData?: Uint8Array[]): Uint8Array | undefined { if (!contextFreeData || !contextFreeData.length) { return undefined; } const buffer = new SerialBuffer(); buffer.pushVaruint32(contextFreeData.length); for (const data of contextFreeData) { buffer....
/** Serialize context-free data */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-eos/src/txBuilder.ts#L140-L150
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
TxBuilder.deflateSerializedArray
public deflateSerializedArray(serializedArray: Uint8Array): Uint8Array { return deflate(serializedArray, { level: 9 }); }
/** Deflate a serialized object */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-eos/src/txBuilder.ts#L154-L156
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
TxBuilder.build
public build(transaction: Transaction, config: TransactConfig, abiMap: Map<string, string>): PackedTransaction { const refBlockInfo = {block_num: config.refBlockNumber, id: config.refBlockId, timestamp: config.refBlockTimestamp} const header = transactionHeader(refBlockInfo, config.expireSeconds); transac...
/** * Create and optionally broadcast a transaction. * * Named Parameters: * `sign`: sign this transaction? * `compression`: compress this transaction? * `readOnlyTrx`: read only transaction? * `returnFailureTraces`: return failure traces? (only available for read only transactions currently) * ...
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-eos/src/txBuilder.ts#L176-L215
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
TxBuilder.sign
public sign(privateKeys: string[], serializedTransaction: Uint8Array, serializedContextFreeData?: Uint8Array): string[] { const digest = digestFromSerializedData(this.chainId, serializedTransaction, serializedContextFreeData); const signatures = []; for (const key of privateKeys) { const privateKey = ...
/** Sign a transaction */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-eos/src/txBuilder.ts#L218-L245
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
isCanonical
const isCanonical = (sigData: Uint8Array): boolean => !(sigData[1] & 0x80) && !(sigData[1] === 0 && !(sigData[2] & 0x80)) && !(sigData[33] & 0x80) && !(sigData[33] === 0 && !(sigData[34] & 0x80));
// special logic
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-eos/src/txBuilder.ts#L225-L227
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
EthWallet.signMessage
async signMessage(param: SignTxParams): Promise<string> { let privateKey; if (param.privateKey) { assertBufferLength(base.fromHex(param.privateKey), 32) privateKey = base.fromHex(param.privateKey) } const data = param.data as TypedMessage; const t = data.t...
// }
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-ethereum/src/EthWallet.ts#L205-L215
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
EthWallet.encrypt
async encrypt(publicKey: string, data: string, version: string): Promise<EthEncryptedData> { return Promise.resolve(eth.sigUtil.encrypt({ publicKey: publicKey, data: data, version: version, })) }
// version
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-ethereum/src/EthWallet.ts#L234-L240
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
EthWallet.decrypt
async decrypt(encryptedData: EthEncryptedData, privateKey: string): Promise<string> { return Promise.resolve(eth.sigUtil.decrypt({ encryptedData: encryptedData as any, privateKey: base.stripHexPrefix(privateKey), })) }
// privateKey hex
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-ethereum/src/EthWallet.ts#L244-L249
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
EthWallet.getHardWareSignedTransaction
async getHardWareSignedTransaction(param: HardwareRawTransactionParam): Promise<any> { try { return eth.getSignedTransaction(param.raw, param.r!, param.s!, param.v!); } catch (e) { return Promise.reject(GetHardwareSignedTransactionError); } }
// BTC does not need to implement this interface. Hardware wallets can directly generate and broadcast transactions.
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-ethereum/src/EthWallet.ts#L307-L313
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
nacl_decodeHex
function nacl_decodeHex(msgHex: string): Uint8Array { const msgBase64 = Buffer.from(msgHex, 'hex').toString('base64'); return naclUtil.decodeBase64(msgBase64); }
/** * Convert a hex string to the UInt8Array format used by nacl. * * @param msgHex - The string to convert. * @returns The converted string. */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-ethereum/src/sdk/eth-sig-util/encryption.ts#L258-L261
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
getSolidityTypes
function getSolidityTypes() { const types = ['bool', 'address', 'string', 'bytes']; const ints = Array.from(new Array(32)).map( (_, index) => `int${(index + 1) * 8}`, ); const uints = Array.from(new Array(32)).map( (_, index) => `uint${(index + 1) * 8}`, ); const bytes = Array.from(new Array(32)...
/** * Get a list of all Solidity types. * * @returns A list of all Solidity types. */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-ethereum/src/sdk/eth-sig-util/sign-typed-data.ts#L457-L470
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
validateVersion
function validateVersion( version: SignTypedDataVersion, allowedVersions?: SignTypedDataVersion[], ) { if (!Object.keys(SignTypedDataVersion).includes(version)) { throw new Error(`Invalid version: '${version}'`); } else if (allowedVersions && !allowedVersions.includes(version)) { throw new Error( ...
/** * Validate that the given value is a valid version string. * * @param version - The version value to validate. * @param allowedVersions - A list of allowed versions. If omitted, all versions are assumed to be * allowed. */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-ethereum/src/sdk/eth-sig-util/sign-typed-data.ts#L479-L492
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
reallyStrangeAddressToBytes
function reallyStrangeAddressToBytes(address: string): Uint8Array { let addressValue = BigInt(0); for (let i = 0; i < address.length; i++) { const character = BigInt(address.charCodeAt(i) - 48); addressValue *= BigInt(10); // 'a' if (character >= 49) { addressValue += character - BigInt(49) ...
/** * Parse an address string to a `Uint8Array`. The behaviour of this is quite * strange, in that it does not parse the address as hexadecimal string, nor as * UTF-8. It does some weird stuff with the string and char codes, and then * returns the result as a `Uint8Array`. * * This is based on the old `ethereumjs...
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-ethereum/src/sdk/eth-sig-util/sign-typed-data.ts#L510-L532
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
parseNumber
function parseNumber(type: string, value: string | number | bigint) { assert( value !== null, `Unable to encode value: Invalid number. Expected a valid number value, but received "${value}".`, ); const bigIntValue = BigInt(value); const length = getLength(type); const maxValue = BigInt(2) ** Big...
/** * Parse a string, number, or bigint value into a `Uint8Array`. * * @param type - The type of the value. * @param value - The value to parse. * @returns The parsed value. */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-ethereum/src/sdk/eth-sig-util/sign-typed-data.ts#L541-L561
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
encodeField
function encodeField( types: Record<string, MessageTypeProperty[]>, name: string, type: string, value: any, version: SignTypedDataVersion.V3 | SignTypedDataVersion.V4, ): [type: string, value: any] { validateVersion(version, [SignTypedDataVersion.V3, SignTypedDataVersion.V4]); if (types[type] !...
/** * Encode a single field. * * @param types - All type definitions. * @param name - The name of the field to encode. * @param type - The type of the field being encoded. * @param value - The value to encode. * @param version - The EIP-712 version the encoding should comply with. * @returns Encoded representat...
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-ethereum/src/sdk/eth-sig-util/sign-typed-data.ts#L573-L676
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
encodeData
function encodeData( primaryType: string, data: Record<string, unknown>, types: Record<string, MessageTypeProperty[]>, version: SignTypedDataVersion.V3 | SignTypedDataVersion.V4, ): Buffer { validateVersion(version, [SignTypedDataVersion.V3, SignTypedDataVersion.V4]); const encodedTypes = ['bytes32...
/** * Encodes an object by encoding and concatenating each of its members. * * @param primaryType - The root type. * @param data - The object to encode. * @param types - Type definitions for all types included in the message. * @param version - The EIP-712 version the encoding should comply with. * @returns An e...
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-ethereum/src/sdk/eth-sig-util/sign-typed-data.ts#L687-L714
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
encodeType
function encodeType( primaryType: string, types: Record<string, MessageTypeProperty[]>, ): string { let result = ''; const unsortedDeps = findTypeDependencies(primaryType, types); unsortedDeps.delete(primaryType); const deps = [primaryType, ...Array.from(unsortedDeps).sort()]; for (const type of deps...
/** * Encodes the type of an object by encoding a comma delimited list of its members. * * @param primaryType - The root type to encode. * @param types - Type definitions for all types included in the message. * @returns An encoded representation of the primary type. */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-ethereum/src/sdk/eth-sig-util/sign-typed-data.ts#L723-L744
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
findTypeDependencies
function findTypeDependencies( primaryType: string, types: Record<string, MessageTypeProperty[]>, results: Set<string> = new Set(), ): Set<string> { [primaryType] = primaryType.match(/^\w*/u)!; if (results.has(primaryType) || types[primaryType] === undefined) { return results; } results.add(pri...
/** * Finds all types within a type definition object. * * @param primaryType - The root type. * @param types - Type definitions for all types included in the message. * @param results - The current set of accumulated types. * @returns The set of all types found in the type definition. */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-ethereum/src/sdk/eth-sig-util/sign-typed-data.ts#L754-L770
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
hashStruct
function hashStruct( primaryType: string, data: Record<string, unknown>, types: Record<string, MessageTypeProperty[]>, version: SignTypedDataVersion.V3 | SignTypedDataVersion.V4, ): Buffer { validateVersion(version, [SignTypedDataVersion.V3, SignTypedDataVersion.V4]); return keccak(encodeData(prima...
/** * Hashes an object. * * @param primaryType - The root type. * @param data - The object to hash. * @param types - Type definitions for all types included in the message. * @param version - The EIP-712 version the encoding should comply with. * @returns The hash of the object. */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-ethereum/src/sdk/eth-sig-util/sign-typed-data.ts#L781-L790
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
hashType
function hashType( primaryType: string, types: Record<string, MessageTypeProperty[]>, ): Buffer { return keccak(Buffer.from(encodeType(primaryType, types))); }
/** * Hashes the type of an object. * * @param primaryType - The root type to hash. * @param types - Type definitions for all types included in the message. * @returns The hash of the object type. */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-ethereum/src/sdk/eth-sig-util/sign-typed-data.ts#L799-L804
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
sanitizeData
function sanitizeData<T extends MessageTypes>( data: TypedMessage<T>, ): TypedMessage<T> { const sanitizedData: Partial<TypedMessage<T>> = {}; for (const key in TYPED_MESSAGE_SCHEMA.properties) { // @ts-ignore if (data[key]) { // @ts-ignore sanitizedData[key] = data[key]; } } if ('ty...
/** * Removes properties from a message object that are not defined per EIP-712. * * @param data - The typed message object. * @returns The typed message object with only allowed fields. */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-ethereum/src/sdk/eth-sig-util/sign-typed-data.ts#L812-L828
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
eip712Hash
function eip712Hash<T extends MessageTypes>( typedData: TypedMessage<T>, version: SignTypedDataVersion.V3 | SignTypedDataVersion.V4, ): Buffer { validateVersion(version, [SignTypedDataVersion.V3, SignTypedDataVersion.V4]); const sanitizedData = sanitizeData(typedData); const parts = [Buffer.from('1901', ...
/** * Hash a typed message according to EIP-712. The returned message starts with the EIP-712 prefix, * which is "1901", followed by the hash of the domain separator, then the data (if any). * The result is hashed again and returned. * * This function does not sign the message. The resulting hash must still be sig...
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-ethereum/src/sdk/eth-sig-util/sign-typed-data.ts#L842-L870
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
_typedSignatureHash
function _typedSignatureHash(typedData: TypedDataV1): Buffer { const error = new Error('Expect argument to be non-empty array'); if ( typeof typedData !== 'object' || !('length' in typedData) || !typedData.length ) { throw error; } const data = typedData.map(function (e) { if (e.typ...
/** * Generate the "V1" hash for the provided typed message. * * The hash will be generated in accordance with an earlier version of the EIP-712 * specification. This hash is used in `signTypedData_v1`. * * @param typedData - The typed message. * @returns The hash representing the type of the provided message. ...
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-ethereum/src/sdk/eth-sig-util/sign-typed-data.ts#L905-L942
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
FeeMarketEIP1559Transaction.fromTxData
public static fromTxData(txData: FeeMarketEIP1559TxData) { return new FeeMarketEIP1559Transaction(txData) }
/** * Instantiate a transaction from a data dictionary. * * Format: { chainId, nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, to, value, data, * accessList, v, r, s } * * Notes: * - `chainId` will be set automatically if not provided * - All parameters are optional and have some basic defa...
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-ethereum/src/sdk/ethereumjs-tx/eip1559Transaction.ts#L58-L60
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
FeeMarketEIP1559Transaction.fromSerializedTx
public static fromSerializedTx(serialized: Buffer) { if (!serialized.slice(0, 1).equals(TRANSACTION_TYPE_BUFFER)) { throw new Error( `Invalid serialized tx input: not an EIP-1559 transaction (wrong tx type, expected: ${TRANSACTION_TYPE}, received: ${serialized .slice(0, 1) ...
/** * Instantiate a transaction from the serialized tx. * * Format: `0x02 || rlp([chainId, nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, to, value, data, * accessList, signatureYParity, signatureR, signatureS])` */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-ethereum/src/sdk/ethereumjs-tx/eip1559Transaction.ts#L68-L84
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
FeeMarketEIP1559Transaction.fromValuesArray
public static fromValuesArray(values: FeeMarketEIP1559ValuesArray) { if (values.length !== 9 && values.length !== 12) { throw new Error( 'Invalid EIP-1559 transaction. Only expecting 9 values (for unsigned tx) or 12 values (for signed tx).' ) } const [ chainId, nonce, ...
/** * Create a transaction from a values array. * * Format: `[chainId, nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, to, value, data, * accessList, signatureYParity, signatureR, signatureS]` */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-ethereum/src/sdk/ethereumjs-tx/eip1559Transaction.ts#L92-L132
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
FeeMarketEIP1559Transaction.constructor
public constructor(txData: FeeMarketEIP1559TxData) { super({ ...txData, type: TRANSACTION_TYPE }) const { chainId, accessList, maxFeePerGas, maxPriorityFeePerGas } = txData this.chainId = toType(chainId, TypeOutput.BN) this.activeCapabilities = this.activeCapabilities.concat([1559, 2718, 2930]) /...
/** * This constructor takes the values, validates them, assigns them and freezes the object. * * It is not recommended to use this constructor directly. Instead use * the static factory methods to assist in creating a Transaction object from * varying data types. */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-ethereum/src/sdk/ethereumjs-tx/eip1559Transaction.ts#L141-L182
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
FeeMarketEIP1559Transaction.raw
raw(): FeeMarketEIP1559ValuesArray { return [ bnToUnpaddedBuffer(this.chainId), bnToUnpaddedBuffer(this.nonce), bnToUnpaddedBuffer(this.maxPriorityFeePerGas), bnToUnpaddedBuffer(this.maxFeePerGas), bnToUnpaddedBuffer(this.gasLimit), this.to !== undefined ? this.to.buf : Buffer.fr...
/** * Returns a Buffer Array of the raw Buffers of the EIP-1559 transaction, in order. * * Format: `[chainId, nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, to, value, data, * accessList, signatureYParity, signatureR, signatureS]` * * Use {@link FeeMarketEIP1559Transaction.serialize} to add a tr...
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-ethereum/src/sdk/ethereumjs-tx/eip1559Transaction.ts#L198-L213
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
FeeMarketEIP1559Transaction.serialize
serialize(): Buffer { const base = this.raw() return Buffer.concat([TRANSACTION_TYPE_BUFFER, rlp.encode(base as any)]) }
/** * Returns the serialized encoding of the EIP-1559 transaction. * * Format: `0x02 || rlp([chainId, nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, to, value, data, * accessList, signatureYParity, signatureR, signatureS])` * * Note that in contrast to the legacy tx serialization format this is ...
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-ethereum/src/sdk/ethereumjs-tx/eip1559Transaction.ts#L225-L228
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
FeeMarketEIP1559Transaction.getMessageToSign
getMessageToSign(hashMessage = true): Buffer { const base = this.raw().slice(0, 9) const message = Buffer.concat([TRANSACTION_TYPE_BUFFER, rlp.encode(base as any)]) if (hashMessage) { return keccak256(message) } else { return message } }
/** * Returns the serialized unsigned tx (hashed or raw), which can be used * to sign the transaction (e.g. for sending to a hardware wallet). * * Note: in contrast to the legacy tx the raw message format is already * serialized and doesn't need to be RLP encoded any more. * * ```javascript * co...
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-ethereum/src/sdk/ethereumjs-tx/eip1559Transaction.ts#L243-L251
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
FeeMarketEIP1559Transaction.hash
public hash(): Buffer { if (!this.isSigned()) { const msg = this._errorMsg('Cannot call hash method if transaction is not signed') throw new Error(msg) } return keccak256(this.serialize()) }
/** * Computes a sha3-256 hash of the serialized tx. * * This method can only be used for signed txs (it throws otherwise). * Use {@link FeeMarketEIP1559Transaction.getMessageToSign} to get a tx hash for the purpose of signing. */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-ethereum/src/sdk/ethereumjs-tx/eip1559Transaction.ts#L259-L265
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
FeeMarketEIP1559Transaction.toJSON
toJSON(): JsonTx { const accessListJSON = AccessLists.getAccessListJSON(this.accessList) return { chainId: bnToHex(this.chainId), nonce: bnToHex(this.nonce), maxPriorityFeePerGas: bnToHex(this.maxPriorityFeePerGas), maxFeePerGas: bnToHex(this.maxFeePerGas), gasLimit: bnToHex(this....
/** * Returns an object with the JSON representation of the transaction */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-ethereum/src/sdk/ethereumjs-tx/eip1559Transaction.ts#L308-L325
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
FeeMarketEIP1559Transaction.errorStr
public errorStr() { let errorStr = this._getSharedErrorPostfix() errorStr += ` maxFeePerGas=${this.maxFeePerGas} maxPriorityFeePerGas=${this.maxPriorityFeePerGas}` return errorStr }
/** * Return a compact error string representation of the object */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-ethereum/src/sdk/ethereumjs-tx/eip1559Transaction.ts#L330-L334
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
FeeMarketEIP1559Transaction._errorMsg
protected _errorMsg(msg: string) { return `${msg} (${this.errorStr()})` }
/** * Internal helper function to create an annotated error message * * @param msg Base error message * @hidden */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-ethereum/src/sdk/ethereumjs-tx/eip1559Transaction.ts#L342-L344
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
AccessListEIP2930Transaction.fromTxData
public static fromTxData(txData: AccessListEIP2930TxData) { return new AccessListEIP2930Transaction(txData) }
/** * Instantiate a transaction from a data dictionary. * * Format: { chainId, nonce, gasPrice, gasLimit, to, value, data, accessList, * v, r, s } * * Notes: * - `chainId` will be set automatically if not provided * - All parameters are optional and have some basic default values */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-ethereum/src/sdk/ethereumjs-tx/eip2930Transaction.ts#L58-L60
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
AccessListEIP2930Transaction.fromSerializedTx
public static fromSerializedTx(serialized: Buffer) { if (!serialized.slice(0, 1).equals(TRANSACTION_TYPE_BUFFER)) { throw new Error( `Invalid serialized tx input: not an EIP-2930 transaction (wrong tx type, expected: ${TRANSACTION_TYPE}, received: ${serialized .slice(0, 1) ...
/** * Instantiate a transaction from the serialized tx. * * Format: `0x01 || rlp([chainId, nonce, gasPrice, gasLimit, to, value, data, accessList, * signatureYParity (v), signatureR (r), signatureS (s)])` */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-ethereum/src/sdk/ethereumjs-tx/eip2930Transaction.ts#L68-L84
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
AccessListEIP2930Transaction.fromValuesArray
public static fromValuesArray(values: AccessListEIP2930ValuesArray) { if (values.length !== 8 && values.length !== 11) { throw new Error( 'Invalid EIP-2930 transaction. Only expecting 8 values (for unsigned tx) or 11 values (for signed tx).' ) } const [chainId, nonce, gasPrice, gasLim...
/** * Create a transaction from a values array. * * Format: `[chainId, nonce, gasPrice, gasLimit, to, value, data, accessList, * signatureYParity (v), signatureR (r), signatureS (s)]` */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-ethereum/src/sdk/ethereumjs-tx/eip2930Transaction.ts#L92-L120
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89
js-wallet-sdk
github_2023
okx
typescript
AccessListEIP2930Transaction.constructor
public constructor(txData: AccessListEIP2930TxData) { super({ ...txData, type: TRANSACTION_TYPE }) const { chainId, accessList, gasPrice } = txData this.chainId = toType(chainId, TypeOutput.BN) this.activeCapabilities = this.activeCapabilities.concat([2718, 2930]) // Populate the access list fiel...
/** * This constructor takes the values, validates them, assigns them and freezes the object. * * It is not recommended to use this constructor directly. Instead use * the static factory methods to assist in creating a Transaction object from * varying data types. */
https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-ethereum/src/sdk/ethereumjs-tx/eip2930Transaction.ts#L129-L158
dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89