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 | sharedSecretToKeys | function sharedSecretToKeys(sharedSecret: Uint8Array): {
encryptionKey: Uint8Array;
hmacKey: Uint8Array;
} {
// generate mac and encryption key from shared secret
const hashedSecret = hashSha512Sync(sharedSecret);
return {
encryptionKey: hashedSecret.slice(0, 32),
hmacKey: hashedSecret.slice(32),
};... | /**
* @ignore
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-stacks/src/encryption/ec.ts#L107-L117 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | allHexChars | function allHexChars(maybe: string): boolean {
return maybe.match(/^[0-9a-f]+$/i) !== null;
} | /**
* @ignore
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-stacks/src/encryption/ec.ts#L122-L124 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | isValidPublicKey | function isValidPublicKey(pub: string): {
result: boolean;
reason: string | null;
reason_data: string | null;
} {
const invalidFormat = {
result: false,
reason_data: 'Invalid public key format',
reason: InvalidPublicKeyReason.InvalidFormat,
};
const invalidPoint = {
result: false,
reason... | /**
* @ignore
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-stacks/src/encryption/ec.ts#L129-L174 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | nativeAddressToSegwitVersion | function nativeAddressToSegwitVersion(
witnessVersion: number,
dataLength: number
): PoXAddressVersion {
if (witnessVersion === SEGWIT_V0 && dataLength === 20) return PoXAddressVersion.P2WPKH;
if (witnessVersion === SEGWIT_V0 && dataLength === 32) return PoXAddressVersion.P2WSH;
if (witnessVersion === SEGWIT_... | /** @ignore */ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-stacks/src/stacking/utils.ts#L66-L77 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | BytesReader.readOffset | get readOffset(): number {
return this.consumed;
} | // } | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-stacks/src/transactions/bytesReader.ts#L94-L96 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | PartialPcWithPrincipal.willSendEq | willSendEq(amount: IntegerType) {
return new PartialPcFtWithCode(
this.address,
amount,
FungibleConditionCode.Equal,
this.contractName
);
} | /**
* ### Fungible Token Post Condition
* A post-condition sending tokens `FungibleConditionCode.Equal` (equal to) the given amount of uSTX or fungible-tokens.
* Finalize with the chained `.ustx()` or `.ft(…)` method.
* @example
* ```
* import { Pc } from '@stacks/transactions';
* Pc.principal('STB... | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-stacks/src/transactions/pc.ts#L83-L90 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | PartialPcWithPrincipal.willSendLte | willSendLte(amount: IntegerType) {
return new PartialPcFtWithCode(
this.address,
amount,
FungibleConditionCode.LessEqual,
this.contractName
);
} | /**
* ### Fungible Token Post Condition
* A post-condition sending tokens `FungibleConditionCode.LessEqual` (less-than or equal to) the given amount of uSTX or fungible-tokens.
* Finalize with the chained `.ustx()` or `.ft(…)` method.
* @example
* ```
* import { Pc } from '@stacks/transactions';
* ... | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-stacks/src/transactions/pc.ts#L102-L109 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | PartialPcWithPrincipal.willSendLt | willSendLt(amount: IntegerType) {
return new PartialPcFtWithCode(
this.address,
amount,
FungibleConditionCode.Less,
this.contractName
);
} | /**
* ### Fungible Token Post Condition
* A post-condition sending tokens `FungibleConditionCode.Less` (less-than) the given amount of uSTX or fungible-tokens.
* Finalize with the chained `.ustx()` or `.ft(…)` method.
* @example
* ```
* import { Pc } from '@stacks/transactions';
* Pc.principal('STB... | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-stacks/src/transactions/pc.ts#L121-L128 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | PartialPcWithPrincipal.willSendGte | willSendGte(amount: IntegerType) {
return new PartialPcFtWithCode(
this.address,
amount,
FungibleConditionCode.GreaterEqual,
this.contractName
);
} | /**
* ### Fungible Token Post Condition
* A post-condition sending tokens `FungibleConditionCode.GreaterEqual` (greater-than or equal to) the given amount of uSTX or fungible-tokens.
* Finalize with the chained `.ustx()` or `.ft(…)` method.
* @example
* ```
* import { Pc } from '@stacks/transactions';... | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-stacks/src/transactions/pc.ts#L140-L147 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | PartialPcWithPrincipal.willSendGt | willSendGt(amount: IntegerType) {
return new PartialPcFtWithCode(
this.address,
amount,
FungibleConditionCode.Greater,
this.contractName
);
} | /**
* ### Fungible Token Post Condition
* A post-condition sending tokens `FungibleConditionCode.Greater` (greater-than) the given amount of uSTX or fungible-tokens.
* Finalize with the chained `.ustx()` or `.ft(…)` method.
* @example
* ```
* import { Pc } from '@stacks/transactions';
* Pc.principa... | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-stacks/src/transactions/pc.ts#L159-L166 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | PartialPcWithPrincipal.willSendAsset | willSendAsset() {
return new PartialPcNftWithCode(
this.address,
NonFungibleConditionCode.Sends,
this.contractName
);
} | /**
* ### NFT Post Condition
* A post-condition which `NonFungibleConditionCode.Sends` an NFT.
* Finalize with the chained `.nft(…)` method.
* @example
* ```
* import { Pc } from '@stacks/transactions';
* Pc.principal('STB4…K6.nft-contract').willSendAsset().nft('STB4…K6.super-nft::super', uintCV(1)... | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-stacks/src/transactions/pc.ts#L178-L184 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | PartialPcWithPrincipal.willNotSendAsset | willNotSendAsset() {
return new PartialPcNftWithCode(
this.address,
NonFungibleConditionCode.DoesNotSend,
this.contractName
);
} | /**
* ### NFT Post Condition
* A post-condition which `NonFungibleConditionCode.DoesNotSend` an NFT.
* Finalize with the chained `.nft(…)` method.
* @example
* ```
* import { Pc } from '@stacks/transactions';
* Pc.principal('STB4…K6.nft-contract').willNotSendAsset().nft('STB4…K6.super-nft::super', ... | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-stacks/src/transactions/pc.ts#L196-L202 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | PartialPcFtWithCode.ustx | ustx() {
// todo: rename to `uSTX`?
if (this.contractName) {
return makeContractSTXPostCondition(this.address, this.contractName, this.code, this.amount);
}
return makeStandardSTXPostCondition(this.address, this.code, this.amount);
} | /**
* ### STX Post Condition
* ⚠ Amount of STX is denoted in uSTX (micro-STX)
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-stacks/src/transactions/pc.ts#L217-L223 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | PartialPcFtWithCode.ft | ft(contractId: ContractIdString, tokenName: string) {
const [address, name] = parseContractId(contractId);
if (this.contractName) {
return makeContractFungiblePostCondition(
this.address,
this.contractName,
this.code,
this.amount,
createAssetInfo(address, name, toke... | /**
* ### Fungible Token Post Condition
* ⚠ Amount of fungible tokens is denoted in the smallest unit of the token
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-stacks/src/transactions/pc.ts#L229-L246 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | parseContractId | function parseContractId(contractId: ContractIdString) {
const [address, name] = contractId.split('.');
if (!address || !name) throw new Error(`Invalid contract identifier: ${contractId}`);
return [address, name];
} | /** @internal */ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-stacks/src/transactions/pc.ts#L298-L302 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | parseNft | function parseNft(nftAssetName: NftString) {
const [principal, tokenName] = nftAssetName.split('::') as [ContractIdString, string];
if (!principal || !tokenName)
throw new Error(`Invalid fully-qualified nft asset name: ${nftAssetName}`);
const [address, name] = parseContractId(principal);
return { contractA... | /** @internal */ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-stacks/src/transactions/pc.ts#L305-L311 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | isContractIdString | function isContractIdString(value: AddressString | ContractIdString): value is ContractIdString {
return value.includes('.');
} | /** @internal */ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-stacks/src/transactions/pc.ts#L314-L316 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | StacksTransaction.setFee | setFee(amount: IntegerType) {
this.auth = setFee(this.auth, amount);
} | /**
* Set the total fee to be paid for this transaction
*
* @param fee - the fee amount in microstacks
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-stacks/src/transactions/transaction.ts#L211-L213 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | StacksTransaction.setNonce | setNonce(nonce: IntegerType) {
this.auth = setNonce(this.auth, nonce);
} | /**
* Set the transaction nonce
*
* @param nonce - the nonce value
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-stacks/src/transactions/transaction.ts#L220-L222 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | StacksTransaction.setSponsorNonce | setSponsorNonce(nonce: IntegerType) {
if (this.auth.authType != AuthType.Sponsored) {
throw new SigningError('Cannot sponsor sign a non-sponsored transaction');
}
this.auth = setSponsorNonce(this.auth, nonce);
} | /**
* Set the transaction sponsor nonce
*
* @param nonce - the sponsor nonce value
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-stacks/src/transactions/transaction.ts#L229-L235 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | trueCV | const trueCV = (): BooleanCV => ({ type: ClarityType.BoolTrue }); | /**
* Converts true to BooleanCV clarity type
*
* @returns {BooleanCV} returns instance of type BooleanCV
*
* @example
* ```
* import { trueCV } from '@stacks/transactions';
*
* const trueCV = trueCV();
* // { type: 3 }
* ```
*
* @see
* {@link https://github.com/hirosystems/stacks.js/blob/master/packag... | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-stacks/src/transactions/clarity/types/booleanCV.ts#L36-L36 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | falseCV | const falseCV = (): BooleanCV => ({ type: ClarityType.BoolFalse }); | /**
* Converts false to BooleanCV clarity type
*
* @returns {BooleanCV} returns instance of type BooleanCV
*
* @example
* ```
* import { falseCV } from '@stacks/transactions';
*
* const falseCV = falseCV();
* // { type: 4 }
* ```
*
* @see
* {@link https://github.com/hirosystems/stacks.js/blob/master/pa... | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-stacks/src/transactions/clarity/types/booleanCV.ts#L54-L54 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | boolCV | const boolCV = (bool: boolean) => (bool ? trueCV() : falseCV()); | /**
* Converts a boolean to BooleanCV clarity type
*
* @returns {BooleanCV} returns instance of type BooleanCV
*
* @example
* ```
* import { boolCV } from '@stacks/transactions';
*
* const boolCV = boolCV(false);
* // { type: 4 }
* ```
*
* @see
* {@link https://github.com/hirosystems/stacks.js/blob/mas... | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-stacks/src/transactions/clarity/types/booleanCV.ts#L72-L72 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | bufferCV | const bufferCV = (buffer: Uint8Array): BufferCV => {
if (buffer.length > 1_000_000) {
throw new Error('Cannot construct clarity buffer that is greater than 1MB');
}
return { type: ClarityType.Buffer, buffer };
}; | /**
* Converts a Uint8Array to a BufferCV clarity type
*
* @param {Uint8Array} buffer value to be converted to clarity type
*
* @returns {BufferCV} returns instance of type BufferCV
*
* @example
* ```
* import { bufferCV } from '@stacks/transactions';
*
* const buffer = utf8ToBytes('this is a test');
* c... | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-stacks/src/transactions/clarity/types/bufferCV.ts#L37-L43 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | bufferCVFromString | const bufferCVFromString = (str: string): BufferCV => bufferCV(utf8ToBytes(str)); | /**
* Converts a string to BufferCV clarity type
*
* @param {str} string input to be converted to bufferCV clarity type
*
* @returns {BufferCV} returns instance of type BufferCV
*
* @example
* ```
* import { bufferCVFromString } from '@stacks/transactions';
*
* const str = 'this is a test';
* const buf =... | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-stacks/src/transactions/clarity/types/bufferCV.ts#L66-L66 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | intCV | const intCV = (value: IntegerType): IntCV => {
const bigInt = intToBigInt(value, true);
if (bigInt > MAX_I128) {
throw new RangeError(`Cannot construct clarity integer from value greater than ${MAX_I128}`);
} else if (bigInt < MIN_I128) {
throw new RangeError(`Cannot construct clarity integer form value l... | /**
* Converts IntegerType in to IntCV clarity type
*
* @param {value} integer value to be converted to IntCV clarity type
*
* @returns {IntCV} returns instance of type IntCV
*
* @example
* ```
* import { intCV } from '@stacks/transactions';
*
* const value = intCV('100'); // parameter any of type: number ... | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-stacks/src/transactions/clarity/types/intCV.ts#L40-L48 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | uintCV | const uintCV = (value: IntegerType): UIntCV => {
const bigInt = intToBigInt(value, false);
if (bigInt < MIN_U128) {
throw new RangeError('Cannot construct unsigned clarity integer from negative value');
} else if (bigInt > MAX_U128) {
throw new RangeError(`Cannot construct unsigned clarity integer greater... | /**
* Converts IntegerType in to IntCV clarity type
*
* @param {value} integer value to be converted to UIntCV clarity type (Only unsigned integer is allowed otherwise throws exception)
*
* @returns {UIntCV} returns instance of type UIntCV
*
* @example
* ```
* import { uintCV } from '@stacks/transactions';
*... | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-stacks/src/transactions/clarity/types/intCV.ts#L73-L81 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | listCV | function listCV<T extends ClarityValue = ClarityValue>(values: T[]): ListCV<T> {
return { type: ClarityType.List, list: values };
} | /**
* Create list of clarity types
*
* @param {ClarityValue[]} list of ClarityValues to be converted to ListCV clarity type
*
* @returns {ListCV<T>} instance of type ListCV<T> of the provided values
*
* @example
* ```
* import { listCV, intCV } from '@stacks/transactions';
*
* const list = listCV([intCV(1)... | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-stacks/src/transactions/clarity/types/listCV.ts#L34-L36 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | noneCV | function noneCV(): NoneCV {
return { type: ClarityType.OptionalNone };
} | /**
* Create a null clarity type
**
* @returns {NoneCV} returns instance of type NoneCV
*
* @example
* ```
* import { noneCV } from '@stacks/transactions';
*
* const value = noneCV();
* // { type: 9 }
* ```
*
* @see
* {@link https://github.com/hirosystems/stacks.js/blob/master/packages/transactions/tes... | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-stacks/src/transactions/clarity/types/optionalCV.ts#L37-L39 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | someCV | function someCV<T extends ClarityValue = ClarityValue>(value: T): OptionalCV<T> {
return { type: ClarityType.OptionalSome, value };
} | /**
* Converts any ClarityValue in to OptionalCV clarity type
*
* @param {ClarityValue} value to be converted to OptionalCV clarity type
*
* @returns {OptionalCV} returns instance of type OptionalCV
*
* @example
* ```
* import { someCV, trueCV } from '@stacks/transactions';
*
* const value = someCV(trueCV(... | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-stacks/src/transactions/clarity/types/optionalCV.ts#L59-L61 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | principalToString | function principalToString(principal: PrincipalCV): string {
if (principal.type === ClarityType.PrincipalStandard) {
return addressToString(principal.address);
} else if (principal.type === ClarityType.PrincipalContract) {
const address = addressToString(principal.address);
return `${address}.${principa... | /** Returns a string in the format `address` or `address.contract-name` from a principal (standard or contract) */ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-stacks/src/transactions/clarity/types/principalCV.ts#L26-L35 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | standardPrincipalCV | function standardPrincipalCV(addressString: string): StandardPrincipalCV {
const addr = createAddress(addressString);
return { type: ClarityType.PrincipalStandard, address: addr };
} | /**
* Converts stx address in to StandardPrincipalCV clarity type
* @param {addressString} string value to be converted to StandardPrincipalCV clarity type
* @returns {StandardPrincipalCV} returns instance of type StandardPrincipalCV
*
* @example
* ```
* import { standardPrincipalCV } from '@stacks/transactions... | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-stacks/src/transactions/clarity/types/principalCV.ts#L62-L65 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | standardPrincipalCVFromAddress | function standardPrincipalCVFromAddress(address: Address): StandardPrincipalCV {
return { type: ClarityType.PrincipalStandard, address };
} | /**
* Converts stx address in to StandardPrincipalCV clarity type
* @param {addressString} string value to be converted to StandardPrincipalCV clarity type
* @returns {StandardPrincipalCV} returns instance of type StandardPrincipalCV
*
* @example
* ```
* import { standardPrincipalCVFromAddress, Address } from ... | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-stacks/src/transactions/clarity/types/principalCV.ts#L89-L91 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | contractPrincipalCV | function contractPrincipalCV(addressString: string, contractName: string): ContractPrincipalCV {
const addr = createAddress(addressString);
const lengthPrefixedContractName = createLPString(contractName);
return contractPrincipalCVFromAddress(addr, lengthPrefixedContractName);
} | /**
* Converts stx address in to ContractPrincipalCV clarity type
* @param {addressString} string value to be converted to ContractPrincipalCV clarity type
* @param {contractName} string containing contract name
* @returns {ContractPrincipalCV} returns instance of type ContractPrincipalCV
*
* @example
* ```
* ... | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-stacks/src/transactions/clarity/types/principalCV.ts#L110-L114 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | contractPrincipalCVFromAddress | function contractPrincipalCVFromAddress(
address: Address,
contractName: LengthPrefixedString
): ContractPrincipalCV {
if (utf8ToBytes(contractName.content).byteLength >= 128) {
throw new Error('Contract name must be less than 128 bytes');
}
return { type: ClarityType.PrincipalContract, address, contractN... | /**
* Create ContractPrincipalCV from Address type
* @param {address} address value to be converted to ContractPrincipalCV clarity type
* @param {contractName} contract name of type LengthPrefixedString
* @returns {ContractPrincipalCV} returns instance of type ContractPrincipalCV
*
* @example
* ```
* import { ... | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-stacks/src/transactions/clarity/types/principalCV.ts#L134-L142 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | responseErrorCV | function responseErrorCV<T extends ClarityValue = ClarityValue>(value: T): ResponseErrorCV<T> {
return { type: ClarityType.ResponseErr, value };
} | /**
* Converts ClarityValue to responseErrorCV
*
* @param {value} ClarityValue value to be converted to responseErrorCV clarity type
*
* @returns {responseErrorCV} returns instance of type responseErrorCV
*
* @example
* ```
* import { responseErrorCV, intCV } from '@stacks/transactions';
*
* const respErro... | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-stacks/src/transactions/clarity/types/responseCV.ts#L42-L44 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | responseOkCV | function responseOkCV<T extends ClarityValue = ClarityValue>(value: T): ResponseOkCV<T> {
return { type: ClarityType.ResponseOk, value };
} | /**
* Converts ClarityValue to ResponseOkCV
*
* @param {value} ClarityValue value to be converted to ResponseOkCV clarity type
*
* @returns {ResponseOkCV} returns instance of type ResponseOkCV
*
* @example
* ```
* import { responseOkCV, intCV } from '@stacks/transactions';
*
* const respOKCV = responseOkCV... | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-stacks/src/transactions/clarity/types/responseCV.ts#L65-L67 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | stringAsciiCV | const stringAsciiCV = (data: string): StringAsciiCV => {
return { type: ClarityType.StringASCII, data };
}; | /**
* Converts ClarityValue to stringAsciiCV
*
* @param {data} ClarityValue value to be converted to stringAsciiCV clarity type
*
* @returns {StringAsciiCV} returns instance of type StringAsciiCV
*
* @example
* ```
* import { stringAsciiCV } from '@stacks/transactions';
*
* const stringAscii = stringAsciiC... | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-stacks/src/transactions/clarity/types/stringCV.ts#L39-L41 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | stringUtf8CV | const stringUtf8CV = (data: string): StringUtf8CV => {
return { type: ClarityType.StringUTF8, data };
}; | /**
* Converts ClarityValue to stringUtf8CV
*
* @param {data} ClarityValue value to be converted to stringUtf8CV clarity type
*
* @returns {stringUtf8CV} returns instance of type stringUtf8CV
*
* @example
* ```
* import { stringUtf8CV } from '@stacks/transactions';
*
* const stringUTF8 = stringUtf8CV('test... | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-stacks/src/transactions/clarity/types/stringCV.ts#L62-L64 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | stringCV | const stringCV = (data: string, encoding: 'ascii' | 'utf8'): StringAsciiCV | StringUtf8CV => {
switch (encoding) {
case 'ascii':
return stringAsciiCV(data);
case 'utf8':
return stringUtf8CV(data);
}
}; | /**
* @ignore
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-stacks/src/transactions/clarity/types/stringCV.ts#L69-L76 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | tupleCV | function tupleCV<T extends ClarityValue = ClarityValue>(data: TupleData<T>): TupleCV<TupleData<T>> {
for (const key in data) {
if (!isClarityName(key)) {
throw new Error(`"${key}" is not a valid Clarity name`);
}
}
return { type: ClarityType.Tuple, data };
} | /**
* Create tuple of clarity values
*
* @param {tupleData} tuple value to be converted to tuple of clarity types
*
* @returns {TupleCV} returns instance of type clarity tuple
*
* @example
* ```
* import { tupleCV, trueCV, falseCV } from '@stacks/transactions';
*
* const tuple = tupleCV({
* c: trueCV()... | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-stacks/src/transactions/clarity/types/tupleCV.ts#L41-L49 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | Block.queryIdentifier | get queryIdentifier(): any {
if (this.number !== null) {
return `blockNumber=${this.number}`;
}
if (this.hash !== null) {
return `blockHash=${this.hash}`;
}
return `blockNumber=${this.tag}`;
} | // TODO: fix any | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-starknet/src/provider/utils.ts#L73-L83 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | Block.identifier | get identifier(): any {
if (this.number !== null) {
return { block_number: this.number };
}
if (this.hash !== null) {
return { block_hash: this.hash };
}
return this.tag;
} | // TODO: fix any | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-starknet/src/provider/utils.ts#L86-L96 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | hashBuiltins | function hashBuiltins(builtins: Builtins) {
return stark.poseidonHashMany(
builtins.flatMap((it: any) => {
return BigInt(encodeShortString(it));
})
);
} | // Cairo1 below | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-starknet/src/utils/hash.ts#L298-L304 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | CallData.validate | public validate(type: 'INVOKE' | 'CALL' | 'DEPLOY', method: string, args: Array<any> = []) {
// ensure provided method of type exists
if (type !== 'DEPLOY') {
const invocableFunctionNames = this.abi
.filter((abi) => {
if (abi.type !== 'function') return false;
const isView = ab... | /**
* Validates if all arguments that are passed to the method are corresponding to the ones in the abi
*
* @param type - type of the method
* @param method - name of the method
* @param args - arguments that are passed to the method
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-starknet/src/utils/calldata/index.ts#L30-L63 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | CallData.compile | public compile(args: Array<any>, inputs: AbiEntry[]): Calldata {
const argsIterator = args[Symbol.iterator]();
return inputs.reduce(
(acc, input) =>
isLen(input.name) ? acc : acc.concat(parseCalldataField(argsIterator, input, this.structs)),
[] as Calldata
);
} | /**
* Parse the calldata by using input fields from the abi for that method
*
* @param args - arguments passed the the method
* @param inputs - list of inputs(fields) that are in the abi
* @return {Calldata} - parsed arguments in format that contract is expecting
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-starknet/src/utils/calldata/index.ts#L72-L79 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | CallData.compile | static compile(data: object | string[]): Calldata {
const createTree = (obj: object) => {
const getEntries = (o: object, prefix = ''): any => {
const oe = Array.isArray(o) ? [o.length.toString(), ...o] : o;
return Object.entries(oe).flatMap(([k, v]) => {
let value = v;
if (... | /**
* Compile contract callData without abi
* @param data Object representing cairo method arguments or string array of compiled data
* @returns string[]
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-starknet/src/utils/calldata/index.ts#L86-L121 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | CallData.parse | public parse(method: string, response: string[]): object {
const { outputs } = this.abi.find((abi) => abi.name === method) as FunctionAbi;
const responseIterator = response.flat()[Symbol.iterator]();
return outputs.flat().reduce((acc, output) => {
acc[output.name] = responseParser(responseIterator, o... | /**
* Parse elements of the response array and structuring them into response object
* @param method - method name
* @param response - response from the method
* @return - parsed response corresponding to the abi
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-starknet/src/utils/calldata/index.ts#L129-L140 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | CallData.format | public format(method: string, response: string[], format: object): object {
const parsed = this.parse(method, response);
return formatter(parsed, format);
} | /**
* Format cairo method response data to native js values based on provided format schema
* @param method - cairo method name
* @param response - cairo method response
* @param format - formatter object schema
* @returns parsed and formatted response object
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-starknet/src/utils/calldata/index.ts#L149-L152 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | CallData.abiInputsLength | static abiInputsLength(inputs: AbiEntry[]) {
return inputs.reduce((acc, input) => (!isLen(input.name) ? acc + 1 : acc), 0);
} | // Helper to calculate inputs | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-starknet/src/utils/calldata/index.ts#L155-L157 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | CallData.getAbiStruct | static getAbiStruct(abi: Abi) {
return abi
.filter((abiEntry) => abiEntry.type === 'struct')
.reduce(
(acc, abiEntry) => ({
...acc,
[abiEntry.name]: abiEntry,
}),
{}
);
} | // Helper to extract structs | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-starknet/src/utils/calldata/index.ts#L160-L170 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | parseTuple | function parseTuple(element: object, typeStr: string): Tupled[] {
const memberTypes = extractTupleMemberTypes(typeStr);
const elements = Object.values(element);
if (elements.length !== memberTypes.length) {
throw Error(
`ParseTuple: provided and expected abi tuple size do not match.
provided: ${e... | /**
* Parse tuple type string to array of known objects
* @param element request element
* @param typeStr tuple type string
* @returns Tupled[]
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-starknet/src/utils/calldata/requestParser.ts#L13-L31 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | parseCalldataValue | function parseCalldataValue(
element: ParsedStruct | BigNumberish | BigNumberish[],
type: string,
structs: AbiStructs
): string | string[] {
if (element === undefined) {
throw Error(`Missing parameter for type ${type}`);
}
if (Array.isArray(element)) {
throw Error(`Array inside array (nD) are not su... | /**
* Deep parse of the object that has been passed to the method
*
* @param element - element that needs to be parsed
* @param type - name of the method
* @param structs - structs from abi
* @return {string | string[]} - parsed arguments in format that contract is expecting
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-starknet/src/utils/calldata/requestParser.ts#L41-L74 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | parseResponseStruct | function parseResponseStruct(
responseIterator: Iterator<string>,
type: string,
structs: AbiStructs
): BigNumberish | ParsedStruct {
// type struct
if (type in structs && structs[type]) {
return structs[type].members.reduce((acc, el) => {
acc[el.name] = parseResponseStruct(responseIterator, el.type,... | /**
* Parse of the response elements that are converted to Object (Struct) by using the abi
*
* @param responseIterator - iterator of the response
* @param type - type of the struct
* @param structs - structs from abi
* @return {BigNumberish | ParsedStruct} - parsed arguments in format that contract is expecting
... | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-starknet/src/utils/calldata/responseParser.ts#L14-L38 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | LosslessNumber.valueOf | valueOf(): number | bigint {
const unsafeReason = getUnsafeNumberReason(this.value)
// safe or truncate_float
if (unsafeReason === undefined || unsafeReason === UnsafeNumberReason.truncate_float) {
return parseFloat(this.value)
}
// truncate_integer
if (isIn... | /**
* Get the value of the LosslessNumber as number or bigint.
*
* - a number is returned for safe numbers and decimal values that only lose some insignificant digits
* - a bigint is returned for big integer numbers
* - an Error is thrown for values that will overflow or underflow
*
*... | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-starknet/src/utils/json/LosslessNumber.ts#L38-L56 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | LosslessNumber.toString | toString(): string {
return this.value
} | /**
* Get the value of the LosslessNumber as string.
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-starknet/src/utils/json/LosslessNumber.ts#L61-L63 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | pos | function pos(): string {
return `at position ${i}`
} | // zero based character position | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-starknet/src/utils/json/parse.ts#L312-L314 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | reviveValue | function reviveValue(
context: GenericObject<unknown> | Array<unknown>,
key: string,
value: unknown,
reviver: Reviver
): unknown {
if (Array.isArray(value)) {
// @ts-ignore
return reviver.call(context, key, reviveArray(value, reviver))
} else if (value && typeof value === 'object... | /**
* Revive a value
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-starknet/src/utils/json/revive.ts#L22-L44 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | reviveObject | function reviveObject(object: GenericObject<unknown>, reviver: Reviver) {
Object.keys(object).forEach((key) => {
const value = reviveValue(object, key, object[key], reviver)
if (value !== undefined) {
object[key] = value
} else {
delete object[key]
}
})
... | /**
* Revive the properties of an object
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-starknet/src/utils/json/revive.ts#L49-L60 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | reviveArray | function reviveArray(array: Array<unknown>, reviver: Reviver): Array<unknown> {
for (let i = 0; i < array.length; i++) {
array[i] = reviveValue(array, i + '', array[i], reviver)
}
return array
} | /**
* Revive the properties of an Array
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-starknet/src/utils/json/revive.ts#L65-L71 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | stringifyValue | function stringifyValue(value: unknown, indent: string): string | undefined {
if (Array.isArray(numberStringifiers)) {
const stringifier = numberStringifiers.find((item) => item.test(value))
if (stringifier) {
const str = stringifier.stringify(value)
if (t... | /**
* Stringify a value
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-starknet/src/utils/json/stringify.ts#L56-L110 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | stringifyArray | function stringifyArray(array: Array<unknown>, indent: string): string {
if (array.length === 0) {
return '[]'
}
const childIndent = resolvedSpace ? indent + resolvedSpace : undefined
let str = resolvedSpace ? '[\n' : '['
for (let i = 0; i < array.length; i++) {
... | /**
* Stringify an array
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-starknet/src/utils/json/stringify.ts#L115-L145 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | stringifyObject | function stringifyObject(object: GenericObject<unknown>, indent: string): string {
if (typeof object.toJSON === 'function') {
// @ts-ignore
return stringify(object.toJSON(), replacer, space, undefined)
}
const keys: string[] = Array.isArray(replacer) ? replacer.map(Strin... | /**
* Stringify an object
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-starknet/src/utils/json/stringify.ts#L150-L187 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | includeProperty | function includeProperty(key: string, value: unknown): boolean {
return typeof value !== 'undefined' && typeof value !== 'function' && typeof value !== 'symbol'
} | /**
* Test whether to include a property in a stringified object or not.
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-starknet/src/utils/json/stringify.ts#L192-L194 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | resolveSpace | function resolveSpace(space: number | string | undefined): string | undefined {
if (typeof space === 'number') {
return ' '.repeat(space)
}
if (typeof space === 'string' && space !== '') {
return space
}
return undefined
} | /**
* Resolve a JSON stringify space:
* replace a number with a string containing that number of spaces
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-starknet/src/utils/json/stringify.ts#L201-L211 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | b64ToUint6 | function b64ToUint6(nChr: number) {
return nChr > 64 && nChr < 91
? nChr - 65
: nChr > 96 && nChr < 123
? nChr - 71
: nChr > 47 && nChr < 58
? nChr + 4
: nChr === 43
? 62
: nChr === 47
? 63
: 0;
} | // Copyright (c) Mysten Labs, Inc. | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-sui/src/bcs/b64.ts#L11-L23 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | uint6ToB64 | function uint6ToB64(nUint6: number) {
return nUint6 < 26
? nUint6 + 65
: nUint6 < 52
? nUint6 + 71
: nUint6 < 62
? nUint6 - 4
: nUint6 === 62
? 43
: nUint6 === 63
? 47
: 65;
} | /* Base64 string to array encoding */ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-sui/src/bcs/b64.ts#L53-L65 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | BcsReader.constructor | constructor(data: Uint8Array) {
this.dataView = new DataView(data.buffer);
} | /**
* @param {Uint8Array} data Data to use as a buffer.
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-sui/src/bcs/index.ts#L91-L93 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | BcsReader.shift | shift(bytes: number) {
this.bytePosition += bytes;
return this;
} | /**
* Shift current cursor position by `bytes`.
*
* @param {Number} bytes Number of bytes to
* @returns {this} Self for possible chaining.
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-sui/src/bcs/index.ts#L100-L103 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | BcsReader.read8 | read8(): number {
let value = this.dataView.getUint8(this.bytePosition);
this.shift(1);
return value;
} | /**
* Read U8 value from the buffer and shift cursor by 1.
* @returns
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-sui/src/bcs/index.ts#L108-L112 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | BcsReader.read16 | read16(): number {
let value = this.dataView.getUint16(this.bytePosition, true);
this.shift(2);
return value;
} | /**
* Read U16 value from the buffer and shift cursor by 2.
* @returns
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-sui/src/bcs/index.ts#L117-L121 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | BcsReader.read32 | read32(): number {
let value = this.dataView.getUint32(this.bytePosition, true);
this.shift(4);
return value;
} | /**
* Read U32 value from the buffer and shift cursor by 4.
* @returns
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-sui/src/bcs/index.ts#L126-L130 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | BcsReader.read64 | read64(): string {
let value1 = this.read32();
let value2 = this.read32();
let result = value2.toString(16) + value1.toString(16).padStart(8, "0");
return BigInt("0x" + result).toString(10);
} | /**
* Read U64 value from the buffer and shift cursor by 8.
* @returns
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-sui/src/bcs/index.ts#L135-L142 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | BcsReader.read128 | read128(): string {
let value1 = BigInt(this.read64());
let value2 = BigInt(this.read64());
let result = value2.toString(16) + value1.toString(16).padStart(8, "0");
return BigInt("0x" + result).toString(10);
} | /**
* Read U128 value from the buffer and shift cursor by 16.
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-sui/src/bcs/index.ts#L146-L152 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | BcsReader.read256 | read256(): string {
let value1 = BigInt(this.read128());
let value2 = BigInt(this.read128());
let result = value2.toString(16) + value1.toString(16).padStart(16, "0");
return BigInt("0x" + result).toString(10);
} | /**
* Read U128 value from the buffer and shift cursor by 32.
* @returns
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-sui/src/bcs/index.ts#L157-L163 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | BcsReader.readBytes | readBytes(num: number): Uint8Array {
let start = this.bytePosition + this.dataView.byteOffset;
let value = new Uint8Array(this.dataView.buffer, start, num);
this.shift(num);
return value;
} | /**
* Read `num` number of bytes from the buffer and shift cursor by `num`.
* @param num Number of bytes to read.
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-sui/src/bcs/index.ts#L168-L175 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | BcsReader.readULEB | readULEB(): number {
let start = this.bytePosition + this.dataView.byteOffset;
let buffer = new Uint8Array(this.dataView.buffer, start);
let { value, length } = ulebDecode(buffer);
this.shift(length);
return value;
} | /**
* Read ULEB value - an integer of varying size. Used for enum indexes and
* vector lengths.
* @returns {Number} The ULEB value.
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-sui/src/bcs/index.ts#L181-L189 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | BcsReader.readVec | readVec(cb: (reader: BcsReader, i: number, length: number) => any): any[] {
let length = this.readULEB();
let result = [];
for (let i = 0; i < length; i++) {
result.push(cb(this, i, length));
}
return result;
} | /**
* Read a BCS vector: read a length and then apply function `cb` X times
* where X is the length of the vector, defined as ULEB in BCS bytes.
* @param cb Callback to process elements of vector.
* @returns {Array<Any>} Array of the resulting values, returned by callback.
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-sui/src/bcs/index.ts#L196-L203 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | BcsWriter.shift | shift(bytes: number): this {
this.bytePosition += bytes;
return this;
} | /**
* Shift current cursor position by `bytes`.
*
* @param {Number} bytes Number of bytes to
* @returns {this} Self for possible chaining.
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-sui/src/bcs/index.ts#L270-L273 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | BcsWriter.write8 | write8(value: number | bigint): this {
this.ensureSizeOrGrow(1);
this.dataView.setUint8(this.bytePosition, Number(value));
return this.shift(1);
} | /**
* Write a U8 value into a buffer and shift cursor position by 1.
* @param {Number} value Value to write.
* @returns {this}
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-sui/src/bcs/index.ts#L279-L283 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | BcsWriter.write16 | write16(value: number | bigint): this {
this.ensureSizeOrGrow(2);
this.dataView.setUint16(this.bytePosition, Number(value), true);
return this.shift(2);
} | /**
* Write a U16 value into a buffer and shift cursor position by 2.
* @param {Number} value Value to write.
* @returns {this}
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-sui/src/bcs/index.ts#L289-L293 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | BcsWriter.write32 | write32(value: number | bigint): this {
this.ensureSizeOrGrow(4);
this.dataView.setUint32(this.bytePosition, Number(value), true);
return this.shift(4);
} | /**
* Write a U32 value into a buffer and shift cursor position by 4.
* @param {Number} value Value to write.
* @returns {this}
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-sui/src/bcs/index.ts#L299-L303 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | BcsWriter.write64 | write64(value: number | bigint): this {
toLittleEndian(BigInt(value), 8).forEach((el) => this.write8(el));
return this;
} | /**
* Write a U64 value into a buffer and shift cursor position by 8.
* @param {bigint} value Value to write.
* @returns {this}
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-sui/src/bcs/index.ts#L309-L313 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | BcsWriter.write128 | write128(value: number | bigint): this {
toLittleEndian(BigInt(value), 16).forEach((el) => this.write8(el));
return this;
} | /**
* Write a U128 value into a buffer and shift cursor position by 16.
*
* @param {bigint} value Value to write.
* @returns {this}
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-sui/src/bcs/index.ts#L320-L324 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | BcsWriter.write256 | write256(value: number | bigint): this {
toLittleEndian(BigInt(value), 32).forEach((el) => this.write8(el));
return this;
} | /**
* Write a U256 value into a buffer and shift cursor position by 16.
*
* @param {bigint} value Value to write.
* @returns {this}
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-sui/src/bcs/index.ts#L331-L335 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | BcsWriter.writeULEB | writeULEB(value: number): this {
ulebEncode(value).forEach((el) => this.write8(el));
return this;
} | /**
* Write a ULEB value into a buffer and shift cursor position by number of bytes
* written.
* @param {Number} value Value to write.
* @returns {this}
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-sui/src/bcs/index.ts#L342-L345 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | BcsWriter.writeVec | writeVec(
vector: any[],
cb: (writer: BcsWriter, el: any, i: number, len: number) => {}
): this {
this.writeULEB(vector.length);
Array.from(vector).forEach((el, i) => cb(this, el, i, vector.length));
return this;
} | /**
* Write a vector into a buffer by first writing the vector length and then calling
* a callback on each passed value.
*
* @param {Array<Any>} vector Array of elements to write.
* @param {WriteVecCb} cb Callback to call on each element of the vector.
* @returns {this}
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-sui/src/bcs/index.ts#L354-L361 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | BcsWriter.toBytes | toBytes(): Uint8Array {
return new Uint8Array(this.dataView.buffer.slice(0, this.bytePosition));
} | /**
* Get underlying buffer taking only value bytes (in case initial buffer size was bigger).
* @returns {Uint8Array} Resulting bcs.
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-sui/src/bcs/index.ts#L378-L380 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | BcsWriter.toString | toString(encoding: Encoding): string {
return encodeStr(this.toBytes(), encoding);
} | /**
* Represent data as 'hex' or 'base64'
* @param encoding Encoding to use: 'base64' or 'hex'
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-sui/src/bcs/index.ts#L386-L388 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | ulebEncode | function ulebEncode(num: number): number[] {
let arr = [];
let len = 0;
if (num === 0) {
return [0];
}
while (num > 0) {
arr[len] = num & 0x7f;
if ((num >>= 7)) {
arr[len] |= 0x80;
}
len += 1;
}
return arr;
} | // Helper utility: write number as an ULEB array. | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-sui/src/bcs/index.ts#L393-L410 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | ulebDecode | function ulebDecode(arr: number[] | Uint8Array): {
value: number;
length: number;
} {
let total = 0;
let shift = 0;
let len = 0;
while (true) {
let byte = arr[len];
len += 1;
total |= (byte & 0x7f) << shift;
if ((byte & 0x80) === 0) {
break;
}
shift += 7;
}
return {
v... | // Helper utility: decode ULEB as an array of numbers. | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-sui/src/bcs/index.ts#L414-L436 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | BCS.tempKey | private tempKey() {
return `bcs-struct-${++this.counter}`;
} | /**
* Name of the key to use for temporary struct definitions.
* Returns a temp key + index (for a case when multiple temp
* structs are processed).
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-sui/src/bcs/index.ts#L573-L575 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | BCS.constructor | constructor(schema: BcsConfig | BCS) {
// if BCS instance is passed -> clone its schema
if (schema instanceof BCS) {
this.schema = schema.schema;
this.types = new Map(schema.types);
return;
}
this.schema = schema;
// Register address type under key 'address'.
this.registerAdd... | /**
* Construct a BCS instance with a prepared schema.
*
* @param schema A prepared schema with type definitions
* @param withPrimitives Whether to register primitive types by default
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-sui/src/bcs/index.ts#L583-L625 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | BCS.ser | public ser(
type: TypeName | StructTypeDefinition,
data: any,
options?: BcsWriterOptions
): BcsWriter {
if (typeof type === "string" || Array.isArray(type)) {
const { name, params } = this.parseTypeName(type);
return this.getTypeInterface(name).encode(
this,
data,
o... | /**
* Serialize data into bcs.
*
* @example
* bcs.registerVectorType('vector<u8>', 'u8');
*
* let serialized = BCS
* .set('vector<u8>', [1,2,3,4,5,6])
* .toBytes();
*
* console.assert(toHex(serialized) === '06010203040506');
*
* @param type Name of the type to serialize (must be ... | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-sui/src/bcs/index.ts#L644-L671 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | BCS.de | public de(
type: TypeName | StructTypeDefinition,
data: Uint8Array | string,
encoding?: Encoding
): any {
if (typeof data === "string") {
if (encoding) {
data = decodeStr(data, encoding);
} else {
throw new Error("To pass a string to `bcs.de`, specify encoding");
}
... | /**
* Deserialize BCS into a JS type.
*
* @example
* let num = bcs.ser('u64', '4294967295').toString('hex');
* let deNum = bcs.de('u64', num, 'hex');
* console.assert(deNum.toString(10) === '4294967295');
*
* @param type Name of the type to deserialize (must be registered) or a struct type defin... | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-sui/src/bcs/index.ts#L686-L717 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | BCS.hasType | public hasType(type: string): boolean {
return this.types.has(type);
} | /**
* Check whether a `TypeInterface` has been loaded for a `type`.
* @param type Name of the type to check.
* @returns
*/ | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-sui/src/bcs/index.ts#L724-L726 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | BCS.registerAlias | public registerAlias(name: string, forType: string): BCS {
this.types.set(name, forType);
return this;
} | /**
* Create an alias for a type.
* WARNING: this can potentially lead to recursion
* @param name Alias to use
* @param forType Type to reference
* @returns
*
* @example
* ```
* let bcs = new BCS(getSuiMoveConfig());
* bcs.registerAlias('ObjectDigest', BCS.BASE58);
* let b58_digest = bc... | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-sui/src/bcs/index.ts#L742-L745 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | BCS.registerType | public registerType(
typeName: TypeName,
encodeCb: (
writer: BcsWriter,
data: any,
typeParams: TypeName[],
typeMap: { [key: string]: TypeName }
) => BcsWriter,
decodeCb: (
reader: BcsReader,
typeParams: TypeName[],
typeMap: { [key: string]: TypeName }
) => a... | /**
* Method to register new types for BCS internal representation.
* For each registered type 2 callbacks must be specified and one is optional:
*
* - encodeCb(writer, data) - write a way to serialize data with BcsWriter;
* - decodeCb(reader) - write a way to deserialize data with BcsReader;
* - vali... | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-sui/src/bcs/index.ts#L769-L834 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | BCS.registerAddressType | public registerAddressType(
name: string,
length: number,
encoding: Encoding | void = "hex"
): BCS {
switch (encoding) {
case "base64":
return this.registerType(
name,
function encodeAddress(writer, data: string) {
return fromB64(data).reduce(
... | /**
* Register an address type which is a sequence of U8s of specified length.
* @example
* bcs.registerAddressType('address', SUI_ADDRESS_LENGTH);
* let addr = bcs.de('address', 'c3aca510c785c7094ac99aeaa1e69d493122444df50bb8a99dfa790c654a79af');
*
* @param name Name of the address type.
* @param ... | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-sui/src/bcs/index.ts#L847-L882 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
js-wallet-sdk | github_2023 | okx | typescript | BCS.registerVectorType | private registerVectorType(typeName: string): BCS {
let { name, params } = this.parseTypeName(typeName);
if (params.length > 1) {
throw new Error("Vector can have only one type parameter; got " + name);
}
return this.registerType(
typeName,
function encodeVector(
this: BCS,
... | /**
* Register custom vector type inside the bcs.
*
* @example
* bcs.registerVectorType('vector<T>'); // generic registration
* let array = bcs.de('vector<u8>', '06010203040506', 'hex'); // [1,2,3,4,5,6];
* let again = bcs.ser('vector<u8>', [1,2,3,4,5,6]).toString('hex');
*
* @param name Name of... | https://github.com/okx/js-wallet-sdk/blob/dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89/packages/coin-sui/src/bcs/index.ts#L896-L986 | dcb1ce39ebfdf747ec71ee657f11d5b2df0bba89 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.