Skip to content

Commit

Permalink
Merge pull request #7 from blooo-io/feat/LDG-571--js-lib-implement-de…
Browse files Browse the repository at this point in the history
…ploy-method

Feat/ldg 571  js lib implement deploy method
  • Loading branch information
n4l5u0r authored Dec 11, 2024
2 parents d993b0c + 7fbee87 commit 40a1846
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 17 deletions.
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

0 comments on commit 40a1846

Please sign in to comment.