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

Ok, I have figured out what was wrong: I was trying to keep compatibility with the "old" JSON "wallet" format. #1139

Open
Michaelalmada opened this issue Nov 22, 2023 · 0 comments

Comments

@Michaelalmada
Copy link

          Ok, I have figured out what was wrong: I was trying to keep compatibility with the "old" JSON "wallet" format. 

Passing the credentials as a Buffer instead of a string into the identity property to the gateway's connect function solves the problem.

Here is the code snippet for those who want to keep the compatibility back with the "User.id" JSON wallet file format (assuming 2 env vars: one to configure the wallet path and another the identity name to be used to transact, plus using more or less the same code structure used into asset-transfer-basic/application-gateway-typescript sample):

const walletPath = process.env.WALLET_PATH || '/opt/node/wallet';
const identity = process.env.IDENTITY || 'Admin';

const walletFile = fs.readFileSync(`${walletPath}/${identity}.id`, 'utf8');
const wallet = JSON.parse(walletFile);

const newIdentity: any = async () => {
    const mspId = wallet.mspId;
    const credentials = Buffer.from(wallet.credentials.certificate); // here is the "gotcha"
    
    return { mspId, credentials };
}

const newSigner: any = async () => {
    const privateKey = crypto.createPrivateKey(wallet.credentials.privateKey);

    return signers.newPrivateKeySigner(privateKey);
}

Originally posted by @jeffbicca in hyperledger/fabric#4358 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant