New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@concordium/common-sdk

Package Overview
Dependencies
Maintainers
4
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@concordium/common-sdk - npm Package Compare versions

Comparing version

to
6.1.0-beta

lib/idProofs.d.ts

2

lib/index.d.ts

@@ -14,2 +14,4 @@ import { sha256 } from './hash';

export { deserializeContractState, deserializeTransaction, deserializeReceiveReturnValue, deserializeReceiveError, deserializeInitError, } from './deserialization';
export * from './idProofs';
export * from './idProofTypes';
export * from './signHelpers';

@@ -16,0 +18,0 @@ export * from './accountHelpers';

@@ -59,2 +59,4 @@ "use strict";

Object.defineProperty(exports, "deserializeInitError", { enumerable: true, get: function () { return deserialization_1.deserializeInitError; } });
__exportStar(require("./idProofs"), exports);
__exportStar(require("./idProofTypes"), exports);
__exportStar(require("./signHelpers"), exports);

@@ -61,0 +63,0 @@ __exportStar(require("./accountHelpers"), exports);

@@ -36,2 +36,30 @@ import { AccountAddress } from './types/accountAddress';

export declare type AttributeKey = keyof Attributes;
export declare enum AttributeKeyString {
firstName = "firstName",
lastName = "lastName",
sex = "sex",
dob = "dob",
countryOfResidence = "countryOfResidence",
nationality = "nationality",
idDocType = "idDocType",
idDocNo = "idDocNo",
idDocIssuer = "idDocIssuer",
idDocIssuedAt = "idDocIssuedAt",
idDocExpiresAt = "idDocExpiresAt",
nationalIdNo = "nationalIdNo",
taxIdNo = "taxIdNo"
}
export declare enum Sex {
NotKnown = "0",
Male = "1",
Female = "2",
NA = "9"
}
export declare enum IdDocType {
NA = "0",
Passport = "1",
NationalIdCard = "2",
DriversLicense = "3",
ImmigrationCard = "4"
}
export declare enum TransactionStatusEnum {

@@ -38,0 +66,0 @@ Received = "received",

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SchemaVersion = exports.buildInvoker = exports.isInstanceInfoV0 = exports.isInstanceInfoV1 = exports.ParameterType = exports.isAccountTransactionType = exports.AccountTransactionType = exports.BlockItemKind = exports.DelegationTargetType = exports.PoolStatusType = exports.BakerPoolPendingChangeType = exports.OpenStatusText = exports.OpenStatus = exports.StakePendingChangeType = exports.instanceOfTransferWithMemoTransactionSummary = exports.RejectReasonTag = exports.TransactionStatusEnum = exports.AttributesKeys = void 0;
exports.SchemaVersion = exports.buildInvoker = exports.isInstanceInfoV0 = exports.isInstanceInfoV1 = exports.ParameterType = exports.isAccountTransactionType = exports.AccountTransactionType = exports.BlockItemKind = exports.DelegationTargetType = exports.PoolStatusType = exports.BakerPoolPendingChangeType = exports.OpenStatusText = exports.OpenStatus = exports.StakePendingChangeType = exports.instanceOfTransferWithMemoTransactionSummary = exports.RejectReasonTag = exports.TransactionStatusEnum = exports.IdDocType = exports.Sex = exports.AttributeKeyString = exports.AttributesKeys = void 0;
var AttributesKeys;

@@ -20,2 +20,33 @@ (function (AttributesKeys) {

})(AttributesKeys = exports.AttributesKeys || (exports.AttributesKeys = {}));
var AttributeKeyString;
(function (AttributeKeyString) {
AttributeKeyString["firstName"] = "firstName";
AttributeKeyString["lastName"] = "lastName";
AttributeKeyString["sex"] = "sex";
AttributeKeyString["dob"] = "dob";
AttributeKeyString["countryOfResidence"] = "countryOfResidence";
AttributeKeyString["nationality"] = "nationality";
AttributeKeyString["idDocType"] = "idDocType";
AttributeKeyString["idDocNo"] = "idDocNo";
AttributeKeyString["idDocIssuer"] = "idDocIssuer";
AttributeKeyString["idDocIssuedAt"] = "idDocIssuedAt";
AttributeKeyString["idDocExpiresAt"] = "idDocExpiresAt";
AttributeKeyString["nationalIdNo"] = "nationalIdNo";
AttributeKeyString["taxIdNo"] = "taxIdNo";
})(AttributeKeyString = exports.AttributeKeyString || (exports.AttributeKeyString = {}));
var Sex;
(function (Sex) {
Sex["NotKnown"] = "0";
Sex["Male"] = "1";
Sex["Female"] = "2";
Sex["NA"] = "9";
})(Sex = exports.Sex || (exports.Sex = {}));
var IdDocType;
(function (IdDocType) {
IdDocType["NA"] = "0";
IdDocType["Passport"] = "1";
IdDocType["NationalIdCard"] = "2";
IdDocType["DriversLicense"] = "3";
IdDocType["ImmigrationCard"] = "4";
})(IdDocType = exports.IdDocType || (exports.IdDocType = {}));
var TransactionStatusEnum;

@@ -22,0 +53,0 @@ (function (TransactionStatusEnum) {

5

package.json
{
"name": "@concordium/common-sdk",
"version": "6.0.0",
"version": "6.1.0-beta",
"license": "Apache-2.0",

@@ -42,3 +42,3 @@ "engines": {

"dependencies": {
"@concordium/rust-bindings": "0.7.0",
"@concordium/rust-bindings": "0.8.0",
"@noble/ed25519": "^1.7.1",

@@ -50,2 +50,3 @@ "@scure/bip39": "^1.1.0",

"hash.js": "^1.1.7",
"iso-3166-1": "^2.1.1",
"json-bigint": "^1.0.0",

@@ -52,0 +53,0 @@ "uuid": "^8.3.2"

@@ -6,2 +6,3 @@ # Common

**Table of Contents**
- [Constructing transactions](#constructing-transactions)

@@ -22,5 +23,18 @@ - [Create a simple transfer](#create-a-simple-transfer)

- [Deserialize contract state](#deserialize-contract-state)
- [Deserialize a receive function's return value](#deserialize-a-receive-functions-return-value)
- [Deserialize a function's error](#deserialize-a-functions-error)
- [Deserialize a transaction](#deserialize-a-transaction)
- [Sign an account transaction](#sign-an-account-transaction)
- [Sign a message](#sign-a-message)
- [Json-Rpc client](#json-rpc-client)
- [Identity proofs](#identity-proofs)
- [Build Statement](#build-statement)
- [Minimum Age](#minimum-age)
- [Eu membership](#eu-membership)
- [Reveal statement](#reveal-statement)
- [Range statement](#range-statement)
- [Membership statement](#membership-statement)
- [Non membership statement](#non-membership-statement)
- [Verify Statement (verifyIdstatement)](#verify-statement-verifyidstatement)
- [Prove Statement (getIdProof)](#prove-statement-getidproof)
- [JSON-RPC client](#json-rpc-client)

@@ -44,3 +58,3 @@ # Constructing transactions

payload: simpleTransfer,
type: AccountTransactionType.SimpleTransfer,
type: AccountTransactionType.Transfer,
};

@@ -65,3 +79,3 @@ ```

payload: simpleTransferWithMemo,
type: AccountTransactionType.SimpleTransferWithMemo,
type: AccountTransactionType.TransferWithMemo,
};

@@ -228,3 +242,3 @@ ```

const deployModule: DeployModulePayload = {
content: wasmModule
source: wasmModule
};

@@ -249,3 +263,3 @@

const deployModule: DeployModulePayload = {
content: wasmModule,
source: wasmModule,
version: 0,

@@ -272,4 +286,4 @@ };

moduleRef: new ModuleReference('a225a5aeb0a5cf9bbc59209e15df030e8cc2c17b8dba08c4bf59f80edaedd8b1'), // Module reference
contractName: contractName,
parameter: params,
initName: contractName,
params: params,
maxContractExecutionEnergy: maxContractExecutionEnergy

@@ -280,3 +294,3 @@ };

payload: initModule,
type: AccountTransactionType.InitializeSmartContractInstance,
type: AccountTransactionType.InitContract,
};

@@ -295,6 +309,6 @@ ```

In this example, the contract does not take any parameters, so we can leave the parameters as an empty buffer.
In this example, the contract does not take any parameters, so we can leave the parameters/message as an empty buffer.
```js
const receiveName = 'INDBank.insertAmount';
const params = Buffer.from([]);
const message = Buffer.from([]);
const contractAddress = { index: BigInt(83), subindex: BigInt(0) } as ContractAddress;

@@ -309,5 +323,5 @@ //The amount of energy that can be used for contract execution.

amount: new CcdAmount(1000n),
contractAddress: contractAddress,
address: contractAddress,
receiveName: receiveName,
parameter: params,
message: message,
maxContractExecutionEnergy: maxContractExecutionEnergy

@@ -318,3 +332,3 @@ };

payload: updateModule,
type: AccountTransactionType.UpdateSmartContractInstance,
type: AccountTransactionType.Update,
};

@@ -392,3 +406,3 @@ ```

contractName: contractName,
parameter: inputParams,
params: inputParams,
maxContractExecutionEnergy: baseEnergy,

@@ -399,3 +413,3 @@ };

payload: initModule,
type: AccountTransactionType.InitializeSmartContractInstance,
type: AccountTransactionType.InitContract,
};

@@ -436,5 +450,5 @@ ```

amount: new CcdAmount(1000n),
contractAddress: contractAddress,
address: contractAddress,
receiveName: receiveName,
parameter: inputParams,
message: inputParams,
maxContractExecutionEnergy: baseEnergy,

@@ -445,3 +459,3 @@ } as UpdateContractPayload;

payload: updateModule,
type: AccountTransactionType.UpdateSmartContractInstance,
type: AccountTransactionType.Update,
};

@@ -531,3 +545,3 @@ ```

...
if (accountTransaction.type === AccountTransactionType.SimpleTransfer) {
if (accountTransaction.type === AccountTransactionType.Transfer) {
// transaction is a simple transfer

@@ -541,3 +555,3 @@ }

Note that currently the only supported account transaction kinds are `SimpleTransfer`, `SimpleTransferWithMemo` and `RegisterData`. If attempting to deserialize other transaction kinds, the function will throw an error;
Note that currently the only supported account transaction kinds are `Transfer`, `TransferWithMemo` and `RegisterData`. If attempting to deserialize other transaction kinds, the function will throw an error;

@@ -607,4 +621,141 @@ ## Sign an account transaction

# Identity proofs
## Build Statement
The SDK contains a helper to create statements about identities, which can then be proven.
To do so, use the IdStatementBuilder, to build a statement:
```js
const statementBuilder = new IdStatementBuilder();
...
const statement = statementBuilder.getStatement();
```
The statement can then be proved using the `getIdProof`, or be provided to a wallet for them it to provide a proof for the statement.
There are currently 4 types of the statements, and if multiple are added, the resulting statement is the conjunction between them.
| Attribute name | Format |
|--------------------|-----------------------------------------------------------------------------|
| firstName | string |
| lastName | string |
| sex | ISO/IEC 5218 |
| dob | ISO8601 YYYYMMDD |
| countryOfResidence | ISO3166-1 alpha-2 |
| nationality | ISO3166-1 alpha-2 |
| idDocType | na=0, passport=1, national id card=2, driving license=3, immigration card=4 |
| idDocNo | string |
| idDocIssuer | ISO3166-1 alpha-2 or ISO3166-2 if applicable |
| idDocIssuedAt | ISO8601 YYYYMMDD |
| idDocExpiresAt | ISO8601 YYYYMMDD |
| nationalIdNo | string |
| taxIdNo | string |
The first parameter of the statement builder is a boolean, which defaults to true, that specifies whether the statement should be checked while being built.
It checks that:
- The used attribute tag is a known one
- There is not multiple statements on the same attribute
- Lower, upper and sets members have the format expected of the attribute
### Minimum Age
There is a helper function for specifying the prover must have some minimum age.
Example: add the statement that the prover must be born at least 18 years old:
```js
statementBuilder.addMinimumAge(18);
```
### Eu membership
There are helpers for specifying the country of residency or nationality to be one of the EU member states.
```js
statementBuilder.addEUNationality();
statementBuilder.addEUResidency();
```
### Reveal statement
State that a given attribute should be revealed as part of the proof.
```js
statementBuilder.revealAttribute(AttributesKeys.nationality);
```
### Range statement
State that a given attribute should be between 2 given values.
Example: add the statement that the prover must be born between January 1, 1941 and Februar 2, 2005.
```js
statementBuilder.addRange(AttributesKeys.dob, 19410101, 20050202);
```
Note that this type of statement is only allowed for the following attributes:
- dob (date of birth)
- idDocIssuedAt
- idDocExpiresAt
### Membership statement
Example: add the statement that the prover's country of residency is France or Spain:
```js
statementBuilder.addMembership(AttributesKeys.CountryOfResidency, ['FR', 'ES']);
```
Note that this type of statement is only allowed for the following attributes:
- Nationality
- CountryOfResidency
- IdDocIssuer
- IdDocType
### Non membership statement
Example: add the statement that the prover's country of residency not Germany nor Portugal:
```js
statementBuilder.addNonMembership(AttributesKeys.CountryOfResidency, ['DE', 'PT']);
```
Note that this type of statement is only allowed for the following attributes:
- Nationality
- CountryOfResidency
- IdDocIssuer
- IdDocType
## Verify Statement (verifyIdstatement)
The SDK provides a helper function to verify a statement, that it is well-formed and complies with the current rules.
The function is `verifyIdstatement` and it will throw an error if the statement does not verify.
Example:
```js
const statement = ...
let isValid = true;
try {
verifyIdstatement(statement);
} catch (e) {
// States why the statement is not valid:
console.log(e.message);
isValid = false;
}
```
## Prove Statement (getIdProof)
The SDK provides a helper function to prove an id statement.
The function is `getIdProof`:
Example:
```js
const statement = ...
const challenge = ...
const proof = getIdProof({
idObject,
globalContext,
seedAsHex,
net: 'Mainnet',
identityProviderIndex,
identityIndex,
credNumber,
statement,
challenge,
})
```
# JSON-RPC client
The SDK also provides a JSON-RPC client, but it is primarily used for web, [so it has been documented in the web-sdk package instead](../web#JSON-RPC-client).
The nodejs SDK also provides a [gRPC client, which can interact directly with a node](../nodejs#ConcordiumNodeClient).