UnhandledPromiseRejectionWarning: ReferenceError: og is not defined
zhb001 opened this issue · 3 comments
zhb001 commented
I seem to have made a new mistake
(node:13414) UnhandledPromiseRejectionWarning: ReferenceError: og is not defined
zhb001 commented
`/**
- Example demonstrating how to add DID with the role of Trust Anchor as Steward.
- Uses seed to obtain Steward's DID which already exists on the ledger.
- Then it generates new DID/Verkey pair for Trust Anchor.
- Using Steward's DID, NYM transaction request is built to add Trust Anchor's DID and Verkey
- on the ledger with the role of Trust Anchor.
- Once the NYM is successfully written on the ledger, it generates new DID/Verkey pair that represents
- a client, which are used to create GET_NYM request to query the ledger and confirm Trust Anchor's Verkey.
- For the sake of simplicity, a single wallet is used. In the real world scenario, three different wallets
- would be used and DIDs would be exchanged using some channel of communication
*/
const indy = require('indy-sdk')
const util = require('./util')
const colors = require('./colors')
const log = console.log
function logValue() {
log(colors.CYAN, ...arguments, colors.NONE)
}
async function run() {
log("设置协议版本 2 以与 Indy Node 1.4 一起使用")
await indy.setProtocolVersion(2)
console.log("gettingStarted.js -> started");
// 1.
log('1. Creates a new local pool ledger configuration that is used later when connecting to ledger.')
log('1. 创建一个新的本地池分类帐配置,稍后在连接到分类帐时使用')
let poolName = 'poolsd'
console.log(`Open Pool Ledger: ${poolName}`);
let genesisFilePath = await util.getPoolGenesisTxnPath(poolName)
console.log(`Open Pool genesisFilePath: ${genesisFilePath}`);
// const poolConfig = {'genesis_txn': genesisFilePath}
let poolConfig = {
"genesis_txn": genesisFilePath
};
console.log(poolConfig);
try {
await indy.createPoolLedgerConfig(poolName, poolConfig);
} catch(e) {
if(e.message !== "PoolLedgerConfigAlreadyExistsError") {
throw e;
}
}
// 2.
log('2. Open pool ledger and get handle from libindy')
log('2. 打开池分类账并从libindy获取处理')
// log(poolName)
const poolHandle = await indy.openPoolLedger(poolName, undefined)
log('+++++++++++++++++++++++++++')
console.log("poolHandle: :", poolHandle)
log('+++++++++++++++++++++++++++')
// 3.
log('3. Creating new secure wallet')
log('3. 创建新的安全钱包')
const walletName = {"id": "wallet2"}
const walletCredentials = {"key": "wallet_key2"}
await indy.deleteWallet(walletName, walletCredentials)
await indy.createWallet(walletName, walletCredentials)
// 4.
log('4. Open wallet and get handle from libindy')
log('4. 打开钱包,从libindy那里得到处理')
const walletHandle = await indy.openWallet(walletName, walletCredentials)
// 5.
log('5. Generating and storing steward DID and verkey')
log('5. 生成并存储管家DID和verkey')
const stewardSeed = '000000000000000000000000Steward2'
const did = {'seed': stewardSeed}
const [stewardDid, stewardVerkey] = await indy.createAndStoreMyDid(walletHandle, did)
logValue('Steward DID: ', stewardDid)
logValue('Steward Verkey: ', stewardVerkey)
// 6.
log('6. Generating and storing trust anchor DID and verkey')
log('6. 生成和存储信任锚DID和verkey')
const [trustAnchorDid, trustAnchorVerkey] = await indy.createAndStoreMyDid(walletHandle, "{}")
logValue('Trust anchor DID: ', trustAnchorDid)
logValue('Trust anchor Verkey: ', trustAnchorVerkey)
// 7.
log('7. Building NYM request to add Trust Anchor to the ledger')
log('7. 正在构建NYM请求,将Trust Anchor添加到分类账中')
const nymRequest = await indy.buildNymRequest(/*submitter_did*/ stewardDid,
/*target_did*/ trustAnchorDid,
/*ver_key*/ trustAnchorVerkey,
/*alias*/ undefined,
/*role*/ 'TRUST_ANCHOR')
// 8.
log('8. Sending NYM request to the ledger')
log('8. 向账本发送NYM请求')
await indy.signAndSubmitRequest(/*pool_handle*/ poolHandle,
/*wallet_handle*/ walletHandle,
/*submitter_did*/ stewardDid,
/*request_json*/ nymRequest)
// 9.
log('9. Generating and storing DID and verkey representing a Client that wants to obtain Trust Anchor Verkey')
log('9. 生成并存储DID和verkey,表示希望获得信任锚verkey的客户端')
const [clientDid, clientVerkey] = await indy.createAndStoreMyDid(walletHandle, "{}")
logValue('Client DID: ', clientDid)
logValue('Client Verkey: ', clientVerkey)
// 10.
log('10. Building the GET_NYM request to query trust anchor verkey')
og('10. 构建GET_NUM请求以查询信任锚verkey')
const getNymRequest = await indy.buildGetNymRequest(/*submitter_did*/ clientDid,
/*target_did*/ trustAnchorDid)
// 11.
log('11. Sending the Get NYM request to the ledger')
log('11. 向账本发送Get NYM请求')
const getNymResponse = await indy.submitRequest(/*pool_handle*/ poolHandle,
/*request_json*/ getNymRequest)
// 12.
log('12. Comparing Trust Anchor verkey as written by Steward and as retrieved in GET_NYM response submitted by Client')
log('12. 比较Steward编写的和客户提交的GET_NOM响应中检索的Trust Anchor verkey')
logValue('Written by Steward: ', trustAnchorVerkey)
const verkeyFromLedger = JSON.parse(getNymResponse['result']['data'])['verkey']
logValue('Queried from ledger: ', verkeyFromLedger)
logValue('Matching: ', verkeyFromLedger == trustAnchorVerkey)
// 13.
log('13. Closing wallet and pool')
log('13. 关闭钱包和池')
await indy.closeWallet(walletHandle)
await indy.closePoolLedger(poolHandle)
// 14.
log('14. Deleting created wallet')
log('14. 正在删除创建的钱包')
await indy.deleteWallet(walletName, walletCredentials)
// 15.
log('15. Deleting pool ledger config')
log('15. 正在删除池分类帐配置')
// await indy.deletePoolLedgerConfig(poolName)
}
try {
run()
} catch (e) {
log("ERROR occured : e")
}`
zhb001 commented
Failed at this step
// 10. log('10. Building the GET_NYM request to query trust anchor verkey') Og ('10. Build GET_NUM request to query trust anchor verkey ') const getNymRequest = await indy.buildGetNymRequest(/*submitter_did*/ clientDid, /*target_ did*/ trustAnchorDid)
zhb001 commented
Ha ha ha, I am so stupid to make such a mistake