diff --git a/fabcar/javascript/enrollAdmin.js b/fabcar/javascript/enrollAdmin.js index 695d9ea57e..ce83f45c66 100644 --- a/fabcar/javascript/enrollAdmin.js +++ b/fabcar/javascript/enrollAdmin.js @@ -5,7 +5,7 @@ 'use strict'; const FabricCAServices = require('fabric-ca-client'); -const { FileSystemWallet, X509WalletMixin } = require('fabric-network'); +const { Wallets } = require('fabric-network'); const fs = require('fs'); const path = require('path'); @@ -23,20 +23,27 @@ async function main() { // Create a new file system based wallet for managing identities. const walletPath = path.join(process.cwd(), 'wallet'); - const wallet = new FileSystemWallet(walletPath); + const wallet = await Wallets.newFileSystemWallet(walletPath); console.log(`Wallet path: ${walletPath}`); // Check to see if we've already enrolled the admin user. - const adminExists = await wallet.exists('admin'); - if (adminExists) { + const identity = await wallet.get('admin'); + if (identity) { console.log('An identity for the admin user "admin" already exists in the wallet'); return; } // Enroll the admin user, and import the new identity into the wallet. const enrollment = await ca.enroll({ enrollmentID: 'admin', enrollmentSecret: 'adminpw' }); - const identity = X509WalletMixin.createIdentity('Org1MSP', enrollment.certificate, enrollment.key.toBytes()); - await wallet.import('admin', identity); + const x509Identity = { + credentials: { + certificate: enrollment.certificate, + privateKey: enrollment.key.toBytes(), + }, + mspId: 'Org1MSP', + type: 'X.509', + }; + await wallet.put('admin', x509Identity); console.log('Successfully enrolled admin user "admin" and imported it into the wallet'); } catch (error) { diff --git a/fabcar/javascript/invoke.js b/fabcar/javascript/invoke.js index 013188bbe3..02952e51e3 100644 --- a/fabcar/javascript/invoke.js +++ b/fabcar/javascript/invoke.js @@ -4,7 +4,7 @@ 'use strict'; -const { FileSystemWallet, Gateway } = require('fabric-network'); +const { Gateway, Wallets } = require('fabric-network'); const path = require('path'); const ccpPath = path.resolve(__dirname, '..', '..', 'first-network', 'connection-org1.json'); @@ -14,12 +14,12 @@ async function main() { // Create a new file system based wallet for managing identities. const walletPath = path.join(process.cwd(), 'wallet'); - const wallet = new FileSystemWallet(walletPath); + const wallet = await Wallets.newFileSystemWallet(walletPath); console.log(`Wallet path: ${walletPath}`); // Check to see if we've already enrolled the user. - const userExists = await wallet.exists('user1'); - if (!userExists) { + const identity = await wallet.get('user1'); + if (!identity) { console.log('An identity for the user "user1" does not exist in the wallet'); console.log('Run the registerUser.js application before retrying'); return; diff --git a/fabcar/javascript/query.js b/fabcar/javascript/query.js index 40af411fd3..63d33fc67b 100644 --- a/fabcar/javascript/query.js +++ b/fabcar/javascript/query.js @@ -4,7 +4,7 @@ 'use strict'; -const { FileSystemWallet, Gateway } = require('fabric-network'); +const { Gateway, Wallets } = require('fabric-network'); const path = require('path'); const ccpPath = path.resolve(__dirname, '..', '..', 'first-network', 'connection-org1.json'); @@ -14,12 +14,12 @@ async function main() { // Create a new file system based wallet for managing identities. const walletPath = path.join(process.cwd(), 'wallet'); - const wallet = new FileSystemWallet(walletPath); + const wallet = await Wallets.newFileSystemWallet(walletPath); console.log(`Wallet path: ${walletPath}`); // Check to see if we've already enrolled the user. - const userExists = await wallet.exists('user1'); - if (!userExists) { + const identity = await wallet.get('user1'); + if (!identity) { console.log('An identity for the user "user1" does not exist in the wallet'); console.log('Run the registerUser.js application before retrying'); return; diff --git a/fabcar/javascript/registerUser.js b/fabcar/javascript/registerUser.js index cb786a25d7..20e0da92e4 100644 --- a/fabcar/javascript/registerUser.js +++ b/fabcar/javascript/registerUser.js @@ -4,7 +4,7 @@ 'use strict'; -const { FileSystemWallet, Gateway, X509WalletMixin } = require('fabric-network'); +const { Gateway, Wallets } = require('fabric-network'); const path = require('path'); const ccpPath = path.resolve(__dirname, '..', '..', 'first-network', 'connection-org1.json'); @@ -14,19 +14,19 @@ async function main() { // Create a new file system based wallet for managing identities. const walletPath = path.join(process.cwd(), 'wallet'); - const wallet = new FileSystemWallet(walletPath); + const wallet = await Wallets.newFileSystemWallet(walletPath); console.log(`Wallet path: ${walletPath}`); // Check to see if we've already enrolled the user. - const userExists = await wallet.exists('user1'); - if (userExists) { + const userIdentity = await wallet.get('user1'); + if (userIdentity) { console.log('An identity for the user "user1" already exists in the wallet'); return; } // Check to see if we've already enrolled the admin user. - const adminExists = await wallet.exists('admin'); - if (!adminExists) { + const adminIdentity = await wallet.get('admin'); + if (!adminIdentity) { console.log('An identity for the admin user "admin" does not exist in the wallet'); console.log('Run the enrollAdmin.js application before retrying'); return; @@ -37,14 +37,22 @@ async function main() { await gateway.connect(ccpPath, { wallet, identity: 'admin', discovery: { enabled: true, asLocalhost: true } }); // Get the CA client object from the gateway for interacting with the CA. - const ca = gateway.getClient().getCertificateAuthority(); - const adminIdentity = gateway.getCurrentIdentity(); + const client = gateway.getClient(); + const ca = client.getCertificateAuthority(); + const adminUser = await client.getUserContext('admin', false); // Register the user, enroll the user, and import the new identity into the wallet. - const secret = await ca.register({ affiliation: 'org1.department1', enrollmentID: 'user1', role: 'client' }, adminIdentity); + const secret = await ca.register({ affiliation: 'org1.department1', enrollmentID: 'user1', role: 'client' }, adminUser); const enrollment = await ca.enroll({ enrollmentID: 'user1', enrollmentSecret: secret }); - const userIdentity = X509WalletMixin.createIdentity('Org1MSP', enrollment.certificate, enrollment.key.toBytes()); - await wallet.import('user1', userIdentity); + const x509Identity = { + credentials: { + certificate: enrollment.certificate, + privateKey: enrollment.key.toBytes(), + }, + mspId: 'Org1MSP', + type: 'X.509', + }; + await wallet.put('user1', x509Identity); console.log('Successfully registered and enrolled admin user "user1" and imported it into the wallet'); } catch (error) { diff --git a/fabcar/typescript/src/enrollAdmin.ts b/fabcar/typescript/src/enrollAdmin.ts index 7325ee2ddd..39778d6dec 100644 --- a/fabcar/typescript/src/enrollAdmin.ts +++ b/fabcar/typescript/src/enrollAdmin.ts @@ -3,7 +3,7 @@ */ import * as FabricCAServices from 'fabric-ca-client'; -import { FileSystemWallet, X509WalletMixin } from 'fabric-network'; +import { Wallets, X509Identity } from 'fabric-network'; import * as fs from 'fs'; import * as path from 'path'; @@ -21,20 +21,27 @@ async function main() { // Create a new file system based wallet for managing identities. const walletPath = path.join(process.cwd(), 'wallet'); - const wallet = new FileSystemWallet(walletPath); + const wallet = await Wallets.newFileSystemWallet(walletPath); console.log(`Wallet path: ${walletPath}`); // Check to see if we've already enrolled the admin user. - const adminExists = await wallet.exists('admin'); - if (adminExists) { + const identity = await wallet.get('admin'); + if (identity) { console.log('An identity for the admin user "admin" already exists in the wallet'); return; } // Enroll the admin user, and import the new identity into the wallet. const enrollment = await ca.enroll({ enrollmentID: 'admin', enrollmentSecret: 'adminpw' }); - const identity = X509WalletMixin.createIdentity('Org1MSP', enrollment.certificate, enrollment.key.toBytes()); - await wallet.import('admin', identity); + const x509Identity: X509Identity = { + credentials: { + certificate: enrollment.certificate, + privateKey: enrollment.key.toBytes(), + }, + mspId: 'Org1MSP', + type: 'X.509', + }; + await wallet.put('admin', x509Identity); console.log('Successfully enrolled admin user "admin" and imported it into the wallet'); } catch (error) { diff --git a/fabcar/typescript/src/invoke.ts b/fabcar/typescript/src/invoke.ts index 017d8ee116..f05d67c75d 100644 --- a/fabcar/typescript/src/invoke.ts +++ b/fabcar/typescript/src/invoke.ts @@ -2,7 +2,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { FileSystemWallet, Gateway } from 'fabric-network'; +import { Gateway, Wallets } from 'fabric-network'; import * as path from 'path'; const ccpPath = path.resolve(__dirname, '..', '..', '..', 'first-network', 'connection-org1.json'); @@ -12,12 +12,12 @@ async function main() { // Create a new file system based wallet for managing identities. const walletPath = path.join(process.cwd(), 'wallet'); - const wallet = new FileSystemWallet(walletPath); + const wallet = await Wallets.newFileSystemWallet(walletPath); console.log(`Wallet path: ${walletPath}`); // Check to see if we've already enrolled the user. - const userExists = await wallet.exists('user1'); - if (!userExists) { + const identity = await wallet.get('user1'); + if (!identity) { console.log('An identity for the user "user1" does not exist in the wallet'); console.log('Run the registerUser.ts application before retrying'); return; diff --git a/fabcar/typescript/src/query.ts b/fabcar/typescript/src/query.ts index 704433ffee..aac7cf1b5e 100644 --- a/fabcar/typescript/src/query.ts +++ b/fabcar/typescript/src/query.ts @@ -2,7 +2,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { FileSystemWallet, Gateway } from 'fabric-network'; +import { Gateway, Wallets } from 'fabric-network'; import * as path from 'path'; const ccpPath = path.resolve(__dirname, '..', '..', '..', 'first-network', 'connection-org1.json'); @@ -12,12 +12,12 @@ async function main() { // Create a new file system based wallet for managing identities. const walletPath = path.join(process.cwd(), 'wallet'); - const wallet = new FileSystemWallet(walletPath); + const wallet = await Wallets.newFileSystemWallet(walletPath); console.log(`Wallet path: ${walletPath}`); // Check to see if we've already enrolled the user. - const userExists = await wallet.exists('user1'); - if (!userExists) { + const identity = await wallet.get('user1'); + if (!identity) { console.log('An identity for the user "user1" does not exist in the wallet'); console.log('Run the registerUser.ts application before retrying'); return; diff --git a/fabcar/typescript/src/registerUser.ts b/fabcar/typescript/src/registerUser.ts index 4e9407e497..82a0d9d115 100644 --- a/fabcar/typescript/src/registerUser.ts +++ b/fabcar/typescript/src/registerUser.ts @@ -2,7 +2,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { FileSystemWallet, Gateway, X509WalletMixin } from 'fabric-network'; +import { Gateway, Wallets, X509Identity } from 'fabric-network'; import * as path from 'path'; const ccpPath = path.resolve(__dirname, '..', '..', '..', 'first-network', 'connection-org1.json'); @@ -12,19 +12,19 @@ async function main() { // Create a new file system based wallet for managing identities. const walletPath = path.join(process.cwd(), 'wallet'); - const wallet = new FileSystemWallet(walletPath); + const wallet = await Wallets.newFileSystemWallet(walletPath); console.log(`Wallet path: ${walletPath}`); // Check to see if we've already enrolled the user. - const userExists = await wallet.exists('user1'); - if (userExists) { + const userIdentity = await wallet.get('user1'); + if (userIdentity) { console.log('An identity for the user "user1" already exists in the wallet'); return; } // Check to see if we've already enrolled the admin user. - const adminExists = await wallet.exists('admin'); - if (!adminExists) { + const adminIdentity = await wallet.get('admin'); + if (!adminIdentity) { console.log('An identity for the admin user "admin" does not exist in the wallet'); console.log('Run the enrollAdmin.ts application before retrying'); return; @@ -35,14 +35,22 @@ async function main() { await gateway.connect(ccpPath, { wallet, identity: 'admin', discovery: { enabled: true, asLocalhost: true } }); // Get the CA client object from the gateway for interacting with the CA. - const ca = gateway.getClient().getCertificateAuthority(); - const adminIdentity = gateway.getCurrentIdentity(); + const client = gateway.getClient(); + const ca = client.getCertificateAuthority(); + const adminUser = await client.getUserContext('admin', false); // Register the user, enroll the user, and import the new identity into the wallet. - const secret = await ca.register({ affiliation: 'org1.department1', enrollmentID: 'user1', role: 'client' }, adminIdentity); + const secret = await ca.register({ affiliation: 'org1.department1', enrollmentID: 'user1', role: 'client' }, adminUser); const enrollment = await ca.enroll({ enrollmentID: 'user1', enrollmentSecret: secret }); - const userIdentity = X509WalletMixin.createIdentity('Org1MSP', enrollment.certificate, enrollment.key.toBytes()); - await wallet.import('user1', userIdentity); + const x509Identity: X509Identity = { + credentials: { + certificate: enrollment.certificate, + privateKey: enrollment.key.toBytes(), + }, + mspId: 'Org1MSP', + type: 'X.509', + }; + await wallet.put('user1', x509Identity); console.log('Successfully registered and enrolled admin user "user1" and imported it into the wallet'); } catch (error) {