Skip to content

Commit

Permalink
Updated dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
vlasonfa committed Oct 20, 2023
1 parent 1db8e29 commit 47d1d66
Show file tree
Hide file tree
Showing 13 changed files with 5,759 additions and 9,716 deletions.
15,332 changes: 5,680 additions & 9,652 deletions package-lock.json

Large diffs are not rendered by default.

32 changes: 17 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
{
"dependencies": {
"@types/node": "^17.0.19",
"amazon-qldb-driver-nodejs": "2.2.0",
"aws-sdk": "^2.1079.0",
"ion-js": "^4.2.1",
"@aws-sdk/client-qldb": "^3.431.0",
"@aws-sdk/node-http-handler": "^3.374.0",
"@aws-sdk/smithy-client": "^3.374.0",
"@types/node": "^20.8.7",
"amazon-qldb-driver-nodejs": "3.0.1",
"ion-hash-js": "^2.0.0",
"ion-js": "^4.3.0",
"jsbi": "^3.1.1",
"log4js": "^6.4.1"
"log4js": "^6.9.1"
},
"name": "amazon-qldb-kvs-nodejs",
"description": "A helper module, simplifying basic interactions with Amazon Quantum Ledger Database for Node.js through a simple key-value store interface.",
"version": "0.8.0",
"version": "0.9.0",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^5.12.1",
"@typescript-eslint/parser": "^5.12.1",
"eslint": "^8.9.0",
"@typescript-eslint/eslint-plugin": "^6.8.0",
"@typescript-eslint/parser": "^6.8.0",
"eslint": "^8.51.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-plugin-import": "^2.25.4",
"eslint-plugin-sonarjs": "^0.12.0",
"jest": "^27.5.1",
"ts-node": "^10.5.0",
"typedoc": "^0.22.12",
"typescript": "^4.5.5"
"eslint-plugin-import": "^2.28.1",
"eslint-plugin-sonarjs": "^0.21.0",
"jest": "^29.7.0",
"ts-node": "^10.9.1",
"typedoc": "^0.25.2",
"typescript": "^5.2.2"
},
"scripts": {
"build": "npm run lint && tsc",
Expand Down
2 changes: 1 addition & 1 deletion src/BlockAddress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import { ValueHolder } from "aws-sdk/clients/qldb";
import { ValueHolder } from "@aws-sdk/client-qldb";
import { dom, IonTypes } from "ion-js";
import { log } from "./Logging";
const logger = log.getLogger("qldb-helper");
Expand Down
9 changes: 6 additions & 3 deletions src/ConnectToLedger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
*/

import { QldbDriver } from "amazon-qldb-driver-nodejs";
import { ClientConfiguration } from "aws-sdk/clients/qldbsession";
import { QLDBSessionClientConfig } from "@aws-sdk/client-qldb-session";
import { NodeHttpHandlerOptions } from "@aws-sdk/node-http-handler";
import { log } from "./Logging";
const logger = log.getLogger("qldb-helper");

Expand All @@ -32,14 +33,16 @@ const logger = log.getLogger("qldb-helper");
* See {@link https://docs.aws.amazon.com/qldb/latest/developerguide/driver.best-practices.html#driver.best-practices.configuring} for more details.
* @returns The pooled driver for creating sessions.
*/
const nodeHttpHandlerOptions: NodeHttpHandlerOptions = {};

export function createQldbDriver(
ledgerName: string,
serviceConfigurationOptions: ClientConfiguration = {},
serviceConfigurationOptions: QLDBSessionClientConfig = {},
maxConcurrentTransactions: number = 5,
): QldbDriver {
const fcnName = '[createQldbDriver]';

logger.debug(`${fcnName} maxConcurrentTransactions: ${maxConcurrentTransactions}`);

return new QldbDriver(ledgerName, serviceConfigurationOptions, maxConcurrentTransactions);
return new QldbDriver(ledgerName, serviceConfigurationOptions, nodeHttpHandlerOptions, maxConcurrentTransactions);
}
33 changes: 20 additions & 13 deletions src/GetBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,23 @@
* limitations under the License.
*/

import { QLDB } from "aws-sdk";
import { Digest, GetBlockRequest, GetBlockResponse, GetDigestResponse, ValueHolder } from "aws-sdk/clients/qldb";


import {
GetBlockCommandInput,
GetBlockCommandOutput,
GetDigestCommandOutput,
QLDB,
ValueHolder,
} from "@aws-sdk/client-qldb";

import { toBase64 } from "ion-js";

import { getLedgerDigest } from './GetDigest';
import { log } from "./Logging";
const logger = log.getLogger("qldb-helper");
import { blockResponseToString, valueHolderToString } from "./Util";
import { blockResponseToString, valueHolderToString, Base64EncodedString } from "./Util";
import { flipRandomBit, parseBlock, verifyDocumentMetadata } from "./Verifier";
import { Base64EncodedString } from "aws-sdk/clients/elastictranscoder";

/**
* Get the block of a ledger's journal.
Expand All @@ -32,16 +39,16 @@ import { Base64EncodedString } from "aws-sdk/clients/elastictranscoder";
* @param qldbClient The QLDB control plane client to use.
* @returns Promise which fulfills with a GetBlockResponse.
*/
async function getBlock(ledgerName: string, blockAddress: ValueHolder, qldbClient: QLDB): Promise<GetBlockResponse> {
async function getBlock(ledgerName: string, blockAddress: ValueHolder, qldbClient: QLDB): Promise<GetBlockCommandOutput> {
logger.debug(
`Let's get the block for block address \n${valueHolderToString(blockAddress)} \nof the ledger ` +
`named ${ledgerName}.`
);
const request: GetBlockRequest = {
const request: GetBlockCommandInput = {
Name: ledgerName,
BlockAddress: blockAddress
};
const result: GetBlockResponse = await qldbClient.getBlock(request).promise();
const result: GetBlockCommandOutput = await qldbClient.getBlock(request);
logger.debug(`Success. GetBlock: \n${blockResponseToString(result)}.`);
return result;
}
Expand All @@ -59,17 +66,17 @@ async function getBlockWithProof(
blockAddress: ValueHolder,
digestTipAddress: ValueHolder,
qldbClient: QLDB
): Promise<GetBlockResponse> {
): Promise<GetBlockCommandOutput> {
logger.debug(
`Let's get the block for block address \n${valueHolderToString(blockAddress)}, \ndigest tip address:
${valueHolderToString(digestTipAddress)} \nof the ledger named ${ledgerName}.`
);
const request: GetBlockRequest = {
const request: GetBlockCommandInput = {
Name: ledgerName,
BlockAddress: blockAddress,
DigestTipAddress: digestTipAddress
};
const result: GetBlockResponse = await qldbClient.getBlock(request).promise();
const result: GetBlockCommandOutput = await qldbClient.getBlock(request);
logger.debug(`Success. GetBlock: \n${blockResponseToString(result)}.`);
return result;
}
Expand All @@ -86,15 +93,15 @@ export async function verifyBlock(ledgerName: string, blockAddress: ValueHolder,
logger.debug(`Let's verify blocks for ledger with name = ${ledgerName}.`);
try {
logger.debug("First, let's get a digest.");
const digestResult: GetDigestResponse = await getLedgerDigest(ledgerName, qldbClient);
const digestBytes: Digest = digestResult.Digest;
const digestResult: GetDigestCommandOutput = await getLedgerDigest(ledgerName, qldbClient);
const digestBytes: Uint8Array = digestResult.Digest;
const digestTipAddress: ValueHolder = digestResult.DigestTipAddress;
logger.debug(
`Got a ledger digest. Digest end address = \n${valueHolderToString(digestTipAddress)}, ` +
`\ndigest = ${toBase64(<Uint8Array>digestBytes)}.`
);

const getBlockResult: GetBlockResponse = await getBlockWithProof(
const getBlockResult: GetBlockCommandOutput = await getBlockWithProof(
ledgerName,
blockAddress,
digestTipAddress,
Expand Down
11 changes: 6 additions & 5 deletions src/GetDigest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,19 @@
* limitations under the License.
*/

import { QLDB } from "aws-sdk";
import { GetDigestRequest, GetDigestResponse } from "aws-sdk/clients/qldb";


import { GetDigestCommandInput, GetDigestCommandOutput, QLDB } from "@aws-sdk/client-qldb";

/**
* Get the digest of a ledger's journal.
* @param ledgerName Name of the ledger to operate on.
* @param qldbClient The QLDB control plane client to use.
* @returns Promise which fulfills with a GetDigestResponse.
*/
export async function getLedgerDigest(ledgerName: string, qldbClient: QLDB): Promise<GetDigestResponse> {
const request: GetDigestRequest = {
export async function getLedgerDigest(ledgerName: string, qldbClient: QLDB): Promise<GetDigestCommandOutput> {
const request: GetDigestCommandInput = {
Name: ledgerName
};
return qldbClient.getDigest(request).promise();
return qldbClient.getDigest(request);
}
2 changes: 1 addition & 1 deletion src/GetDocumentHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { validateTableNameConstrains, validateStringAsISODateTime } from "./Util
import { getDocumentIdsAndVersions } from "./GetDocument";
import { dom } from "ion-js";
import { log } from "./Logging";
import { ValueHolder } from "aws-sdk/clients/qldbsession";
import { ValueHolder } from "@aws-sdk/client-qldb-session";
const logger = log.getLogger("qldb-helper");

/**
Expand Down
9 changes: 4 additions & 5 deletions src/GetMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@
*/

import { Result, TransactionExecutor } from "amazon-qldb-driver-nodejs";
import { QLDB } from "aws-sdk";
import { GetRevisionResponse, ValueHolder } from "aws-sdk/clients/qldb";
import { GetRevisionCommandOutput, QLDB, ValueHolder } from "@aws-sdk/client-qldb";
import { dom, toBase64 } from "ion-js";

import { getLedgerDigest } from './GetDigest';
import { blockAddressToValueHolder, getMetadataId } from './BlockAddress';
import { log } from "./Logging";
const logger = log.getLogger("qldb-helper");
import { getBlobValue, valueHolderToString, Base64EncodedString, sleep, validateTableNameConstrains, validateAttributeNameConstrains } from "./Util";
import { getBlobValue, valueHolderToString, Digest, Base64EncodedString, sleep, validateTableNameConstrains, validateAttributeNameConstrains } from "./Util";
import { getRevision, getRevisionMetadataByDocIdAndTxId } from "./GetRevision";

export interface LedgerMetadata {
Expand Down Expand Up @@ -150,7 +149,7 @@ export async function getDocumentLedgerMetadata(
digestTipAddress: digestTipAddress
})}`);

const revisionResponse: GetRevisionResponse = await getRevision(
const revisionResponse: GetRevisionCommandOutput = await getRevision(
ledgerName,
documentId,
blockAddress,
Expand Down Expand Up @@ -250,7 +249,7 @@ export async function getDocumentLedgerMetadataByDocIdAndTxId(
digestTipAddress: digestTipAddress
})}`);

const revisionResponse: GetRevisionResponse = await getRevision(
const revisionResponse: GetRevisionCommandOutput = await getRevision(
ledgerName,
documentId,
blockAddress,
Expand Down
9 changes: 4 additions & 5 deletions src/GetRevision.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
*/

import { Result, TransactionExecutor } from "amazon-qldb-driver-nodejs";
import { QLDB } from "aws-sdk";
import { GetRevisionRequest, GetRevisionResponse, ValueHolder } from "aws-sdk/clients/qldb";
import { GetRevisionCommandInput, GetRevisionCommandOutput, QLDB, ValueHolder } from "@aws-sdk/client-qldb";
import { Base64EncodedString, validateTableNameConstrains } from "./Util";
import { dom } from "ion-js";

Expand All @@ -39,16 +38,16 @@ export async function getRevision(
blockAddress: ValueHolder,
digestTipAddress: ValueHolder,
qldbClient: QLDB
): Promise<GetRevisionResponse> {
): Promise<GetRevisionCommandOutput> {
const fcnName = "[GetRevision getRevision]"
try {
const request: GetRevisionRequest = {
const request: GetRevisionCommandInput = {
Name: ledgerName,
BlockAddress: blockAddress,
DocumentId: documentId,
DigestTipAddress: digestTipAddress
};
return await qldbClient.getRevision(request).promise();
return await qldbClient.getRevision(request);
} catch (err) {
throw `${fcnName} ${err} `
}
Expand Down
7 changes: 3 additions & 4 deletions src/QLDBKVS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import { QldbDriver, TransactionExecutor, Result } from "amazon-qldb-driver-nodejs";
import { QLDB } from "aws-sdk";
import { GetDigestCommandOutput, GetRevisionCommandOutput, QLDB } from "@aws-sdk/client-qldb";
import { createTableWithIndex, listTables } from "./QLDBHelper";
import { getByKeyAttribute, getByKeyAttributes, GetDocumentResult } from "./GetDocument"
import { getLedgerDigest } from './GetDigest';
Expand All @@ -30,7 +30,6 @@ import { log } from "./Logging";
import { createQldbDriver } from "./ConnectToLedger"

import { VALUE_ATTRIBUTE_NAME, KEY_ATTRIBUTE_NAME, DEFAULT_DOWNLOADS_PATH, MAX_QLDB_DOCUMENT_SIZE, TABLE_CREATION_MAX_WAIT } from "./Constants";
import { GetRevisionResponse } from "aws-sdk/clients/qldb";
import { makeReader, dom, load } from "ion-js";

const qldbClient: QLDB = new QLDB();
Expand Down Expand Up @@ -649,7 +648,7 @@ export class QLDBKVS {

logger.debug(`${fcnName} Retrieving document revision by metadata ${ledgerMetadata.DocumentId} from ledger ${ledgerName}`);

const revisionResponse: GetRevisionResponse = await getRevision(ledgerName,
const revisionResponse: GetRevisionCommandOutput = await getRevision(ledgerName,
ledgerMetadata.DocumentId,
ledgerMetadata.BlockAddress,
ledgerMetadata.LedgerDigest.DigestTipAddress,
Expand Down Expand Up @@ -693,7 +692,7 @@ export class QLDBKVS {
* @param ledgerName A name of the ledger
* @throws Error: If error happen during the process.
*/
async getLedgerDigest(ledgerName: string, qldbClient: QLDB): Promise<QLDB.GetDigestResponse> {
async getLedgerDigest(ledgerName: string, qldbClient: QLDB): Promise<GetDigestCommandOutput> {
const fcnName = "[QLDBHelper.getLedgerDigest]"
return getLedgerDigest(ledgerName, qldbClient);
}
Expand Down
4 changes: 3 additions & 1 deletion src/Util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import { GetBlockResponse, GetDigestResponse, ValueHolder } from "aws-sdk/clients/qldb";
import { GetBlockResponse, GetDigestResponse, ValueHolder } from "@aws-sdk/client-qldb";
import {
decodeUtf8,
dom,
Expand All @@ -32,6 +32,8 @@ const logger = log.getLogger("qldb-helper");

export type Base64EncodedString = string;

export type Digest = Base64EncodedString | undefined;

/**
* Returns the string representation of a given BlockResponse.
* @param blockResponse The BlockResponse to convert to string.
Expand Down
2 changes: 1 addition & 1 deletion src/Verifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import { ValueHolder } from "aws-sdk/clients/qldb";
import { ValueHolder } from "@aws-sdk/client-qldb";
import { createHash } from "crypto";
import { dom, toBase64 } from "ion-js";
import { log } from "./Logging";
Expand Down
23 changes: 13 additions & 10 deletions src/VerifyLedgerMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,20 @@
*/

import { TransactionExecutor } from "amazon-qldb-driver-nodejs";
import { QLDB } from "aws-sdk";
import { Digest, GetDigestResponse, GetRevisionResponse, ValueHolder } from "aws-sdk/clients/qldb";

import {
GetDigestCommandOutput,
GetRevisionCommandOutput,
QLDB,
ValueHolder,
} from "@aws-sdk/client-qldb";

import { dom, toBase64 } from "ion-js";

import { blockAddressToValueHolder } from './BlockAddress';
import { log } from "./Logging";
const logger = log.getLogger("qldb-helper");
import { getBlobValue, valueHolderToString, Base64EncodedString } from "./Util";
import { Digest, getBlobValue, valueHolderToString, Base64EncodedString } from "./Util";
import { flipRandomBit, verifyDocumentMetadata } from "./Verifier";
import { getDocumentLedgerMetadata, LedgerMetadata } from "./GetMetadata";
import { getRevision } from "./GetRevision"
Expand Down Expand Up @@ -50,14 +56,13 @@ export async function verifyDocumentMetadataWithLedgerData(

const result = await getDocumentLedgerMetadata(txn, ledgerName, tableName, keyAttributeName, keyAttributeValue, qldbClient);

const digest: GetDigestResponse = result.LedgerDigest;
const digestBytes: Digest = digest.Digest;
const digestTipAddress: ValueHolder = digest.DigestTipAddress;
const digestBase64: Digest = result.LedgerDigest.Digest;
const digestTipAddress: ValueHolder = result.LedgerDigest.DigestTipAddress;

const blockAddress: ValueHolder = result.BlockAddress;
const documentId: string = result.DocumentId;

const revisionResponse: GetRevisionResponse = await getRevision(
const revisionResponse: GetRevisionCommandOutput = await getRevision(
ledgerName,
documentId,
blockAddress,
Expand All @@ -70,8 +75,6 @@ export async function verifyDocumentMetadataWithLedgerData(
const proof: ValueHolder = revisionResponse.Proof;
logger.debug(`Got back a proof: ${valueHolderToString(proof)}.`);

const digestBase64: Base64EncodedString = toBase64(<Uint8Array>digestBytes);

let verified: boolean = verifyDocumentMetadata(documentHash, digestBase64, proof);

if (!verified) {
Expand Down Expand Up @@ -119,7 +122,7 @@ export async function verifyDocumentMetadataWithUserData(
//const userProof: ValueHolder = userLedgerMetadata.Proof;
const userDigestBase64: Base64EncodedString = userLedgerMetadata.LedgerDigest.Digest;

const revisionResponse: GetRevisionResponse = await getRevision(
const revisionResponse: GetRevisionCommandOutput = await getRevision(
ledgerName,
userLedgerMetadata.DocumentId,
userLedgerMetadata.BlockAddress,
Expand Down

0 comments on commit 47d1d66

Please sign in to comment.