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 | Slice.toString | toString(): string {
return this.asCell().toString();
} | /**
* Print slice as string by converting it to cell
* @returns string
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-ton/src/ton-core/boc/Slice.ts#L554-L556 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | Dictionary.empty | static empty<K extends DictionaryKeyTypes, V>(key?: Maybe<DictionaryKey<K>>, value?: Maybe<DictionaryValue<V>>): Dictionary<K, V> {
if (key && value) {
return new Dictionary<K, V>(new Map(), key, value);
} else {
return new Dictionary<K, V>(new Map(), null, null);
}
} | /**
* Create an empty map
* @param key key type
* @param value value type
* @returns Dictionary<K, V>
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-ton/src/ton-core/dict/Dictionary.ts#L218-L224 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | Dictionary.load | static load<K extends DictionaryKeyTypes, V>(key: DictionaryKey<K>, value: DictionaryValue<V>, sc: Slice | Cell): Dictionary<K, V> {
let slice: Slice;
if (sc instanceof Cell) {
if (sc.isExotic) {
return Dictionary.empty<K, V>(key, value);
}
slice = sc.... | /**
* Load dictionary from slice
* @param key key description
* @param value value description
* @param src slice
* @returns Dictionary<K, V>
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-ton/src/ton-core/dict/Dictionary.ts#L233-L249 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | Dictionary.loadDirect | static loadDirect<K extends DictionaryKeyTypes, V>(key: DictionaryKey<K>, value: DictionaryValue<V>, sc: Slice | Cell | null): Dictionary<K, V> {
if (!sc) {
return Dictionary.empty<K, V>(key, value);
}
let slice: Slice;
if (sc instanceof Cell) {
slice = sc.beginPa... | /**
* Low level method for rare dictionaries from system contracts.
* Loads dictionary from slice directly without going to the ref.
*
* @param key key description
* @param value value description
* @param sc slice
* @returns Dictionary<K, V>
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-ton/src/ton-core/dict/Dictionary.ts#L260-L276 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | Dictionary.generateMerkleProof | generateMerkleProof(keys: K[]): Cell {
return generateMerkleProof(this, keys, this._key!)
} | /**
* Generate merkle proof for multiple keys in the dictionary
* @param keys an array of the keys
* @returns generated merkle proof cell
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-ton/src/ton-core/dict/Dictionary.ts#L400-L402 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | Dictionary.generateMerkleProofDirect | generateMerkleProofDirect(keys: K[]): Cell {
return generateMerkleProofDirect(this, keys, this._key!)
} | /**
* Low level method for generating pruned dictionary directly.
* The result can be used as a part of a bigger merkle proof
* @param keys an array of the keys
* @returns cell that contains the pruned dictionary
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-ton/src/ton-core/dict/Dictionary.ts#L410-L412 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | createAddressKey | function createAddressKey(): DictionaryKey<Address> {
return {
bits: 267,
serialize: (src) => {
if (!Address.isAddress(src)) {
throw Error('Key is not an address');
}
return beginCell().storeAddress(src).endCell().beginParse().preloadUintBig(267);
... | // | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-ton/src/ton-core/dict/Dictionary.ts#L423-L436 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | pad | function pad(src: string, size: number) {
while (src.length < size) {
src = '0' + src;
}
return src;
} | // | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-ton/src/ton-core/dict/serializeDict.ts#L16-L21 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | serializeTupleItem | function serializeTupleItem(src: TupleItem, builder: Builder) {
if (src.type === 'null') {
builder.storeUint(0x00, 8);
} else if (src.type === 'int') {
if (src.value <= INT64_MAX && src.value >= INT64_MIN) {
builder.storeUint(0x01, 8);
builder.storeInt(src.value, 64);
... | // vm_stk_null#00 = VmStackValue; | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-ton/src/ton-core/tuple/tuple.ts#L44-L103 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | serializeTupleTail | function serializeTupleTail(src: TupleItem[], builder: Builder) {
if (src.length > 0) {
// rest:^(VmStackList n)
let tail = beginCell();
serializeTupleTail(src.slice(0, src.length - 1), tail);
builder.storeRef(tail.endCell());
// tos
serializeTupleItem(src[src.lengt... | // | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-ton/src/ton-core/tuple/tuple.ts#L179-L190 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | WalletContractV4.getBalance | async getBalance(provider: ContractProvider) {
let state = await provider.getState();
return state.balance;
} | /**
* Get Wallet Balance
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-ton/src/ton/wallets/WalletContractV4.ts#L62-L65 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | WalletContractV4.getSeqno | async getSeqno(provider: ContractProvider) {
let state = await provider.getState();
if (state.state.type === 'active') {
let res = await provider.get('seqno', []);
return res.stack.readNumber();
} else {
return 0;
}
} | /**
* Get Wallet Seqno
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-ton/src/ton/wallets/WalletContractV4.ts#L70-L78 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | WalletContractV4.send | async send(provider: ContractProvider, message: Cell) {
await provider.external(message);
} | /**
* Send signed transfer
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-ton/src/ton/wallets/WalletContractV4.ts#L83-L85 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | WalletContractV4.sendTransfer | async sendTransfer(provider: ContractProvider, args: {
seqno: number,
secretKey: Buffer,
messages: MessageRelaxed[]
sendMode?: Maybe<SendMode>,
timeout?: Maybe<number>,
}) {
let transfer = this.createTransfer(args);
await this.send(provider, transfer);
} | /**
* Sign and send transfer
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-ton/src/ton/wallets/WalletContractV4.ts#L90-L99 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | WalletContractV4.createTransfer | createTransfer(args: {
seqno: number,
secretKey: Buffer,
messages: MessageRelaxed[]
sendMode?: Maybe<SendMode>,
timeout?: Maybe<number>,
}) {
// let sendMode = SendMode.PAY_GAS_SEPARATELY;
let sendMode = SendMode.PAY_GAS_SEPARATELY + SendMode.IGNORE_ERRORS;
... | /**
* Create signed transfer
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-ton/src/ton/wallets/WalletContractV4.ts#L104-L142 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | WalletContractV4.sender | sender(provider: ContractProvider, secretKey: Buffer): Sender {
return {
send: async (args) => {
let seqno = await this.getSeqno(provider);
let transfer = this.createTransfer({
seqno,
secretKey,
sendMode: arg... | /**
* Create sender
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-ton/src/ton/wallets/WalletContractV4.ts#L147-L166 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | TrxWallet.signMessage | async signMessage(param: SignTxParams): Promise<string> {
try {
const message = base.stripHexPrefix(param.data.message);
const signedMsg = tron.signMessage(param.data.type, message, param.privateKey, true);
return Promise.resolve(signedMsg);
} catch (e) {
}
... | // } | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-tron/src/TrxWallet.ts#L137-L145 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | getMultiplier | function getMultiplier(decimals: BigNumberish): string {
if (typeof(decimals) !== "number") {
try {
decimals = BigNumber.from(decimals).toNumber();
} catch (e) {}
}
if (typeof(decimals) === "number" && decimals >= 0 && decimals <= 256 && !(decimals % 1)) {
return ("1" + zeros.substring(0, deci... | // Returns a string "1" followed by decimal "0"s | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-zkspace/src/Units.ts#L23-L36 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | getCloseAmountsByLocal | function getCloseAmountsByLocal(amounts: string) {
const originAmounts = BigNumber.from(amounts)
const closeAmounts=closestPackableTransactionAmount(amounts)
if (closeAmounts.gt(originAmounts)) {
throw new Error('closeAmounts greater than origin');
}
return closeAmounts.toString();
} | // @ts-ignore | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-zkspace/src/ZksyncWallet.ts#L111-L118 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | packAmount | function packAmount(amount, mantissaBits, expBits, expBase) {
const expBaseBN = BigNumber.from(expBase);
const expBitsBN = BigNumber.from(expBits);
const mantissaBitsBN = BigNumber.from(mantissaBits);
const mantissaMaskBN = BigNumber.from(2).pow(mantissaBitsBN).sub(1);
const expMaskBN = BigNumber.from(2).pow(... | // This is essentially a scientific notation for amount | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-zkspace/src/zkspace/index.ts#L199-L219 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | unpackAmount | function unpackAmount(amount, mantissaBits, expBits) {
const expBaseBN = BigNumber.from(10);
const expBitsBN = BigNumber.from(expBits);
const mantissaBitsBN = BigNumber.from(mantissaBits);
const mantissaMaskBN = BigNumber.from(2).pow(mantissaBitsBN).sub(1);
const expMaskBN = BigNumber.from(2).pow(expBitsBN).s... | // @ts-ignore | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-zkspace/src/zkspace/index.ts#L222-L233 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | hexZeroPad | function hexZeroPad(value: string, length: number) {
while (value.length < 2 * length + 2) {
value = '0x0' + value.substring(2);
}
return value;
} | // Transfer 0.0175 ETH to: 0xad06a98cac85448cb33495ca68b0837e3b65abe6 | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-zkspace/src/zksync/index.ts#L229-L234 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | packAmount | function packAmount(amount, mantissaBits, expBits, expBase) {
const expBaseBN = BigNumber.from(expBase);
const expBitsBN = BigNumber.from(expBits);
const mantissaBitsBN = BigNumber.from(mantissaBits);
const mantissaMaskBN = BigNumber.from(2).pow(mantissaBitsBN).sub(1);
const expMaskBN = BigNumber.from(2).pow(... | // @ts-ignore | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-zkspace/src/zksync/index.ts#L241-L261 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | unpackAmount | function unpackAmount(amount, mantissaBits, expBits) {
const expBaseBN = BigNumber.from(10);
const expBitsBN = BigNumber.from(expBits);
const mantissaBitsBN = BigNumber.from(mantissaBits);
const mantissaMaskBN = BigNumber.from(2).pow(mantissaBitsBN).sub(1);
const expMaskBN = BigNumber.from(2).pow(expBitsBN).s... | // @ts-ignore | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-zkspace/src/zksync/index.ts#L264-L275 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | safeParseInt | function safeParseInt(v: string, base: number): number {
if (v[0] === '0' && v[1] === '0') {
throw new Error('invalid RLP: extra zeros')
}
return parseInt(v, base)
} | /**
* Parse integers. Check if there is no leading zeros
* @param v The value to parse
* @param base The base to parse the integer into
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/crypto-lib/src/abi/rlp.ts#L49-L55 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | _decode | function _decode(input: Buffer): Decoded {
let length, llength, data, innerRemainder, d
const decoded = []
const firstByte = input[0]
if (firstByte <= 0x7f) {
// a single byte whose value is in the [0x00, 0x7f] range, that byte is its own RLP encoding.
return {
data: input.s... | /** Decode an input with RLP */ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/crypto-lib/src/abi/rlp.ts#L126-L215 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | intToHex | function intToHex(integer: number | bigint): string {
if (integer < 0) {
throw new Error('Invalid integer as argument, must be unsigned!')
}
const hex = integer.toString(16)
return hex.length % 2 ? `0${hex}` : hex
} | /** Transform an integer into its hexadecimal value */ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/crypto-lib/src/abi/rlp.ts#L228-L234 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | padToEven | function padToEven(a: string): string {
return a.length % 2 ? `0${a}` : a
} | /** Pad a string to be even */ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/crypto-lib/src/abi/rlp.ts#L237-L239 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | intToBuffer | function intToBuffer(integer: number | bigint): Buffer {
const hex = intToHex(integer)
return Buffer.from(hex, 'hex')
} | /** Transform an integer into a Buffer */ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/crypto-lib/src/abi/rlp.ts#L242-L245 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | toBuffer | function toBuffer(v: Input): Buffer {
if (!Buffer.isBuffer(v)) {
if (typeof v === 'string') {
if (isHexPrefixed(v)) {
return Buffer.from(padToEven(stripHexPrefix(v)), 'hex')
} else {
return Buffer.from(v)
}
} else if (typeof v === '... | /** Transform anything into a Buffer */ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/crypto-lib/src/abi/rlp.ts#L248-L274 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | createApi | function createApi(secp256k1) {
return {
isPoint: (p: Buffer) => secp256k1.publicKeyVerify(p),
isPrivate: (d: Buffer) => secp256k1.privateKeyVerify(d),
pointAddScalar: (p: Buffer, tweak: Buffer, compress: boolean) => secp256k1.publicKeyTweakAdd(p, tweak, compress),
pointFromScalar: (d: Buffer, compres... | // @ts-ignore | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/crypto-lib/src/bip32/bip32.ts#L16-L26 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | createTinySecp256k1Interface | function createTinySecp256k1Interface(secp256k1) {
return {
isPoint: (p: Uint8Array): boolean => secp256k1.publicKeyVerify(p),
pointCompress: (p: Uint8Array, compressed?: boolean): Uint8Array => Uint8Array.from(secp256k1.publicKeyConvert(p, compressed != null? compressed: true)),
isPrivate: (d: Uint8Array... | // @ts-ignore | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/crypto-lib/src/bip32/bip32.ts#L29-L44 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | BIP32.isNeutered | isNeutered(): boolean {
return this.__D === undefined;
} | // Public === neutered | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/crypto-lib/src/bip32/bip32.ts#L167-L169 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | BIP32.derive | derive(index: number): BIP32Interface {
typeforce(typeforce.UInt32, index);
const isHardened = index >= HIGHEST_BIT;
const data = Buffer.allocUnsafe(37);
// Hardened child
if (isHardened) {
if (this.isNeutered())
throw new TypeError('Missing private key for hardened child key');
... | // https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#child-key-derivation-ckd-functions | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/crypto-lib/src/bip32/bip32.ts#L226-L295 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | Decimal.zero | public static zero(fractionalDigits: number): Decimal {
Decimal.verifyFractionalDigits(fractionalDigits);
return new Decimal("0", fractionalDigits);
} | /**
* Creates a Decimal with value 0.0 and the given number of fractial digits.
*
* Fractional digits are not relevant for the value but needed to be able
* to perform arithmetic operations with other decimals.
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/crypto-lib/src/math/decimal.ts#L67-L70 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | Decimal.one | public static one(fractionalDigits: number): Decimal {
Decimal.verifyFractionalDigits(fractionalDigits);
return new Decimal("1" + "0".repeat(fractionalDigits), fractionalDigits);
} | /**
* Creates a Decimal with value 1.0 and the given number of fractial digits.
*
* Fractional digits are not relevant for the value but needed to be able
* to perform arithmetic operations with other decimals.
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/crypto-lib/src/math/decimal.ts#L78-L81 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | Decimal.toFloatApproximation | public toFloatApproximation(): number {
const out = Number(this.toString());
if (Number.isNaN(out)) throw new Error("Conversion to number failed");
return out;
} | /**
* Returns an approximation as a float type. Only use this if no
* exact calculation is required.
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/crypto-lib/src/math/decimal.ts#L134-L138 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | Decimal.plus | public plus(b: Decimal): Decimal {
if (this.fractionalDigits !== b.fractionalDigits) throw new Error("Fractional digits do not match");
const sum = this.data.atomics.add(new BN(b.atomics));
return new Decimal(sum.toString(), this.fractionalDigits);
} | /**
* a.plus(b) returns a+b.
*
* Both values need to have the same fractional digits.
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/crypto-lib/src/math/decimal.ts#L145-L149 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | Decimal.minus | public minus(b: Decimal): Decimal {
if (this.fractionalDigits !== b.fractionalDigits) throw new Error("Fractional digits do not match");
const difference = this.data.atomics.sub(new BN(b.atomics));
if (difference.ltn(0)) throw new Error("Difference must not be negative");
return new Decimal(difference.t... | /**
* a.minus(b) returns a-b.
*
* Both values need to have the same fractional digits.
* The resulting difference needs to be non-negative.
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/crypto-lib/src/math/decimal.ts#L157-L162 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | Decimal.multiply | public multiply(b: Uint32 | Uint53 | Uint64): Decimal {
const product = this.data.atomics.mul(new BN(b.toString()));
return new Decimal(product.toString(), this.fractionalDigits);
} | /**
* a.multiply(b) returns a*b.
*
* We only allow multiplication by unsigned integers to avoid rounding errors.
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/crypto-lib/src/math/decimal.ts#L169-L172 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | Uint32.fromBigEndianBytes | public static fromBigEndianBytes(bytes: ArrayLike<number>): Uint32 {
return Uint32.fromBytes(bytes);
} | /** @deprecated use Uint32.fromBytes */ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/crypto-lib/src/math/integers.ts#L27-L29 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | Uint32.fromBytes | public static fromBytes(bytes: ArrayLike<number>, endianess: "be" | "le" = "be"): Uint32 {
if (bytes.length !== 4) {
throw new Error("Invalid input length. Expected 4 bytes.");
}
for (let i = 0; i < bytes.length; ++i) {
if (!Number.isInteger(bytes[i]) || bytes[i] > 255 || bytes[i] < 0) {
... | /**
* Creates a Uint32 from a fixed length byte array.
*
* @param bytes a list of exactly 4 bytes
* @param endianess defaults to big endian
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/crypto-lib/src/math/integers.ts#L37-L53 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | Uint64.fromBytesBigEndian | public static fromBytesBigEndian(bytes: ArrayLike<number>): Uint64 {
return Uint64.fromBytes(bytes);
} | /** @deprecated use Uint64.fromBytes */ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/crypto-lib/src/math/integers.ts#L174-L176 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | Uint64.fromBytes | public static fromBytes(bytes: ArrayLike<number>, endianess: "be" | "le" = "be"): Uint64 {
if (bytes.length !== 8) {
throw new Error("Invalid input length. Expected 8 bytes.");
}
for (let i = 0; i < bytes.length; ++i) {
if (!Number.isInteger(bytes[i]) || bytes[i] > 255 || bytes[i] < 0) {
... | /**
* Creates a Uint64 from a fixed length byte array.
*
* @param bytes a list of exactly 8 bytes
* @param endianess defaults to big endian
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/crypto-lib/src/math/integers.ts#L184-L197 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | sqrtMod | function sqrtMod(y: bigint): bigint {
const P = secp256k1P;
// prettier-ignore
const _3n = BigInt(3), _6n = BigInt(6), _11n = BigInt(11), _22n = BigInt(22);
// prettier-ignore
const _23n = BigInt(23), _44n = BigInt(44), _88n = BigInt(88);
const b2 = (y * y * y) % P; // x^3, 11
const b3 = (b2 * b2 * y) % P... | /**
* √n = n^((p+1)/4) for fields p = 3 mod 4. We unwrap the loop and multiply bit-by-bit.
* (P+1n/4n).toString(2) would produce bits [223x 1, 0, 22x 1, 4x 0, 11, 00]
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/crypto-lib/src/signutil/schnorr/secp256k1.ts#L21-L43 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | pointToBytes | const pointToBytes = (point: PointType<bigint>) => point.toRawBytes(true).slice(1); | // ECDSA compact points are 33-byte. Schnorr is 32: we strip first byte 0x02 or 0x03 | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/crypto-lib/src/signutil/schnorr/secp256k1.ts#L110-L110 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | schnorrGetExtPubKey | function schnorrGetExtPubKey(priv: PrivKey) {
let d_ = secp256k1.utils.normPrivateKeyToScalar(priv); // same method executed in fromPrivateKey
let p = Point.fromPrivateKey(d_); // P = d'⋅G; 0 < d' < n check is done inside
const scalar = p.hasEvenY() ? d_ : modN(-d_);
return { scalar: scalar, bytes: pointToBytes... | // Calculate point, scalar and bytes | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/crypto-lib/src/signutil/schnorr/secp256k1.ts#L119-L124 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | lift_x | function lift_x(x: bigint): PointType<bigint> {
if (!fe(x)) throw new Error('bad x: need 0 < x < p'); // Fail if x ≥ p.
const xx = modP(x * x);
const c = modP(xx * x + BigInt(7)); // Let c = x³ + 7 mod p.
let y = sqrtMod(c); // Let y = c^(p+1)/4 mod p.
if (y % _2n !== _0n) y = modP(-y); // Return the unique p... | /**
* lift_x from BIP340. Convert 32-byte x coordinate to elliptic curve point.
* @returns valid point checked for being on-curve
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/crypto-lib/src/signutil/schnorr/secp256k1.ts#L129-L138 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | challenge | function challenge(...args: Uint8Array[]): bigint {
return modN(bytesToNumberBE(taggedHash('BIP0340/challenge', ...args)));
} | /**
* Create tagged hash, convert it to bigint, reduce modulo-n.
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/crypto-lib/src/signutil/schnorr/secp256k1.ts#L142-L144 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | schnorrGetPublicKey | function schnorrGetPublicKey(privateKey: Hex): Uint8Array {
return schnorrGetExtPubKey(privateKey).bytes; // d'=int(sk). Fail if d'=0 or d'≥n. Ret bytes(d'⋅G)
} | /**
* Schnorr public key is just `x` coordinate of Point as per BIP340.
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/crypto-lib/src/signutil/schnorr/secp256k1.ts#L149-L151 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | schnorrSign | function schnorrSign(
message: Hex,
privateKey: PrivKey,
auxRand: Hex = randomBytes(32)
): Uint8Array {
const m = ensureBytes('message', message);
const { bytes: px, scalar: d } = schnorrGetExtPubKey(privateKey); // checks for isWithinCurveOrder
const a = ensureBytes('auxRand', auxRand, 32); // Auxiliary ra... | /**
* Creates Schnorr signature as per BIP340. Verifies itself before returning anything.
* auxRand is optional and is not the sole source of k generation: bad CSPRNG won't be dangerous.
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/crypto-lib/src/signutil/schnorr/secp256k1.ts#L157-L177 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | schnorrVerify | function schnorrVerify(signature: Hex, message: Hex, publicKey: Hex): boolean {
const sig = ensureBytes('signature', signature, 64);
const m = ensureBytes('message', message);
const pub = ensureBytes('publicKey', publicKey, 32);
try {
const P = lift_x(bytesToNumberBE(pub)); // P = lift_x(int(pk)); fail if t... | /**
* Verifies Schnorr signature.
* Will swallow errors & return false except for initial type validation of arguments.
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/crypto-lib/src/signutil/schnorr/secp256k1.ts#L183-L200 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | poseidonRoundConstant | function poseidonRoundConstant(Fp: IField<bigint>, name: string, idx: number) {
const val = Fp.fromBytes(sha256(utf8ToBytes(`${name}${idx}`)));
return Fp.create(val);
} | // 2^251 + 17 * 2^192 + 1 | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/crypto-lib/src/signutil/schnorr/stark.ts#L240-L243 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | i2osp | function i2osp(value: number, length: number): Uint8Array {
if (value < 0 || value >= 1 << (8 * length)) {
throw new Error(`bad I2OSP call: value=${value} length=${length}`);
}
const res = Array.from({ length }).fill(0) as number[];
for (let i = length - 1; i >= 0; i--) {
res[i] = value & 0xff;
valu... | // Integer to Octet Stream (numberToBytesBE) | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/crypto-lib/src/signutil/schnorr/abstract/hash-to-curve.ts#L34-L44 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | u8fr | const u8n = (data?: any) => new Uint8Array(data); | // creates Uint8Array | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/crypto-lib/src/signutil/schnorr/abstract/utils.ts | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | reset | const reset = () => {
v.fill(1);
k.fill(0);
i = 0;
}; | // Iterations counter, will throw when over 1000 | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/crypto-lib/src/signutil/schnorr/abstract/utils.ts#L163-L167 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | reseed | const reseed = (seed = u8n()) => {
// HMAC-DRBG reseed() function. Steps D-G
k = h(u8fr([0x00]), seed); // k = hmac(k || v || 0x00 || seed)
v = h(); // v = hmac(k || v)
if (seed.length === 0) return;
k = h(u8fr([0x01]), seed); // k = hmac(k || v || 0x01 || seed)
v = h(); // v = hmac(k || v)
}; | // hmac(k)(v, ...values) | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/crypto-lib/src/signutil/schnorr/abstract/utils.ts#L169-L176 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | slice | const slice = (s: string): string => (Number.parseInt(s[0], 16) & 0b1000 ? '00' + s : s); | // Add leading zero if first byte has negative bit enabled. More details in '_parseInt' | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/crypto-lib/src/signutil/schnorr/abstract/weierstrass.ts#L171-L171 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | weierstrassEquation | function weierstrassEquation(x: T): T {
const { a, b } = CURVE;
const x2 = Fp.sqr(x); // x * x
const x3 = Fp.mul(x2, x); // x2 * x
return Fp.add(Fp.add(x3, Fp.mul(x, a)), b); // x3 + a * x + b
} | /**
* y² = x³ + ax + b: Short weierstrass curve formula
* @returns y²
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/crypto-lib/src/signutil/schnorr/abstract/weierstrass.ts#L215-L220 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | isWithinCurveOrder | function isWithinCurveOrder(num: bigint): boolean {
return typeof num === 'bigint' && _0n < num && num < CURVE.n;
} | // Valid group elements reside in range 1..n-1 | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/crypto-lib/src/signutil/schnorr/abstract/weierstrass.ts#L229-L231 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | normPrivateKeyToScalar | function normPrivateKeyToScalar(key: PrivKey): bigint {
const { allowedPrivateKeyLengths: lengths, nByteLength, wrapPrivateKey, n } = CURVE;
if (lengths && typeof key !== 'bigint') {
if (key instanceof Uint8Array) key = ut.bytesToHex(key);
// Normalize to hex string, pad. E.g. P521 would norm 130-13... | // Validates if priv key is valid and converts it to bigint. | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/crypto-lib/src/signutil/schnorr/abstract/weierstrass.ts#L237-L257 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | Point.fromAffine | static fromAffine(p: AffinePoint<T>): Point {
const { x, y } = p || {};
if (!p || !Fp.isValid(x) || !Fp.isValid(y)) throw new Error('invalid affine point');
if (p instanceof Point) throw new Error('projective point not allowed');
const is0 = (i: T) => Fp.eql(i, Fp.ZERO);
// fromAffine(x:0, y:0) woul... | // Use fromHex instead, or call assertValidity() later. | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/crypto-lib/src/signutil/schnorr/abstract/weierstrass.ts#L280-L288 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | Point.normalizeZ | static normalizeZ(points: Point[]): Point[] {
const toInv = Fp.invertBatch(points.map((p) => p.pz));
return points.map((p, i) => p.toAffine(toInv[i])).map(Point.fromAffine);
} | /**
* Takes a bunch of Projective Points but executes only one
* inversion on all of them. Inversion is very slow operation,
* so this improves performance massively.
* Optimization: converts a list of projective points to a list of identical points with Z=1.
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/crypto-lib/src/signutil/schnorr/abstract/weierstrass.ts#L303-L306 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | Point.fromHex | static fromHex(hex: Hex): Point {
const P = Point.fromAffine(fromBytes(ensureBytes('pointHex', hex)));
P.assertValidity();
return P;
} | /**
* Converts hash string or Uint8Array to Point.
* @param hex short/long ECDSA hex
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/crypto-lib/src/signutil/schnorr/abstract/weierstrass.ts#L312-L316 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | Point.fromPrivateKey | static fromPrivateKey(privateKey: PrivKey) {
return Point.BASE.multiply(normPrivateKeyToScalar(privateKey));
} | // Multiplies generator point by privateKey. | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/crypto-lib/src/signutil/schnorr/abstract/weierstrass.ts#L319-L321 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | Point._setWindowSize | _setWindowSize(windowSize: number) {
this._WINDOW_SIZE = windowSize;
pointPrecomputes.delete(this);
} | // "Private method", don't use it directly | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/crypto-lib/src/signutil/schnorr/abstract/weierstrass.ts#L329-L332 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | Point.assertValidity | assertValidity(): void {
// Zero is valid point too!
if (this.is0()) {
if (CURVE.allowInfinityPoint) return;
throw new Error('bad point: ZERO');
}
// Some 3rd-party test vectors require different wording between here & `fromCompressedHex`
const { x, y } = this.toAffine();
// Check if x, y are va... | // A point on curve is valid if it conforms to equation. | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/crypto-lib/src/signutil/schnorr/abstract/weierstrass.ts#L335-L349 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | Point.equals | equals(other: Point): boolean {
assertPrjPoint(other);
const { px: X1, py: Y1, pz: Z1 } = this;
const { px: X2, py: Y2, pz: Z2 } = other;
const U1 = Fp.eql(Fp.mul(X1, Z2), Fp.mul(X2, Z1));
const U2 = Fp.eql(Fp.mul(Y1, Z2), Fp.mul(Y2, Z1));
return U1 && U2;
} | /**
* Compare one point to another.
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/crypto-lib/src/signutil/schnorr/abstract/weierstrass.ts#L359-L366 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | Point.negate | negate(): Point {
return new Point(this.px, Fp.neg(this.py), this.pz);
} | /**
* Flips point to one corresponding to (x, -y) in Affine coordinates.
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/crypto-lib/src/signutil/schnorr/abstract/weierstrass.ts#L371-L373 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | Point.double | double() {
const { a, b } = CURVE;
const b3 = Fp.mul(b, _3n);
const { px: X1, py: Y1, pz: Z1 } = this;
let X3 = Fp.ZERO, Y3 = Fp.ZERO, Z3 = Fp.ZERO; // prettier-ignore
let t0 = Fp.mul(X1, X1); // step 1
let t1 = Fp.mul(Y1, Y1);
let t2 = Fp.mul(Z1, Z1);
let t3 = Fp.mul(X1, Y1);
t3 = F... | // Cost: 8M + 3S + 3*a + 2*b3 + 15add. | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/crypto-lib/src/signutil/schnorr/abstract/weierstrass.ts#L379-L416 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | Point.add | add(other: Point): Point {
assertPrjPoint(other);
const { px: X1, py: Y1, pz: Z1 } = this;
const { px: X2, py: Y2, pz: Z2 } = other;
let X3 = Fp.ZERO, Y3 = Fp.ZERO, Z3 = Fp.ZERO; // prettier-ignore
const a = CURVE.a;
const b3 = Fp.mul(CURVE.b, _3n);
let t0 = Fp.mul(X1, X2); // step 1
let... | // Cost: 12M + 0S + 3*a + 3*b3 + 23add. | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/crypto-lib/src/signutil/schnorr/abstract/weierstrass.ts#L422-L470 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | Point.multiplyUnsafe | multiplyUnsafe(n: bigint): Point {
const I = Point.ZERO;
if (n === _0n) return I;
assertGE(n); // Will throw on 0
if (n === _1n) return this;
const { endo } = CURVE;
if (!endo) return wnaf.unsafeLadder(this, n);
// Apply endomorphism
let { k1neg, k1, k2neg, k2 } = endo.splitScalar(n);
... | /**
* Non-constant-time multiplication. Uses double-and-add algorithm.
* It's faster, but should only be used when you don't care about
* an exposed private key e.g. sig verification, which works over *public* keys.
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/crypto-lib/src/signutil/schnorr/abstract/weierstrass.ts#L491-L515 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | Point.multiply | multiply(scalar: bigint): Point {
assertGE(scalar);
let n = scalar;
let point: Point, fake: Point; // Fake point is used to const-time mult
const { endo } = CURVE;
if (endo) {
const { k1neg, k1, k2neg, k2 } = endo.splitScalar(n);
let { p: k1p, f: f1p } = this.wNAF(k1);
let { p: k2p... | /**
* Constant time multiplication.
* Uses wNAF method. Windowed method may be 10% faster,
* but takes 2x longer to generate and consumes 2x memory.
* Uses precomputes when available.
* Uses endomorphism for Koblitz curves.
* @param scalar by which the point would be multiplied
* @returns New point... | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/crypto-lib/src/signutil/schnorr/abstract/weierstrass.ts#L526-L547 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | Point.multiplyAndAddUnsafe | multiplyAndAddUnsafe(Q: Point, a: bigint, b: bigint): Point | undefined {
const G = Point.BASE; // No Strauss-Shamir trick: we have 10% faster G precomputes
const mul = (
P: Point,
a: bigint // Select faster multiply() method
) => (a === _0n || a === _1n || !P.equals(G) ? P.multiplyUnsafe(a) : P... | /**
* Efficiently calculate `aP + bQ`. Unsafe, can expose private key, if used incorrectly.
* Not using Strauss-Shamir trick: precomputation tables are faster.
* The trick could be useful if both P and Q are not G (not in our case).
* @returns non-zero affine point
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/crypto-lib/src/signutil/schnorr/abstract/weierstrass.ts#L555-L563 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | mul | const mul = (
P: Point,
a: bigint // Select faster multiply() method
) => (a === _0n || a === _1n || !P.equals(G) ? P.multiplyUnsafe(a) : P.multiply(a)); | // No Strauss-Shamir trick: we have 10% faster G precomputes | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/crypto-lib/src/signutil/schnorr/abstract/weierstrass.ts#L557-L560 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | Point.toAffine | toAffine(iz?: T): AffinePoint<T> {
const { px: x, py: y, pz: z } = this;
const is0 = this.is0();
// If invZ was 0, we return zero point. However we still want to execute
// all operations, so we replace invZ with a random number, 1.
if (iz == null) iz = is0 ? Fp.ONE : Fp.inv(z);
const ax = Fp.mul(... | // (x, y, z) ∋ (x=x/z, y=y/z) | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/crypto-lib/src/signutil/schnorr/abstract/weierstrass.ts#L568-L580 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | isValidFieldElement | function isValidFieldElement(num: bigint): boolean {
return _0n < num && num < Fp.ORDER; // 0 is banned since it's not invertible FE
} | // e.g. 65 for 32 | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/crypto-lib/src/signutil/schnorr/abstract/weierstrass.ts#L693-L695 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | slcNum | const slcNum = (b: Uint8Array, from: number, to: number) => ut.bytesToNumberBE(b.slice(from, to)); | // slice bytes num | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/crypto-lib/src/signutil/schnorr/abstract/weierstrass.ts#L758-L758 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | Signature.fromCompact | static fromCompact(hex: Hex) {
const l = CURVE.nByteLength;
hex = ensureBytes('compactSignature', hex, l * 2);
return new Signature(slcNum(hex, 0, l), slcNum(hex, l, 2 * l));
} | // pair (bytes of r, bytes of s) | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/crypto-lib/src/signutil/schnorr/abstract/weierstrass.ts#L769-L773 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | Signature.fromDER | static fromDER(hex: Hex) {
const { r, s } = DER.toSig(ensureBytes('DER', hex));
return new Signature(r, s);
} | // https://bitcoin.stackexchange.com/questions/57644/what-are-the-parts-of-a-bitcoin-transaction-input-script | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/crypto-lib/src/signutil/schnorr/abstract/weierstrass.ts#L777-L780 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | Signature.hasHighS | hasHighS(): boolean {
return isBiggerThanHalfOrder(this.s);
} | // Signatures should be low-s, to prevent malleability. | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/crypto-lib/src/signutil/schnorr/abstract/weierstrass.ts#L810-L812 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | Signature.toDERRawBytes | toDERRawBytes() {
return ut.hexToBytes(this.toDERHex());
} | // DER-encoded | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/crypto-lib/src/signutil/schnorr/abstract/weierstrass.ts#L819-L821 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | Signature.toCompactRawBytes | toCompactRawBytes() {
return ut.hexToBytes(this.toCompactHex());
} | // padded bytes of r, then padded bytes of s | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/crypto-lib/src/signutil/schnorr/abstract/weierstrass.ts#L827-L829 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | getPublicKey | function getPublicKey(privateKey: PrivKey, isCompressed = true): Uint8Array {
return Point.fromPrivateKey(privateKey).toRawBytes(isCompressed);
} | /**
* Computes public key for a private key. Checks for validity of the private key.
* @param privateKey private key
* @param isCompressed whether to return compact (default), or full key
* @returns Public key, full when isCompressed=false; short when isCompressed=true
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/crypto-lib/src/signutil/schnorr/abstract/weierstrass.ts#L878-L880 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | isProbPub | function isProbPub(item: PrivKey | PubKey): boolean {
const arr = item instanceof Uint8Array;
const str = typeof item === 'string';
const len = (arr || str) && (item as Hex).length;
if (arr) return len === compressedLen || len === uncompressedLen;
if (str) return len === 2 * compressedLen || len ===... | /**
* Quick and dirty check for item being public key. Does not validate hex, or being on-curve.
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/crypto-lib/src/signutil/schnorr/abstract/weierstrass.ts#L885-L893 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | getSharedSecret | function getSharedSecret(privateA: PrivKey, publicB: Hex, isCompressed = true): Uint8Array {
if (isProbPub(privateA)) throw new Error('first arg must be private key');
if (!isProbPub(publicB)) throw new Error('second arg must be public key');
const b = Point.fromHex(publicB); // check for being on-curve
... | /**
* ECDH (Elliptic Curve Diffie Hellman).
* Computes shared public key from private key and public key.
* Checks: 1) private key validity 2) shared key is on-curve.
* Does NOT hash the result.
* @param privateA private key
* @param publicB different public key
* @param isCompressed whether to ret... | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/crypto-lib/src/signutil/schnorr/abstract/weierstrass.ts#L905-L910 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | int2octets | function int2octets(num: bigint): Uint8Array {
if (typeof num !== 'bigint') throw new Error('bigint expected');
if (!(_0n <= num && num < ORDER_MASK))
throw new Error(`bigint expected < 2^${CURVE.nBitLength}`);
// works with order, can have different size than numToField!
return ut.numberToBytesBE... | /**
* Converts to bytes. Checks if num in `[0..ORDER_MASK-1]` e.g.: `[0..2^256-1]`.
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/crypto-lib/src/signutil/schnorr/abstract/weierstrass.ts#L935-L941 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | prepSig | function prepSig(msgHash: Hex, privateKey: PrivKey, opts = defaultSigOpts) {
if (['recovered', 'canonical'].some((k) => k in opts))
throw new Error('sign() legacy options not supported');
const { hash, randomBytes } = CURVE;
let { lowS, prehash, extraEntropy: ent } = opts; // generates low-s sigs by d... | // Steps A, D of RFC6979 3.2 | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/crypto-lib/src/signutil/schnorr/abstract/weierstrass.ts#L948-L994 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | k2sig | function k2sig(kBytes: Uint8Array): RecoveredSignature | undefined {
// RFC 6979 Section 3.2, step 3: k = bits2int(T)
const k = bits2int(kBytes); // Cannot use fields methods, since it is group element
if (!isWithinCurveOrder(k)) return; // Important: all mod() calls here must be done over N
con... | // NOTE: no need to call bits2int second time here, it is inside truncateHash! | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/crypto-lib/src/signutil/schnorr/abstract/weierstrass.ts#L972-L992 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | sign | function sign(msgHash: Hex, privKey: PrivKey, opts = defaultSigOpts): RecoveredSignature {
const { seed, k2sig } = prepSig(msgHash, privKey, opts); // Steps A, D of RFC6979 3.2.
const C = CURVE;
const drbg = ut.createHmacDrbg<RecoveredSignature>(C.hash.outputLen, C.nByteLength, C.hmac);
return drbg(seed... | /**
* Signs message hash with a private key.
* ```
* sign(m, d, k) where
* (x, y) = G × k
* r = x mod n
* s = (m + dr)/k mod n
* ```
* @param msgHash NOT message. msg needs to be hashed to `msgHash`, or use `prehash`.
* @param privKey private key
* @param opts lowS for non-malleable ... | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/crypto-lib/src/signutil/schnorr/abstract/weierstrass.ts#L1011-L1016 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | verify | function verify(
signature: Hex | SignatureLike,
msgHash: Hex,
publicKey: Hex,
opts = defaultVerOpts
): boolean {
const sg = signature;
msgHash = ensureBytes('msgHash', msgHash);
publicKey = ensureBytes('publicKey', publicKey);
if ('strict' in opts) throw new Error('options.strict was ... | // utils.precompute(8, ProjectivePoint.BASE) | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/crypto-lib/src/signutil/schnorr/abstract/weierstrass.ts#L1035-L1082 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | sqrtRatio | let sqrtRatio = (u: T, v: T): { isValid: boolean; value: T } => {
let tv1 = c6; // 1. tv1 = c6
let tv2 = Fp.pow(v, c4); // 2. tv2 = v^c4
let tv3 = Fp.sqr(tv2); // 3. tv3 = tv2^2
tv3 = Fp.mul(tv3, v); // 4. tv3 = tv3 * v
let tv5 = Fp.mul(u, tv3); // 5. tv5 = u * tv3
tv5 = Fp.pow(tv5, c3); // 6. t... | // 7. c7 = Z^((c2 + 1) / 2) | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/crypto-lib/src/signutil/schnorr/abstract/weierstrass.ts#L1120-L1150 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
turbo | github_2023 | unfoldadmin | typescript | FetchHttpRequest.request | public override request<T>(options: ApiRequestOptions): CancelablePromise<T> {
return __request(this.config, options)
} | /**
* Request method
* @param options The request options from the service
* @returns CancelablePromise<T>
* @throws ApiError
*/ | https://github.com/unfoldadmin/turbo/blob/6f4ecf55bf67fbc6d9d42840ea50f71fe513a639/frontend/packages/types/api/core/FetchHttpRequest.ts#L22-L24 | 6f4ecf55bf67fbc6d9d42840ea50f71fe513a639 |
turbo | github_2023 | unfoldadmin | typescript | SchemaService.schemaRetrieve | public schemaRetrieve(
format?: 'json' | 'yaml',
lang?:
| 'af'
| 'ar'
| 'ar-dz'
| 'ast'
| 'az'
| 'be'
| 'bg'
| 'bn'
| 'br'
| 'bs'
| 'ca'
| 'ckb'
| 'cs'
| 'cy'
| 'da'
| 'de'
| 'dsb'
| 'el'
| 'en'
... | /**
* OpenApi3 schema for this API. Format can be selected via content negotiation.
*
* - YAML: application/vnd.oai.openapi
* - JSON: application/vnd.oai.openapi+json
* @param format
* @param lang
* @returns any
* @throws ApiError
*/ | https://github.com/unfoldadmin/turbo/blob/6f4ecf55bf67fbc6d9d42840ea50f71fe513a639/frontend/packages/types/api/services/SchemaService.ts#L21-L132 | 6f4ecf55bf67fbc6d9d42840ea50f71fe513a639 |
turbo | github_2023 | unfoldadmin | typescript | TokenService.tokenCreate | public tokenCreate(
requestBody: TokenObtainPair
): CancelablePromise<TokenObtainPair> {
return this.httpRequest.request({
method: 'POST',
url: '/api/token/',
body: requestBody,
mediaType: 'application/json'
})
} | /**
* Takes a set of user credentials and returns an access and refresh JSON web
* token pair to prove the authentication of those credentials.
* @param requestBody
* @returns TokenObtainPair
* @throws ApiError
*/ | https://github.com/unfoldadmin/turbo/blob/6f4ecf55bf67fbc6d9d42840ea50f71fe513a639/frontend/packages/types/api/services/TokenService.ts#L21-L30 | 6f4ecf55bf67fbc6d9d42840ea50f71fe513a639 |
turbo | github_2023 | unfoldadmin | typescript | TokenService.tokenRefreshCreate | public tokenRefreshCreate(
requestBody: TokenRefresh
): CancelablePromise<TokenRefresh> {
return this.httpRequest.request({
method: 'POST',
url: '/api/token/refresh/',
body: requestBody,
mediaType: 'application/json'
})
} | /**
* Takes a refresh type JSON web token and returns an access type JSON web
* token if the refresh token is valid.
* @param requestBody
* @returns TokenRefresh
* @throws ApiError
*/ | https://github.com/unfoldadmin/turbo/blob/6f4ecf55bf67fbc6d9d42840ea50f71fe513a639/frontend/packages/types/api/services/TokenService.ts#L39-L48 | 6f4ecf55bf67fbc6d9d42840ea50f71fe513a639 |
turbo | github_2023 | unfoldadmin | typescript | UsersService.usersCreate | public usersCreate(requestBody: UserCreate): CancelablePromise<UserCreate> {
return this.httpRequest.request({
method: 'POST',
url: '/api/users/',
body: requestBody,
mediaType: 'application/json'
})
} | /**
* @param requestBody
* @returns UserCreate
* @throws ApiError
*/ | https://github.com/unfoldadmin/turbo/blob/6f4ecf55bf67fbc6d9d42840ea50f71fe513a639/frontend/packages/types/api/services/UsersService.ts#L21-L28 | 6f4ecf55bf67fbc6d9d42840ea50f71fe513a639 |
turbo | github_2023 | unfoldadmin | typescript | UsersService.usersChangePasswordCreate | public usersChangePasswordCreate(
requestBody: UserChangePassword
): CancelablePromise<void> {
return this.httpRequest.request({
method: 'POST',
url: '/api/users/change-password/',
body: requestBody,
mediaType: 'application/json'
})
} | /**
* @param requestBody
* @returns void
* @throws ApiError
*/ | https://github.com/unfoldadmin/turbo/blob/6f4ecf55bf67fbc6d9d42840ea50f71fe513a639/frontend/packages/types/api/services/UsersService.ts#L35-L44 | 6f4ecf55bf67fbc6d9d42840ea50f71fe513a639 |
turbo | github_2023 | unfoldadmin | typescript | UsersService.usersDeleteAccountDestroy | public usersDeleteAccountDestroy(): CancelablePromise<void> {
return this.httpRequest.request({
method: 'DELETE',
url: '/api/users/delete-account/'
})
} | /**
* @returns void
* @throws ApiError
*/ | https://github.com/unfoldadmin/turbo/blob/6f4ecf55bf67fbc6d9d42840ea50f71fe513a639/frontend/packages/types/api/services/UsersService.ts#L50-L55 | 6f4ecf55bf67fbc6d9d42840ea50f71fe513a639 |
turbo | github_2023 | unfoldadmin | typescript | UsersService.usersMeRetrieve | public usersMeRetrieve(): CancelablePromise<UserCurrent> {
return this.httpRequest.request({
method: 'GET',
url: '/api/users/me/'
})
} | /**
* @returns UserCurrent
* @throws ApiError
*/ | https://github.com/unfoldadmin/turbo/blob/6f4ecf55bf67fbc6d9d42840ea50f71fe513a639/frontend/packages/types/api/services/UsersService.ts#L61-L66 | 6f4ecf55bf67fbc6d9d42840ea50f71fe513a639 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.