Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/ldg 571 js lib implement deploy method #7

Merged
merged 3 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,11 @@ jobs:
- name: Install node
uses: actions/setup-node@v3
with:
node-version: '16'
node-version: '22'
registry-url: "https://registry.npmjs.org/"
scope: "@blooo"
- name: Install yarn
run: npm install -g yarn
- run: yarn install
- run: yarn build
- run: npm install
- run: npm run build
- name: Get latest release version number
id: get_version
uses: battila7/get-version-action@v2
Expand Down
26 changes: 16 additions & 10 deletions src/Concordium.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ const P2_LAST = 0x00;
const P1_INITIAL_PACKET = 0x00;
const P1_SCHEDULED_TRANSFER_PAIRS = 0x01;

// Deploy Module
const P1_SOURCE = 0x01;

// Update Credentials
const P2_CREDENTIAL_INITIAL = 0x00;
const P2_CREDENTIAL_CREDENTIAL_INDEX = 0x01;
Expand Down Expand Up @@ -578,19 +581,22 @@ export default class Concordium {
*/
async signDeployModule(txn: IDeployModuleTransaction, path: string): Promise<{ signature: string[] }> {

const { payloads } = serializeDeployModule(txn, path);
const { payloadsHeaderAndVersion, payloadSource } = serializeDeployModule(txn, path);

let response;
await this.sendToDevice(
INS.SIGN_DEPLOY_MODULE,
P1_INITIAL_PACKET,
P2_LAST,
payloadsHeaderAndVersion[0]
);

for (let i = 0; i < payloads.length; i++) {
const lastChunk = i === payloads.length - 1;
response = await this.sendToDevice(
INS.SIGN_DEPLOY_MODULE,
P1_FIRST_CHUNK + i,
lastChunk ? P2_LAST : P2_MORE,
payloads[i]
);
}
response = await this.sendToDevice(
INS.SIGN_DEPLOY_MODULE,
P1_SOURCE,
P2_LAST,
payloadSource
);

if (response.length === 1) throw new Error("User has declined.");

Expand Down
13 changes: 11 additions & 2 deletions src/serialization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ const TRANSACTION_FEE_COMMISSION_LENGTH = 4;
const BAKING_REWARD_COMMISSION_LENGTH = 4;
const FINALIZATION_REWARD_COMMISSION_LENGTH = 4;

// Deploy module constants
const VERSION_LENGTH = 4;
const SOURCE_LENGTH_LENGTH = 4;

// Credential and identity-related constants
const REG_ID_LENGTH = 48;
const IP_IDENTITY_LENGTH = 4;
Expand Down Expand Up @@ -422,8 +426,13 @@ export const serializeTransferToPublic = (txn: ITransferToPublicTransaction, pat
* @param {string} path - The BIP32 path as a string.
* @returns {{ payloads: Buffer[] }} - An object containing serialized payloads.
*/
export const serializeDeployModule = (txn: IDeployModuleTransaction, path: string): { payloads: Buffer[] } => {
return serializeTransaction(txn, path);
export const serializeDeployModule = (txn: IDeployModuleTransaction, path: string): { payloadsHeaderAndVersion: Buffer[], payloadSource: Buffer } => {
const txSerialized = serializeAccountTransaction(txn);
const headerAndVersion = txSerialized.subarray(0, HEADER_LENGTH + TRANSACTION_KIND_LENGTH + VERSION_LENGTH + SOURCE_LENGTH_LENGTH);
const payloadSource = txSerialized.subarray(HEADER_LENGTH + TRANSACTION_KIND_LENGTH + VERSION_LENGTH + SOURCE_LENGTH_LENGTH);

const payloadsHeaderAndVersion = serializeTransactionPayloadsWithDerivationPath(path, headerAndVersion);
return {payloadsHeaderAndVersion, payloadSource};
};

/**
Expand Down