@concordium/common-sdk
Advanced tools
Comparing version
import { sha256 } from './hash'; | ||
export * from './types'; | ||
export { getAccountTransactionHash, getAccountTransactionSignDigest, getCredentialDeploymentSignDigest, getCredentialDeploymentTransactionHash, getCredentialForExistingAccountSignDigest, serializeInitContractParameters, serializeUpdateContractParameters, serializeAccountTransactionForSubmission, serializeCredentialDeploymentTransactionForSubmission, getSignedCredentialDeploymentTransactionHash, } from './serialization'; | ||
export { getAccountTransactionHash, getAccountTransactionSignDigest, getCredentialDeploymentSignDigest, getCredentialDeploymentTransactionHash, getCredentialForExistingAccountSignDigest, serializeInitContractParameters, serializeUpdateContractParameters, serializeAccountTransactionForSubmission, serializeCredentialDeploymentTransactionForSubmission, getSignedCredentialDeploymentTransactionHash, serializeTypeValue, } from './serialization'; | ||
export { sha256 }; | ||
@@ -21,2 +21,3 @@ export { CredentialRegistrationId } from './types/CredentialRegistrationId'; | ||
export * from './HdWallet'; | ||
export * from './schemaHelpers'; | ||
export { isHex } from './util'; | ||
@@ -23,0 +24,0 @@ export { HttpProvider } from './providers/httpProvider'; |
@@ -17,3 +17,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.calculateEnergyCost = exports.getAccountTransactionHandler = exports.JsonRpcClient = exports.HttpProvider = exports.isHex = exports.deserializeInitError = exports.deserializeReceiveError = exports.deserializeReceiveReturnValue = exports.deserializeTransaction = exports.deserializeContractState = exports.getAlias = exports.isAlias = exports.createCredentialV1 = exports.buildSignedCredentialForExistingAccount = exports.getAccountAddress = exports.createUnsignedCredentialForExistingAccount = exports.createCredentialDeploymentTransaction = exports.ModuleReference = exports.DataBlob = exports.TransactionExpiry = exports.CcdAmount = exports.AccountAddress = exports.CredentialRegistrationId = exports.sha256 = 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.JsonRpcClient = exports.HttpProvider = exports.isHex = exports.deserializeInitError = exports.deserializeReceiveError = exports.deserializeReceiveReturnValue = exports.deserializeTransaction = exports.deserializeContractState = exports.getAlias = exports.isAlias = exports.createCredentialV1 = exports.buildSignedCredentialForExistingAccount = exports.getAccountAddress = exports.createUnsignedCredentialForExistingAccount = exports.createCredentialDeploymentTransaction = exports.ModuleReference = exports.DataBlob = exports.TransactionExpiry = exports.CcdAmount = exports.AccountAddress = exports.CredentialRegistrationId = exports.sha256 = 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"); | ||
@@ -33,2 +33,3 @@ Object.defineProperty(exports, "sha256", { enumerable: true, get: function () { return hash_1.sha256; } }); | ||
Object.defineProperty(exports, "getSignedCredentialDeploymentTransactionHash", { enumerable: true, get: function () { return serialization_1.getSignedCredentialDeploymentTransactionHash; } }); | ||
Object.defineProperty(exports, "serializeTypeValue", { enumerable: true, get: function () { return serialization_1.serializeTypeValue; } }); | ||
var CredentialRegistrationId_1 = require("./types/CredentialRegistrationId"); | ||
@@ -68,2 +69,3 @@ Object.defineProperty(exports, "CredentialRegistrationId", { enumerable: true, get: function () { return CredentialRegistrationId_1.CredentialRegistrationId; } }); | ||
__exportStar(require("./HdWallet"), exports); | ||
__exportStar(require("./schemaHelpers"), exports); | ||
var util_1 = require("./util"); | ||
@@ -70,0 +72,0 @@ Object.defineProperty(exports, "isHex", { enumerable: true, get: function () { return util_1.isHex; } }); |
@@ -57,3 +57,3 @@ import { Buffer } from 'buffer/'; | ||
* Returns the digest of the credential deployment transaction that has to be signed. | ||
* @param credentialDeploymentTransaction the credential deployment transaction | ||
* @param credentialDeployment the credential deployment transaction | ||
* @returns the sha256 of the serialized unsigned credential deployment information | ||
@@ -65,3 +65,3 @@ */ | ||
* deployment transaction. | ||
* @param credentialDeploymentTransaction the transaction to hash | ||
* @param credentialDeployment the transaction to hash | ||
* @param signatures the signatures that will also be part of the hash | ||
@@ -74,3 +74,3 @@ * @returns the sha256 hash of the serialized block item kind, signatures, and credential deployment transaction | ||
* submitted to the node. | ||
* @param credentialDeploymentTransaction the credenetial deployment transaction | ||
* @param credentialDeployment the credenetial deployment transaction | ||
* @param signatures the signatures on the hash of unsigned credential deployment information | ||
@@ -97,3 +97,10 @@ * @returns the serialization of the credential deployment transaction ready for being submitted to a node | ||
export declare function serializeUpdateContractParameters(contractName: string, receiveFunctionName: string, parameters: any, rawSchema: Buffer, schemaVersion?: SchemaVersion): Buffer; | ||
/** | ||
* Given a value for a smart contract type, and the raw schema for that type, serialize the value into binary format. | ||
* @param value the value that should be serialized. Should correspond to the JSON representation | ||
* @param rawSchema the schema for the type that the given value should be serialized as | ||
* @returns serialized buffer of the value | ||
*/ | ||
export declare function serializeTypeValue(value: any, rawSchema: Buffer): Buffer; | ||
export declare function serializeSignedCredentialDeploymentDetailsForSubmission(credentialDetails: SignedCredentialDeploymentDetails): Buffer; | ||
export declare function getSignedCredentialDeploymentTransactionHash(credentialDetails: SignedCredentialDeploymentDetails): string; |
@@ -26,3 +26,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getSignedCredentialDeploymentTransactionHash = exports.serializeSignedCredentialDeploymentDetailsForSubmission = exports.serializeUpdateContractParameters = exports.serializeInitContractParameters = exports.serializeCredentialDeploymentTransactionForSubmission = exports.getCredentialDeploymentTransactionHash = exports.getCredentialDeploymentSignDigest = exports.getCredentialForExistingAccountSignDigest = exports.serializeCredentialDeploymentInfo = exports.serializeAccountTransactionForSubmission = exports.getAccountTransactionSignDigest = exports.getAccountTransactionHash = exports.serializeAccountTransaction = exports.serializeAccountTransactionSignature = void 0; | ||
exports.getSignedCredentialDeploymentTransactionHash = exports.serializeSignedCredentialDeploymentDetailsForSubmission = exports.serializeTypeValue = exports.serializeUpdateContractParameters = exports.serializeInitContractParameters = exports.serializeCredentialDeploymentTransactionForSubmission = exports.getCredentialDeploymentTransactionHash = exports.getCredentialDeploymentSignDigest = exports.getCredentialForExistingAccountSignDigest = exports.serializeCredentialDeploymentInfo = exports.serializeAccountTransactionForSubmission = exports.getAccountTransactionSignDigest = exports.getAccountTransactionHash = exports.serializeAccountTransaction = exports.serializeAccountTransactionSignature = void 0; | ||
const buffer_1 = require("buffer/"); | ||
@@ -246,3 +246,3 @@ const accountTransactions_1 = require("./accountTransactions"); | ||
* Returns the digest of the credential deployment transaction that has to be signed. | ||
* @param credentialDeploymentTransaction the credential deployment transaction | ||
* @param credentialDeployment the credential deployment transaction | ||
* @returns the sha256 of the serialized unsigned credential deployment information | ||
@@ -265,3 +265,3 @@ */ | ||
* deployment transaction. | ||
* @param credentialDeploymentTransaction the transaction to hash | ||
* @param credentialDeployment the transaction to hash | ||
* @param signatures the signatures that will also be part of the hash | ||
@@ -278,3 +278,3 @@ * @returns the sha256 hash of the serialized block item kind, signatures, and credential deployment transaction | ||
* submitted to the node. | ||
* @param credentialDeploymentTransaction the credenetial deployment transaction | ||
* @param credentialDeployment the credenetial deployment transaction | ||
* @param signatures the signatures on the hash of unsigned credential deployment information | ||
@@ -327,2 +327,20 @@ * @returns the serialization of the credential deployment transaction ready for being submitted to a node | ||
exports.serializeUpdateContractParameters = serializeUpdateContractParameters; | ||
/** | ||
* Given a value for a smart contract type, and the raw schema for that type, serialize the value into binary format. | ||
* @param value the value that should be serialized. Should correspond to the JSON representation | ||
* @param rawSchema the schema for the type that the given value should be serialized as | ||
* @returns serialized buffer of the value | ||
*/ | ||
function serializeTypeValue( | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types | ||
value, rawSchema) { | ||
const serializedValue = wasm.serializeTypeValue(JSON.stringify(value), rawSchema.toString('hex')); | ||
try { | ||
return buffer_1.Buffer.from(serializedValue, 'hex'); | ||
} | ||
catch (e) { | ||
throw new Error('unable to deserialize value, due to: ' + serializedValue); // In this case serializedValue is the error message from the rust module | ||
} | ||
} | ||
exports.serializeTypeValue = serializeTypeValue; | ||
function serializeSignedCredentialDeploymentDetails(credentialDetails) { | ||
@@ -329,0 +347,0 @@ const serializedBlockItemKind = (0, serializationHelpers_1.encodeWord8)(types_1.BlockItemKind.CredentialDeploymentKind); |
import { AccountAddress } from './types/accountAddress'; | ||
import { CredentialRegistrationId } from './types/CredentialRegistrationId'; | ||
import { CcdAmount } from './types/ccdAmount'; | ||
@@ -7,2 +8,3 @@ import { DataBlob } from './types/DataBlob'; | ||
import { ModuleReference } from './types/moduleReference'; | ||
export declare type HexString = string; | ||
/** | ||
@@ -74,2 +76,3 @@ * Returns a union of all keys of type T with values matching type V. | ||
} | ||
export declare type AccountIdentifierInput = AccountAddress | CredentialRegistrationId | bigint; | ||
export interface TransactionEvent { | ||
@@ -589,3 +592,4 @@ tag: 'ModuleDeployed' | 'ContractInitialized' | 'AccountCreated' | 'CredentialDeployed' | 'BakerAdded' | 'BakerRemoved' | 'BakerStakeIncreased' | 'BakerStakeDecreased' | 'BakerSetRestakeEarnings' | 'BakerKeysUpdated' | 'CredentialKeysUpdated' | 'NewEncryptedAmount' | 'EncryptedAmountsRemoved' | 'AmountAddedByDecryption' | 'EncryptedSelfAmountAdded' | 'UpdateEnqueued' | 'TransferredWithSchedule' | 'CredentialsUpdated' | 'DataRegistered' | 'BakerSetOpenStatus' | 'BakerSetMetadataURL' | 'BakerSetTransactionFeeCommission' | 'BakerSetBakingRewardCommission' | 'BakerSetFinalizationRewardCommission' | 'DelegationStakeIncreased' | 'DelegationStakeDecreased' | 'DelegationSetRestakeEarnings' | 'DelegationSetDelegationTarget' | 'DelegationAdded' | 'DelegationRemoved'; | ||
incomingAmounts: string[]; | ||
numAggregated: number; | ||
numAggregated?: number; | ||
aggregatedAmount?: string; | ||
} | ||
@@ -779,2 +783,3 @@ export interface VerifyKey { | ||
} | ||
export declare type AccountCredential = Versioned<InitialAccountCredential | NormalAccountCredential>; | ||
interface AccountInfoCommon { | ||
@@ -789,3 +794,3 @@ accountAddress: string; | ||
accountReleaseSchedule: AccountReleaseSchedule; | ||
accountCredentials: Record<number, Versioned<InitialAccountCredential | NormalAccountCredential>>; | ||
accountCredentials: Record<number, AccountCredential>; | ||
} | ||
@@ -792,0 +797,0 @@ export declare type AccountInfoSimple = AccountInfoCommon; |
{ | ||
"name": "@concordium/common-sdk", | ||
"version": "6.1.0", | ||
"version": "6.2.0", | ||
"license": "Apache-2.0", | ||
@@ -42,3 +42,3 @@ "engines": { | ||
"dependencies": { | ||
"@concordium/rust-bindings": "0.8.0", | ||
"@concordium/rust-bindings": "0.9.0", | ||
"@noble/ed25519": "^1.7.1", | ||
@@ -45,0 +45,0 @@ "@scure/bip39": "^1.1.0", |
@@ -450,2 +450,22 @@ # Common | ||
## Serialize parameters with only the specific type's schema | ||
In the previous section the schema used was assumed to be the schema for an entire module. In some cases one might want to use a schema containing only the specific type of the parameter. | ||
For this, the function `serializeTypeValue` can used. | ||
``` | ||
const inputParams = serializeTypeValue(userInput, rawTypeSchema); | ||
``` | ||
For reference, the type schema for parameters can be extracted using the functions `getInitContractParameterSchema` and `getUpdateContractParameterSchema`. | ||
``` | ||
const rawTypeSchema = getUpdateContractParameterSchema( | ||
rawModuleSchema, | ||
contractName, | ||
receiveFunctionName, | ||
userInput, | ||
schemaVersion | ||
) | ||
``` | ||
# Utility functions | ||
@@ -452,0 +472,0 @@ |
334637
2.11%67
3.08%6562
1.72%764
2.69%+ Added
- Removed