@concordium/common-sdk
Advanced tools
Comparing version
@@ -244,3 +244,3 @@ import { Buffer } from 'buffer/'; | ||
* @param blockHeightRequest Either an absolute block height request or a relative block height request | ||
* @returns A lsit of block hashes as hex strings | ||
* @returns A list of block hashes as hex strings | ||
*/ | ||
@@ -247,0 +247,0 @@ getBlocksAtHeight(blockHeightRequest: v1.BlocksAtHeightRequest): Promise<HexString[]>; |
@@ -323,3 +323,3 @@ "use strict"; | ||
const blocks = this.client.getFinalizedBlocks(v2.Empty, opts).responses; | ||
return (0, util_1.mapAsyncIterable)(blocks, translate.commonBlockInfo); | ||
return (0, util_1.mapStream)(blocks, translate.commonBlockInfo); | ||
} | ||
@@ -338,3 +338,3 @@ /** | ||
const blocks = this.client.getBlocks(v2.Empty, opts).responses; | ||
return (0, util_1.mapAsyncIterable)(blocks, translate.commonBlockInfo); | ||
return (0, util_1.mapStream)(blocks, translate.commonBlockInfo); | ||
} | ||
@@ -395,3 +395,3 @@ /** | ||
const asyncIter = this.client.getAccountList(hash, opts).responses; | ||
return (0, util_1.mapAsyncIterable)(asyncIter, translate.unwrapToBase58); | ||
return (0, util_1.mapStream)(asyncIter, translate.unwrapToBase58); | ||
} | ||
@@ -411,3 +411,3 @@ /** | ||
const asyncIter = this.client.getModuleList(hash, opts).responses; | ||
return (0, util_1.mapAsyncIterable)(asyncIter, translate.unwrapValToHex); | ||
return (0, util_1.mapStream)(asyncIter, translate.unwrapValToHex); | ||
} | ||
@@ -431,3 +431,3 @@ /** | ||
const asyncIter = this.client.getAncestors(request, opts).responses; | ||
return (0, util_1.mapAsyncIterable)(asyncIter, translate.unwrapValToHex); | ||
return (0, util_1.mapStream)(asyncIter, translate.unwrapValToHex); | ||
} | ||
@@ -450,3 +450,3 @@ /** | ||
const asyncIter = this.client.getInstanceState(request, opts).responses; | ||
return (0, util_1.mapAsyncIterable)(asyncIter, translate.instanceStateKVPair); | ||
return (0, util_1.mapStream)(asyncIter, translate.instanceStateKVPair); | ||
} | ||
@@ -487,3 +487,3 @@ /** | ||
const ips = this.client.getIdentityProviders(block, opts).responses; | ||
return (0, util_1.mapAsyncIterable)(ips, translate.ipInfo); | ||
return (0, util_1.mapStream)(ips, translate.ipInfo); | ||
} | ||
@@ -503,3 +503,3 @@ /** | ||
const ars = this.client.getAnonymityRevokers(block, opts).responses; | ||
return (0, util_1.mapAsyncIterable)(ars, translate.arInfo); | ||
return (0, util_1.mapStream)(ars, translate.arInfo); | ||
} | ||
@@ -510,3 +510,3 @@ /** | ||
* @param blockHeightRequest Either an absolute block height request or a relative block height request | ||
* @returns A lsit of block hashes as hex strings | ||
* @returns A list of block hashes as hex strings | ||
*/ | ||
@@ -540,3 +540,3 @@ async getBlocksAtHeight(blockHeightRequest) { | ||
const bakers = this.client.getBakerList(block, opts).responses; | ||
return (0, util_1.mapAsyncIterable)(bakers, (x) => x.value); | ||
return (0, util_1.mapStream)(bakers, (x) => x.value); | ||
} | ||
@@ -564,3 +564,3 @@ /** | ||
}).responses; | ||
return (0, util_1.mapAsyncIterable)(delegatorInfo, translate.delegatorInfo); | ||
return (0, util_1.mapStream)(delegatorInfo, translate.delegatorInfo); | ||
} | ||
@@ -585,3 +585,3 @@ /** | ||
const delegatorInfo = this.client.getPoolDelegatorsRewardPeriod(request, { abort: abortSignal }).responses; | ||
return (0, util_1.mapAsyncIterable)(delegatorInfo, translate.delegatorInfo); | ||
return (0, util_1.mapStream)(delegatorInfo, translate.delegatorInfo); | ||
} | ||
@@ -602,3 +602,3 @@ /** | ||
const delegatorInfo = this.client.getPassiveDelegators(getBlockHashInput(blockHash), { abort: abortSignal }).responses; | ||
return (0, util_1.mapAsyncIterable)(delegatorInfo, translate.delegatorInfo); | ||
return (0, util_1.mapStream)(delegatorInfo, translate.delegatorInfo); | ||
} | ||
@@ -618,3 +618,3 @@ /** | ||
const delegatorInfo = this.client.getPassiveDelegatorsRewardPeriod(getBlockHashInput(blockHash), { abort: abortSignal }).responses; | ||
return (0, util_1.mapAsyncIterable)(delegatorInfo, translate.delegatorInfo); | ||
return (0, util_1.mapStream)(delegatorInfo, translate.delegatorInfo); | ||
} | ||
@@ -653,3 +653,3 @@ /** | ||
const transactions = this.client.getAccountNonFinalizedTransactions({ value: accountAddress.decodedAddress }, { abort: abortSignal }).responses; | ||
return (0, util_1.mapAsyncIterable)(transactions, translate.unwrapValToHex); | ||
return (0, util_1.mapStream)(transactions, translate.unwrapValToHex); | ||
} | ||
@@ -666,3 +666,3 @@ /** | ||
const blockItemSummaries = this.client.getBlockTransactionEvents(getBlockHashInput(blockHash), { abort: abortSignal }).responses; | ||
return (0, util_1.mapAsyncIterable)(blockItemSummaries, translate.blockItemSummary); | ||
return (0, util_1.mapStream)(blockItemSummaries, translate.blockItemSummary); | ||
} | ||
@@ -818,3 +818,3 @@ /** | ||
const blockSpecialEvents = this.client.getBlockSpecialEvents(getBlockHashInput(blockHash), { abort: abortSignal }).responses; | ||
return (0, util_1.mapAsyncIterable)(blockSpecialEvents, translate.blockSpecialEvent); | ||
return (0, util_1.mapStream)(blockSpecialEvents, translate.blockSpecialEvent); | ||
} | ||
@@ -831,3 +831,3 @@ /** | ||
const pendingUpdates = this.client.getBlockPendingUpdates(getBlockHashInput(blockHash), { abort: abortSignal }).responses; | ||
return (0, util_1.mapAsyncIterable)(pendingUpdates, translate.pendingUpdate); | ||
return (0, util_1.mapStream)(pendingUpdates, translate.pendingUpdate); | ||
} | ||
@@ -834,0 +834,0 @@ /** |
@@ -22,3 +22,4 @@ import { sha256 } from './hash'; | ||
export * from './schemaHelpers'; | ||
export { isHex } from './util'; | ||
export { getContractName } from './contractHelpers'; | ||
export { isHex, streamToList } from './util'; | ||
export { HttpProvider } from './providers/httpProvider'; | ||
@@ -30,1 +31,4 @@ export { JsonRpcClient } from './JsonRpcClient'; | ||
export { calculateEnergyCost } from './energyCost'; | ||
export * from './uleb128'; | ||
export * from './cis2'; | ||
export * from './cis0'; |
@@ -20,3 +20,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.calculateEnergyCost = exports.getAccountTransactionHandler = exports.ConcordiumGRPCClient = exports.JsonRpcClient = exports.HttpProvider = exports.isHex = exports.deserializeTypeValue = exports.deserializeInitError = exports.deserializeReceiveError = exports.deserializeReceiveReturnValue = exports.deserializeTransaction = exports.deserializeContractState = exports.getAlias = exports.isAlias = exports.ModuleReference = exports.DataBlob = exports.TransactionExpiry = exports.CcdAmount = exports.AccountAddress = exports.CredentialRegistrationId = exports.sha256 = exports.serializeCredentialDeploymentPayload = exports.serializeAccountTransactionPayload = exports.serializeTypeValue = exports.getSignedCredentialDeploymentTransactionHash = exports.serializeCredentialDeploymentTransactionForSubmission = exports.serializeAccountTransactionForSubmission = exports.serializeUpdateContractParameters = exports.serializeInitContractParameters = exports.getCredentialForExistingAccountSignDigest = exports.getCredentialDeploymentTransactionHash = exports.getCredentialDeploymentSignDigest = exports.getAccountTransactionSignDigest = exports.getAccountTransactionHash = void 0; | ||
exports.calculateEnergyCost = exports.getAccountTransactionHandler = exports.ConcordiumGRPCClient = exports.JsonRpcClient = exports.HttpProvider = exports.streamToList = exports.isHex = exports.getContractName = exports.deserializeTypeValue = exports.deserializeInitError = exports.deserializeReceiveError = exports.deserializeReceiveReturnValue = exports.deserializeTransaction = exports.deserializeContractState = exports.getAlias = exports.isAlias = exports.ModuleReference = exports.DataBlob = exports.TransactionExpiry = exports.CcdAmount = exports.AccountAddress = exports.CredentialRegistrationId = exports.sha256 = exports.serializeCredentialDeploymentPayload = exports.serializeAccountTransactionPayload = exports.serializeTypeValue = exports.getSignedCredentialDeploymentTransactionHash = exports.serializeCredentialDeploymentTransactionForSubmission = exports.serializeAccountTransactionForSubmission = exports.serializeUpdateContractParameters = exports.serializeInitContractParameters = exports.getCredentialForExistingAccountSignDigest = exports.getCredentialDeploymentTransactionHash = exports.getCredentialDeploymentSignDigest = exports.getAccountTransactionSignDigest = exports.getAccountTransactionHash = void 0; | ||
const hash_1 = require("./hash"); | ||
@@ -70,4 +70,7 @@ Object.defineProperty(exports, "sha256", { enumerable: true, get: function () { return hash_1.sha256; } }); | ||
__exportStar(require("./schemaHelpers"), exports); | ||
var contractHelpers_1 = require("./contractHelpers"); | ||
Object.defineProperty(exports, "getContractName", { enumerable: true, get: function () { return contractHelpers_1.getContractName; } }); | ||
var util_1 = require("./util"); | ||
Object.defineProperty(exports, "isHex", { enumerable: true, get: function () { return util_1.isHex; } }); | ||
Object.defineProperty(exports, "streamToList", { enumerable: true, get: function () { return util_1.streamToList; } }); | ||
var httpProvider_1 = require("./providers/httpProvider"); | ||
@@ -84,1 +87,4 @@ Object.defineProperty(exports, "HttpProvider", { enumerable: true, get: function () { return httpProvider_1.HttpProvider; } }); | ||
Object.defineProperty(exports, "calculateEnergyCost", { enumerable: true, get: function () { return energyCost_1.calculateEnergyCost; } }); | ||
__exportStar(require("./uleb128"), exports); | ||
__exportStar(require("./cis2"), exports); | ||
__exportStar(require("./cis0"), exports); |
import { Buffer } from 'buffer/'; | ||
import { ConfigureBakerPayload, VerifyKey, ConfigureDelegationPayload } from './types'; | ||
import { ConfigureBakerPayload, VerifyKey, ConfigureDelegationPayload, HexString } from './types'; | ||
import { DataBlob } from './types/DataBlob'; | ||
@@ -79,4 +79,10 @@ export declare function serializeMap<K extends string | number | symbol, T>(map: Record<K, T>, encodeSize: (size: number) => Buffer, encodeKey: (k: string) => Buffer, encodeValue: (t: T) => Buffer): Buffer; | ||
*/ | ||
export declare function packBufferWithWord16Length(buffer: Buffer): Buffer; | ||
export declare function packBufferWithWord16Length(buffer: Buffer, useLittleEndian?: boolean): Buffer; | ||
/** | ||
* Packing a buffer along the with offset of 8 bit length | ||
* @param buffer containing the buffer | ||
* @returns Buffer containing the length of the buffer of 8 bit and buffer. | ||
*/ | ||
export declare function packBufferWithWord8Length(buffer: Buffer): Buffer; | ||
/** | ||
* Convert a hex string to a Buffer | ||
@@ -118,2 +124,15 @@ * @param str hex-encoded string | ||
export declare function serializeConfigureBakerPayload(payload: ConfigureBakerPayload): Buffer; | ||
/** | ||
* Helper function to create a function that deserializes a `HexString` value into a list of dynamic type values | ||
* determined by the deserialization logic defined in the callback function. | ||
* | ||
* @param {Function} deserializer - A callback function invoked with a `Buffer` containing the remaining slice of the full value given by the `input` | ||
* The callback function is expected to return the deserialized value of type `R` along with the number of bytes processed in the format of {value: R, bytesRead: number} | ||
* | ||
* @returns {Function} A function taking a single `HexString` input, returning a list of dynamic type values deserialized according to the `deserializer` function. | ||
*/ | ||
export declare const makeDeserializeListResponse: <R>(deserializer: (buffer: Buffer) => { | ||
value: R; | ||
bytesRead: number; | ||
}) => (value: HexString) => R[]; | ||
export {}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.serializeConfigureBakerPayload = exports.serializeConfigureDelegationPayload = exports.getSerializedConfigureDelegationBitmap = exports.configureDelegationSerializationSpec = exports.orUndefined = exports.isDefined = exports.serializeYearMonth = exports.serializeVerifyKey = exports.encodeHexString = exports.packBufferWithWord16Length = exports.packBufferWithWord32Length = exports.encodeDataBlob = exports.encodeWord16FromString = exports.encodeWord8FromString = exports.encodeWord8 = exports.encodeInt8 = exports.encodeWord16 = exports.encodeInt16 = exports.encodeWord32 = exports.encodeInt32 = exports.encodeWord64 = exports.encodeBool = exports.serializeList = exports.serializeMap = void 0; | ||
exports.makeDeserializeListResponse = exports.serializeConfigureBakerPayload = exports.serializeConfigureDelegationPayload = exports.getSerializedConfigureDelegationBitmap = exports.configureDelegationSerializationSpec = exports.orUndefined = exports.isDefined = exports.serializeYearMonth = exports.serializeVerifyKey = exports.encodeHexString = exports.packBufferWithWord8Length = exports.packBufferWithWord16Length = exports.packBufferWithWord32Length = exports.encodeDataBlob = exports.encodeWord16FromString = exports.encodeWord8FromString = exports.encodeWord8 = exports.encodeInt8 = exports.encodeWord16 = exports.encodeInt16 = exports.encodeWord32 = exports.encodeInt32 = exports.encodeWord64 = exports.encodeBool = exports.serializeList = exports.serializeMap = void 0; | ||
const buffer_1 = require("buffer/"); | ||
@@ -175,4 +175,4 @@ const types_1 = require("./types"); | ||
*/ | ||
function packBufferWithWord16Length(buffer) { | ||
const length = encodeWord16(buffer.length); | ||
function packBufferWithWord16Length(buffer, useLittleEndian = false) { | ||
const length = encodeWord16(buffer.length, useLittleEndian); | ||
return buffer_1.Buffer.concat([length, buffer]); | ||
@@ -182,2 +182,12 @@ } | ||
/** | ||
* Packing a buffer along the with offset of 8 bit length | ||
* @param buffer containing the buffer | ||
* @returns Buffer containing the length of the buffer of 8 bit and buffer. | ||
*/ | ||
function packBufferWithWord8Length(buffer) { | ||
const length = encodeWord8(buffer.length); | ||
return buffer_1.Buffer.concat([length, buffer]); | ||
} | ||
exports.packBufferWithWord8Length = packBufferWithWord8Length; | ||
/** | ||
* Convert a hex string to a Buffer | ||
@@ -319,1 +329,23 @@ * @param str hex-encoded string | ||
exports.serializeConfigureBakerPayload = serializeConfigureBakerPayload; | ||
/** | ||
* Helper function to create a function that deserializes a `HexString` value into a list of dynamic type values | ||
* determined by the deserialization logic defined in the callback function. | ||
* | ||
* @param {Function} deserializer - A callback function invoked with a `Buffer` containing the remaining slice of the full value given by the `input` | ||
* The callback function is expected to return the deserialized value of type `R` along with the number of bytes processed in the format of {value: R, bytesRead: number} | ||
* | ||
* @returns {Function} A function taking a single `HexString` input, returning a list of dynamic type values deserialized according to the `deserializer` function. | ||
*/ | ||
const makeDeserializeListResponse = (deserializer) => (value) => { | ||
const buf = buffer_1.Buffer.from(value, 'hex'); | ||
const n = buf.readUInt16LE(0); | ||
let cursor = 2; // First 2 bytes hold number of token amounts included in response. | ||
const values = []; | ||
for (let i = 0; i < n; i++) { | ||
const { value, bytesRead } = deserializer(buffer_1.Buffer.from(buf.subarray(cursor))); | ||
values.push(value); | ||
cursor += bytesRead; | ||
} | ||
return values; | ||
}; | ||
exports.makeDeserializeListResponse = makeDeserializeListResponse; |
@@ -1,15 +0,67 @@ | ||
import { AccountInfo, AccountTransaction, AccountTransactionSignature } from './types'; | ||
import { AccountInfo, AccountTransaction, AccountTransactionSignature, HexString, SimpleAccountKeys, WalletExportFormat, WithAccountKeys } from './types'; | ||
import { Buffer } from 'buffer/'; | ||
import { AccountAddress } from './types/accountAddress'; | ||
/** | ||
* A structure to use for creating signatures on a given digest. | ||
*/ | ||
export interface AccountSigner { | ||
/** | ||
* Creates a signature of the provided digest | ||
* | ||
* @param {Buffer} digest - The digest to create signatures on. | ||
* | ||
* @returns {Promise<AccountTransactionSignature>} A promise resolving with a set of signatures for a set of credentials corresponding to some account | ||
*/ | ||
sign(digest: Buffer): Promise<AccountTransactionSignature>; | ||
/** | ||
* Returns the amount of signatures that the signer produces | ||
*/ | ||
getSignatureCount(): bigint; | ||
} | ||
/** | ||
* Creates a signer for an account which uses the first credential's first keypair. | ||
* Creates an `AccountSigner` for an account which uses the first credential's first keypair. | ||
* Note that if the account has a threshold > 1 or the first credentials has a threshold > 1, the transaction signed using this will fail. | ||
* @param privateKey the ed25519 private key in HEX format. (First credential's first keypair's private key) | ||
* | ||
* @param {HexString} privateKey - the ed25519 private key in HEX format. (First credential's first keypair's private key) | ||
* | ||
* @returns {AccountSigner} an `AccountSigner` which creates a signature using the first credentials first keypair | ||
*/ | ||
export declare function buildBasicAccountSigner(privateKey: string): AccountSigner; | ||
export declare function buildBasicAccountSigner(privateKey: HexString): AccountSigner; | ||
/** | ||
* Creates an `AccountSigner` for an account exported from a Concordium wallet. | ||
* Creating signatures using the `AccountSigner` will hold signatures for all credentials and all their respective keys included in the export. | ||
* | ||
* @param {WalletExportFormat} walletExport - The wallet export object. | ||
* | ||
* @returns {AccountSigner} An `AccountSigner` which creates signatures using all keys for all credentials | ||
*/ | ||
export declare function buildAccountSigner(walletExport: WalletExportFormat): AccountSigner; | ||
/** | ||
* Creates an `AccountSigner` for an arbitrary format extending the {@link WithAccountKeys} type. | ||
* Creating signatures using the `AccountSigner` will hold signatures for all credentials and all their respective keys included. | ||
* | ||
* @param {AccountKeys} value.accountKeys - Account keys of type {@link AccountKeys} to use for creating signatures | ||
* | ||
* @returns {AccountSigner} An `AccountSigner` which creates signatures using all keys for all credentials | ||
*/ | ||
export declare function buildAccountSigner<T extends WithAccountKeys>(value: T): AccountSigner; | ||
/** | ||
* Creates an `AccountSigner` for the {@link SimpleAccountKeys} type. | ||
* Creating signatures using the `AccountSigner` will hold signatures for all credentials and all their respective keys included. | ||
* | ||
* @param {SimpleAccountKeys} keys - Account keys to use for creating signatures | ||
* | ||
* @returns {AccountSigner} An `AccountSigner` which creates signatures using all keys for all credentials | ||
*/ | ||
export declare function buildAccountSigner(keys: SimpleAccountKeys): AccountSigner; | ||
/** | ||
* Creates an `AccountSigner` for an account which uses the first credential's first keypair. | ||
* Note that if the account has a threshold > 1 or the first credentials has a threshold > 1, the transaction signed using this will fail. | ||
* | ||
* @param {HexString} key - The ed25519 private key in HEX format. (First credential's first keypair's private key) | ||
* | ||
* @returns {AccountSigner} An `AccountSigner` which creates a signature using the first credentials first keypair | ||
*/ | ||
export declare function buildAccountSigner(key: HexString): AccountSigner; | ||
/** | ||
* Helper function to sign an AccountTransaction. | ||
@@ -16,0 +68,0 @@ * @param transaction the account transaction to sign |
@@ -26,3 +26,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.verifyMessageSignature = exports.signMessage = exports.signTransaction = exports.buildBasicAccountSigner = void 0; | ||
exports.verifyMessageSignature = exports.signMessage = exports.signTransaction = exports.buildAccountSigner = exports.buildBasicAccountSigner = void 0; | ||
const serialization_1 = require("./serialization"); | ||
@@ -33,6 +33,11 @@ const ed = __importStar(require("@noble/ed25519")); | ||
const hash_1 = require("./hash"); | ||
const util_1 = require("./util"); | ||
const getSignature = async (digest, privateKey) => buffer_1.Buffer.from(await ed.sign(digest, privateKey)).toString('hex'); | ||
/** | ||
* Creates a signer for an account which uses the first credential's first keypair. | ||
* Creates an `AccountSigner` for an account which uses the first credential's first keypair. | ||
* Note that if the account has a threshold > 1 or the first credentials has a threshold > 1, the transaction signed using this will fail. | ||
* @param privateKey the ed25519 private key in HEX format. (First credential's first keypair's private key) | ||
* | ||
* @param {HexString} privateKey - the ed25519 private key in HEX format. (First credential's first keypair's private key) | ||
* | ||
* @returns {AccountSigner} an `AccountSigner` which creates a signature using the first credentials first keypair | ||
*/ | ||
@@ -45,6 +50,5 @@ function buildBasicAccountSigner(privateKey) { | ||
async sign(digest) { | ||
const signature = buffer_1.Buffer.from(await ed.sign(digest, privateKey)).toString('hex'); | ||
return { | ||
0: { | ||
0: signature, | ||
0: await getSignature(digest, privateKey), | ||
}, | ||
@@ -56,2 +60,41 @@ }; | ||
exports.buildBasicAccountSigner = buildBasicAccountSigner; | ||
const isWalletExport = (value) => value.value?.accountKeys !== undefined; | ||
const isSimpleAccountKeys = (value) => value.value?.accountKeys === undefined && | ||
value.accountKeys === undefined; | ||
const getKeys = (value) => { | ||
if (isSimpleAccountKeys(value)) { | ||
return value; | ||
} | ||
const { keys } = isWalletExport(value) | ||
? value.value.accountKeys | ||
: value.accountKeys; | ||
return (0, util_1.mapRecord)(keys, (credKeys) => (0, util_1.mapRecord)(credKeys.keys, (keyPair) => keyPair.signKey)); | ||
}; | ||
const getCredentialSignature = async (digest, keys) => { | ||
const sig = {}; | ||
for (const key in keys) { | ||
sig[key] = await getSignature(digest, keys[key]); | ||
} | ||
return sig; | ||
}; | ||
function buildAccountSigner(value) { | ||
if (typeof value === 'string') { | ||
return buildBasicAccountSigner(value); | ||
} | ||
const keys = getKeys(value); | ||
const numKeys = Object.values(keys).reduce((acc, credKeys) => acc + BigInt(Object.keys(credKeys).length), 0n); | ||
return { | ||
getSignatureCount() { | ||
return numKeys; | ||
}, | ||
async sign(digest) { | ||
const sig = {}; | ||
for (const key in keys) { | ||
sig[key] = await getCredentialSignature(digest, keys[key]); | ||
} | ||
return sig; | ||
}, | ||
}; | ||
} | ||
exports.buildAccountSigner = buildAccountSigner; | ||
/** | ||
@@ -58,0 +101,0 @@ * Helper function to sign an AccountTransaction. |
@@ -19,2 +19,3 @@ import { AccountAddress } from './types/accountAddress'; | ||
export declare type Base58String = string; | ||
export declare type Base64String = string; | ||
export declare type DigitString = string; | ||
@@ -554,4 +555,8 @@ export declare type UrlString = string; | ||
schemeId: string; | ||
verifyKey: string; | ||
verifyKey: HexString; | ||
} | ||
export interface KeyPair { | ||
signKey: HexString; | ||
verifyKey: HexString; | ||
} | ||
export interface CredentialPublicKeys { | ||
@@ -561,2 +566,24 @@ keys: Record<number, VerifyKey>; | ||
} | ||
export interface CredentialKeys { | ||
keys: Record<number, KeyPair>; | ||
threshold: number; | ||
} | ||
export interface AccountKeys { | ||
keys: Record<number, CredentialKeys>; | ||
threshold: number; | ||
} | ||
export declare type SimpleAccountKeys = Record<number, Record<number, HexString>>; | ||
export interface WithAccountKeys { | ||
accountKeys: AccountKeys; | ||
} | ||
export interface WalletExportFormat { | ||
type: string; | ||
v: number; | ||
environment: string; | ||
value: { | ||
accountKeys: AccountKeys; | ||
address: Base58String; | ||
credentials: Record<number, HexString>; | ||
}; | ||
} | ||
export interface ChainArData { | ||
@@ -563,0 +590,0 @@ encIdCredPubShare: string; |
@@ -58,3 +58,3 @@ import { AccountTransactionSignature, HexString, IpAddressString } from './types'; | ||
*/ | ||
export declare function mapAsyncIterable<A, B>(stream: AsyncIterable<A>, mapper: (x: A) => B): AsyncIterable<B>; | ||
export declare function mapStream<A, B>(stream: AsyncIterable<A>, mapper: (x: A) => B): AsyncIterable<B>; | ||
/** | ||
@@ -66,2 +66,22 @@ * Filters entries from a record | ||
export declare function filterRecord<A extends string | number | symbol, B>(rec: Record<A, B>, predicate: (k: A, v: B) => boolean): Record<A, B>; | ||
export declare function asyncIterableToList<A>(iterable: AsyncIterable<A>): Promise<A[]>; | ||
export declare function streamToList<A>(iterable: AsyncIterable<A>): Promise<A[]>; | ||
/** | ||
* Creates a function that takes either a `T` or `T[]` from a function that takes `T[]`. | ||
* | ||
* @param {(input: T[]) => R} fun - A function that takes `T[]` | ||
* | ||
* @example | ||
* const serializer = makeDynamicFunction(serialize); | ||
* const exampleStruct = { | ||
tokenId: ''; | ||
tokenAmount: 100n; | ||
from: { | ||
address: "3nsRkrtQVMRtD2Wvm88gEDi6UtqdUVvRN3oGZ1RqNJ3eto8owi" | ||
}; | ||
to: 3nsRkrtQVMRtD2Wvm88gEDi6UtqdUVvRN3oGZ1RqNJ3eto8owi; | ||
data: '48656c6c6f20776f726c6421'; | ||
}; | ||
* const bytesSingle = serializer(exampleStruct); | ||
* const bytesMulti = serializer([exampleStruct, exampleStruct]); | ||
*/ | ||
export declare const makeDynamicFunction: <T, R>(fun: (a: T[]) => R) => (input: T | T[]) => R; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.asyncIterableToList = exports.filterRecord = exports.mapAsyncIterable = exports.mapRecord = exports.unwrap = exports.secondsSinceEpoch = exports.countSignatures = exports.isValidIp = exports.isValidHash = exports.isHex = exports.buildJsonResponseReviver = exports.intToStringTransformer = exports.stringToInt = void 0; | ||
exports.makeDynamicFunction = exports.streamToList = exports.filterRecord = exports.mapStream = exports.mapRecord = exports.unwrap = exports.secondsSinceEpoch = exports.countSignatures = exports.isValidIp = exports.isValidHash = exports.isHex = exports.buildJsonResponseReviver = exports.intToStringTransformer = exports.stringToInt = void 0; | ||
/** | ||
@@ -156,3 +156,3 @@ * Replaces a number in a JSON string with the same number as a | ||
*/ | ||
function mapAsyncIterable(stream, mapper) { | ||
function mapStream(stream, mapper) { | ||
return { | ||
@@ -177,3 +177,3 @@ [Symbol.asyncIterator]() { | ||
} | ||
exports.mapAsyncIterable = mapAsyncIterable; | ||
exports.mapStream = mapStream; | ||
/** | ||
@@ -188,4 +188,4 @@ * Filters entries from a record | ||
exports.filterRecord = filterRecord; | ||
// Converts an async iterable to a list. Beware! this will not terminate if given an infinite stream. | ||
async function asyncIterableToList(iterable) { | ||
// Converts an async iterable to a list. Beware! This will not terminate if given an infinite stream. | ||
async function streamToList(iterable) { | ||
const list = []; | ||
@@ -197,2 +197,23 @@ for await (const iter of iterable) { | ||
} | ||
exports.asyncIterableToList = asyncIterableToList; | ||
exports.streamToList = streamToList; | ||
/** | ||
* Creates a function that takes either a `T` or `T[]` from a function that takes `T[]`. | ||
* | ||
* @param {(input: T[]) => R} fun - A function that takes `T[]` | ||
* | ||
* @example | ||
* const serializer = makeDynamicFunction(serialize); | ||
* const exampleStruct = { | ||
tokenId: ''; | ||
tokenAmount: 100n; | ||
from: { | ||
address: "3nsRkrtQVMRtD2Wvm88gEDi6UtqdUVvRN3oGZ1RqNJ3eto8owi" | ||
}; | ||
to: 3nsRkrtQVMRtD2Wvm88gEDi6UtqdUVvRN3oGZ1RqNJ3eto8owi; | ||
data: '48656c6c6f20776f726c6421'; | ||
}; | ||
* const bytesSingle = serializer(exampleStruct); | ||
* const bytesMulti = serializer([exampleStruct, exampleStruct]); | ||
*/ | ||
const makeDynamicFunction = (fun) => (input) => fun(Array.isArray(input) ? input : [input]); | ||
exports.makeDynamicFunction = makeDynamicFunction; |
{ | ||
"name": "@concordium/common-sdk", | ||
"version": "6.4.2", | ||
"version": "6.5.0", | ||
"license": "Apache-2.0", | ||
@@ -5,0 +5,0 @@ "engines": { |
@@ -27,4 +27,6 @@ # Common | ||
- [Deserialize a transaction](#deserialize-a-transaction) | ||
- [Creating an AccountSigner](#creating-an-accountsigner) | ||
- [Sign an account transaction](#sign-an-account-transaction) | ||
- [Sign a message](#sign-a-message) | ||
- [Check smart contract for support for standards](#check-smart-contract-for-support-for-standards) | ||
- [Identity proofs](#identity-proofs) | ||
@@ -42,2 +44,3 @@ - [Build Statement](#build-statement) | ||
- [JSON-RPC client](#json-rpc-client) | ||
- [CIS-2 Contract](#cis-2-contract) | ||
@@ -612,2 +615,24 @@ # Constructing transactions | ||
## Creating an `AccountSigner` | ||
It is possible to build an `AccountSigner` in a variety of ways by utilizing the function `buildAccountSigner`. For a simple account, with a single credential and one keypair in the credential, one can supply a single private key, like so: | ||
```js | ||
const privateKey = '...'; // Private key of an account as hex string | ||
const signer: AccountSigner = buildAccountSigner(privateKey); | ||
``` | ||
For a more complex account with one or more credentials, each with one or more keypairs, `buildAccountSigner` is also compatible with the format created by the chain genesis tool, Concordium wallet exports, along with a map of type `SimpleAccountKeys`. | ||
```js | ||
const keys: SimpleAccountKeys = { | ||
0: { | ||
0: '...', // Private key of an account as hex string | ||
1: '...', | ||
... | ||
}, | ||
... | ||
}; | ||
const signer: AccountSigner = buildAccountSigner(keys); | ||
``` | ||
## Sign an account transaction | ||
@@ -627,5 +652,2 @@ The following example demonstrates how to use the `signTransaction` helper function to sign a account transaction: | ||
For a simple account, with a single credential and one keypair in the credential, one can use the `buildBasicAccountSigner` to get the signer. Otherwise one needs to implement the AccountSigner interface themselves, for now. | ||
The `buildBasicAccountSigner` function take the account's private key as a hex string. | ||
The following is an example of how to sign an account transaction without using the `signTransaction` helper function: | ||
@@ -688,2 +710,16 @@ ```js | ||
## Check smart contract for support for standards | ||
To check if a smart contract supports a certain standard (according to [CIS-0 standard detection](https://proposals.concordium.software/CIS/cis-0.html)), the utility function `cis0Supports` can be used. It should be noted, that the support of the contract is purely based on the claims of the contract and does not give any guarantees for whether the contract adheres to the standard it claims to implement. The function returns `undefined` if the contract does not support CIS-0. | ||
This requires a [`ConcordiumNodeClient`](../../docs/gRPC.md). | ||
```js | ||
const client = ...; // `ConcordiumNodeClient` | ||
const address = {index: 1234n, subindex: 0n}; // Contract to check for support. | ||
const standardId = 'CIS-2'; | ||
// const standardIds = ['CIS-1', 'CIS-2']; // Example of a list of standards to check for. | ||
const supportResult = await cis0Supports(client, address, 'CIS-2'); | ||
``` | ||
# Identity proofs | ||
@@ -839,1 +875,6 @@ ## Build Statement | ||
The SDK also provides a JSON-RPC client, [check here for the documentation](../../docs/JSON-RPC.md). | ||
# CIS-2 contract | ||
The SDK provides a class for interacting with smart contracts adhering to the [CIS-2 standard](https://proposals.concordium.software/CIS/cis-2.html). | ||
For an overview of the class, [check here](../../docs/CIS2Contract.md). |
1222477
6.17%102
13.33%27715
5.87%875
4.92%