node.jshyperledger-fabrichsm

The constructor for HSMWalletMixin in HLF 1.4 doesn't have the correct variables


I'm trying to connect to an HSM using fabric-network V1.4.17 looking at the HSMWalletMixin constructor there are no options to tell the class the library label and pin.

Instead all these variables can be found in the X509WalletMixin.

Here's the code in the class:

export interface WalletMixin {} // tslint:disable-line:no-empty-interface

export class X509WalletMixin implements WalletMixin {
    public static createIdentity(mspId: string, certificate: string, privateKey: string): Identity;
    constructor(library?: string, slot?: string, pin?: string, userType?: string);
}

export class HSMWalletMixin implements WalletMixin {
    public static createIdentity(mspId: string, certificate: string): Identity;
    constructor();
}

So I tried creating an HSM Wallet using the X509WalletMixin like below, but it created a regular wallet instead.

const hsmWalletMixin = new X509WalletMixin('/path/to/lib/libCryptoki2_64.so', 'slot', 'pin');
const wallet = new FileSystemWallet(walletPath, hsmWalletMixin);

So, How can create an HSM Wallet then? are there some environment variables like in this tutorial Testing for Hardware Security Module via PKCS#11?

Thanks


Solution

  • Looking at the source code the implementation is correct https://github.com/hyperledger/fabric-sdk-node/blob/4ca22aa1a70f464c3a5b9c259542aa7fee651061/fabric-network/lib/impl/wallet/hsmwalletmixin.js#L40

    What is not correct are the type definitions which is the code snippet you have posted.

    It's only going to be an issue if you are using typescript in which case you will just have to not use the HSMWalletMixin type to ensure typescript doesn't try to do any validation.