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

The execution never continue after calling agent.handleMessage #281

Closed
Muhammad-Altabba opened this issue Nov 25, 2020 · 5 comments
Closed
Assignees
Labels
bug Something isn't working wontfix This will not be worked on

Comments

@Muhammad-Altabba
Copy link

Muhammad-Altabba commented Nov 25, 2020

Bug severity
5

Describe the bug
Not being able to get the processed message after calling agent.handleMessage (the execution never continue). We started to have this after migrating from Daf 5 to Daf 6. (Early data was all erased by deleting the Mobile App and clearing the cache)

      const verified = await verifyJWT(message.raw, { resolver: agent.didResolver, audience })

To Reproduce
Steps to reproduce the behavior:

        const vcJwt: Daf.Credential = await agent.handleAction({
            type: W3cActionTypes.signCredentialJwt,
            save: true,
            data: {
                "@context": ["https://www.w3.org/2018/credentials/v1"],
                type: ["VerifiableCredential"],
                issuer: this.userIdentity?.did,
                credentialSubject: credentialSubject,
            },
        } as ActionSignW3cVc);

        // vcJwt.raw is something like: 
        //eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NkstUiJ9.eyJpYXQiOjE2MDYzMDU5MDksInZjIjp7IkBjb250ZXh0IjpbImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL3YxIl0sInR5cGUiOlsiVmVyaWZpYWJsZUNyZWRlbnRpYWwiXSwiY3JlZGVudGlhbFN1YmplY3QiOnsic3RyZWV0X2FkZHJlc3MiOiI0NTd0enVpbmJ1dmd0In19LCJzdWIiOiJkaWQ6ZXRocjpnb2VybGk6MHg0MmU5MGY3NTA3MTIxZGU2MGNlODU2NTJhODMzZTg5MzI4MjhjYmU1IiwiaXNzIjoiZGlkOmV0aHI6Z29lcmxpOjB4NDJlOTBmNzUwNzEyMWRlNjBjZTg1NjUyYTgzM2U4OTMyODI4Y2JlNSJ9.WWDJdJKgDPwuIyKxlfaq7-a87HgZIEPmIyt-kbL8U1OD6BmVjvaFbA1HLcq_nJMF9CdQ-C6lfnL4vZN0CedtCgA

        const claimMessage: Daf.Message = await agent.handleMessage({
            raw: vcJwt.raw,
            save: true,
        });

        //The previous await never end and never continue the execution to the next line.

Note: Trying to tace the bug origin. The method that produces the issue is await verifyJWT that is called inside JwtMessageHandler -> handle. And when adding console.log(e) The following was logged:

[Error: Error decoding changed(address):(uint256) with 0x0000000000000000000000000000000000000000000000000000000000000000 : Can't find variable: BigInt]

Setup Configuration

// 1- Setting up the database connection
// https://typeorm.io/#/connection-options
import { createConnection, getConnection, Connection, ConnectionOptions as TypeOrmConnectionOptions } from 'typeorm'
import { Agent, IdentityStore, KeyStore, Entities as DafEntities, Resolver as DidResolver } from 'daf-core'
import { ServiceControllerDerived } from 'daf-core/build/service/abstract-service-controller'
import * as EthrDid from 'daf-ethr-did'
import { UrlMessageHandler } from 'daf-url'
import { DIDCommMessageHandler, DIDCommActionHandler } from 'daf-did-comm'
import { JwtMessageHandler } from 'daf-did-jwt'
import { W3cMessageHandler, W3cActionHandler } from 'daf-w3c'
import { SdrMessageHandler, SdrActionHandler } from 'daf-selective-disclosure'
import In3Client from "in3-asmjs";
import { importKey, IncubedDafResolver } from './helper';

const network = "goerli";
let in3;
if (process.env.NODE_ENV === "test") in3 = new In3Client({ rpc: `https://rpc.slock.it/${network}` });
else in3 = new In3Client({ chainId: network });

let isNode = false;
if (typeof document != 'undefined') {
  // I'm on the web!
}
else if (typeof navigator != 'undefined' && navigator.product == 'ReactNative') {
  // I'm in react-native
  // temp workaround for `in3-asmjs`: `in3-asmjs` currently sets the storage cache as if we are in the browser
  // https://git.slock.it/in3/c/in3-core/-/issues/667
  const in3_cache={};
  In3Client.setStorage({
          get: key => in3_cache[key],
          set: (key, value) => in3_cache[key]=value
  });
}
else {
  // I'm in node js
  isNode = true;
}

let KeyManagementSystem, SecretBox;
if (isNode) {  // For NodeJS (the test-cases run within Node)
  // Note: having the following block without 'eval' will cause the react native app to crash!
  //  Unclear why, even when the 'if' condition is false, react-native crash if there is no 'eval'!
  eval('const libsodium = require("daf-libsodium");\
    KeyManagementSystem = libsodium.KeyManagementSystem;\
    SecretBox = libsodium.SecretBox;');
}
else { // For react-native
  const libsodium = require("daf-react-native-libsodium");
  KeyManagementSystem = libsodium.KeyManagementSystem;

  // ToDo: Temp patch  https://git.slock.it/identity/identity-lib/-/issues/137
  KeyManagementSystem.prototype.importKey = importKey

  SecretBox = libsodium.SecretBox;
}

import { IdentityContext } from './IdentityContext';

let dbConfig: TypeOrmConnectionOptions;

if (isNode) {
  const { v4: uuidv4 } = require('uuid');
  dbConfig = {
    type: 'sqlite',
    database: `./database-${uuidv4()}.sqlite`,
    synchronize: true,
    logging: false,
    entities: [...DafEntities],
  }
} else
  dbConfig = {
      type: "react-native",
      database: "daf.sqlite",
      location: "default",
      synchronize: true,
      logging: ["error"],
      entities: [...DafEntities],
  };

// Using local DID Document resolver. It is being used internally to validate messages and to get information about service endpoints
let didResolver: DidResolver = new IncubedDafResolver({ web3Provider: in3 })

const getOrCreateDbConnection = async (): Promise<Connection> => {
  try {
    return getConnection()
  } catch (e) {
    return createConnection(dbConfig)
  }
}

const dbConnection = getOrCreateDbConnection()

// 2 - We will be using 'did:ethr' identities
// 3 - Storing key pairs in the database
// 4 - KeyManagementSystem is responsible for managing encryption and signing keys
// 5 - Storing managed identities in the database
export const identityStore = new IdentityStore(network, dbConnection)

const keyStore = new KeyStore(dbConnection)
const kms = new KeyManagementSystem(keyStore)

const identityProviders = [
  new EthrDid.IdentityProvider({
    identityStore: new IdentityStore(`${network}-ethr`, dbConnection),
    kms,               //: new KeyManagementSystem(new KeyStore(dbConnection, new DafLocalStorage.KeyStore('localKeys'))),
    network,
    web3Provider: in3,
  }),
]

const serviceControllers: ServiceControllerDerived[] = []

// Setting up Message Handler Chain
const messageHandler = new UrlMessageHandler()
messageHandler
  .setNext(new DIDCommMessageHandler())
  .setNext(new JwtMessageHandler())
  .setNext(new W3cMessageHandler())
  .setNext(new SdrMessageHandler())

// Setting up Action Handler Chain
const actionHandler = new W3cActionHandler()
actionHandler
  .setNext(new SdrActionHandler())
  .setNext(new DIDCommActionHandler())

// Initializing the agent
export const agent = new Agent({
  dbConnection,
  didResolver,
  serviceControllers,
  identityProviders,
  actionHandler,
  messageHandler,
})

export const initializeContext = async () => {
  console.log('1 - Inside initializeDB function ')
  IdentityContext.Initialize();
}

Versions:

  • Daf: 6.4.1
  • React Native: 0.63.3, React: 16.13.1
  • Node Version: v10.19.0
@Muhammad-Altabba Muhammad-Altabba added the bug Something isn't working label Nov 25, 2020
@Muhammad-Altabba
Copy link
Author

More on this issue...

When trying to process this SDR:
eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NkstUiJ9.eyJpYXQiOjE2MDYzOTAyMjMsInR5cGUiOiJzZHIiLCJ0YWciOiJzZHJfb0xxdFBsV2F5Y1RHVU9tV3RSNjJLa0ZkRFJ6MW9ZQ1EiLCJjbGFpbXMiOlt7Imlzc3VlcnMiOlt7ImRpZCI6ImRpZDpldGhyOmdvZXJsaToweGVmMGMyYTBkYWRmNDljMjgzNjZjM2EwYzFkNmYwZTk4MDg5YTA3NjciLCJ1cmwiOiJodHRwOi8vc3AtaWQuZGVtby5pYW1vLmRldiJ9XSwicmVhc29uIjoiV2UgbmVlZCB5b3VyIG5hbWUuIiwiZXNzZW50aWFsIjp0cnVlLCJjbGFpbVR5cGUiOiJuYW1lIn0seyJpc3N1ZXJzIjpbeyJkaWQiOiJkaWQ6ZXRocjpnb2VybGk6MHhlZjBjMmEwZGFkZjQ5YzI4MzY2YzNhMGMxZDZmMGU5ODA4OWEwNzY3IiwidXJsIjoiaHR0cDovL3NwLWlkLmRlbW8uaWFtby5kZXYifV0sInJlYXNvbiI6IldlIG5lZWQgeW91ciBkYXRlT2ZCaXJ0aC4iLCJlc3NlbnRpYWwiOnRydWUsImNsYWltVHlwZSI6ImRhdGVPZkJpcnRoIn0seyJpc3N1ZXJzIjpbeyJkaWQiOiJkaWQ6ZXRocjpnb2VybGk6MHhlZjBjMmEwZGFkZjQ5YzI4MzY2YzNhMGMxZDZmMGU5ODA4OWEwNzY3IiwidXJsIjoiaHR0cDovL3NwLWlkLmRlbW8uaWFtby5kZXYifV0sInJlYXNvbiI6IldlIG5lZWQgeW91ciBjb3VudHJ5LiIsImVzc2VudGlhbCI6dHJ1ZSwiY2xhaW1UeXBlIjoiY291bnRyeSJ9XSwiaXNzIjoiZGlkOmV0aHI6Z29lcmxpOjB4YmM1NTc4N2IyYWIwZDEyYjkxMmM1MzA1YTEyYTA1ZWVlMGM4MTZiYSJ9.NQMfw7rRhpDo1FA22_cvElvCSm4PyVF5LXhLpxHTb00p5KUd5O2DlHjLj7zvMr7_JnjSgJ6x6eZD7St-nvl7SwA

I got this error:

[Error: Error decoding changed(address):(uint256) with 0x00000000000000000000000000000000000000000000000000000000003897f5 : Can't find variable: BigInt]

An important point to mention: when I attach to a debugger, the error does not show and the process goes smoothly for both reading and SDR and creating claims in addition to sending the SDR approval to the issuer endpoint.

@mirceanis
Copy link
Member

Thank you for the clarification.
We will try to reproduce but in your case it may be linked to the react-native environment you're running in.

Can you see if the solution from this bug changes something for you?
facebook/react-native#28492 (comment)

From the perspective of DAF it is still a bug that the error is swallowed and the handleMessage promise is never rejected.
Can you please add some more context to the error message? do you have a stack trace that you can share?

@Muhammad-Altabba
Copy link
Author

Thanks Mircea,

I added @babel/plugin-syntax-bigint as suggested here facebook/react-native#28492 but it did not solve the problem.

Regarding the stack trace, console.trace(); printed nothing. And console.log('stack', e.stack); printed the following:

abiDecode@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:488802:24
http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:489561:42
http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:99555:29
P@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:99559:18
O@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:99532:48
p@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:99410:26
_callTimer@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:30687:17
callTimers@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:30895:19
__callFunction@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:3445:36
http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:3177:31
__guard@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:3399:15
callFunctionReturnFlushedQueue@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:3176:21
callFunctionReturnFlushedQueue@[native code]

And I could not find that DAF has tests for DAF React Native packages. Both https://github.com/uport-project/daf/tree/master/packages/daf-react-native-libsodium and https://github.com/uport-project/daf/tree/master/packages/daf-react-native-async-storage do not seem to have tests. However, in our case we are only using daf-react-native-libsodium:

@mirceanis
Copy link
Member

@Muhammad-Altabba is this still an issue in the latest veramo?

@stale
Copy link

stale bot commented Apr 18, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix This will not be worked on label Apr 18, 2021
@stale stale bot closed this as completed Jun 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

3 participants