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

Issue adding/resolving DID Docs #22

Open
HLK65 opened this issue Jun 17, 2020 · 9 comments
Open

Issue adding/resolving DID Docs #22

HLK65 opened this issue Jun 17, 2020 · 9 comments

Comments

@HLK65
Copy link

HLK65 commented Jun 17, 2020

Hey,

I'm trying to create and add a DID Doc but it seems like it's not being added to the network. Maybe you can help me find the issue.

I got a node.js express server setup with the following code to create a did

var did = require('did-ipid');
...
ipid = did.default(ipfsNode, {lifetime: '24h'}); //IPFS.create({repo: "ipfs-server", pass: "}{.&PWPWPWPWPWPWPW000000"})
...
router.get('/register', function (req, res) { 
    let rsaKeyPair = generateRsaKeyPair(); //generates rsa keys with crypto 
    ipid.create(rsaKeyPair.privateKey, (document) => {
        const publicKey = document.addPublicKey({
            type: 'RsaVerificationKey2018',
            publicKeyHex: rsaKeyPair.publicKey
        }); 

        const authentication = document.addAuthentication(publicKey.id);

        const service = document.addService({
            id: 'hub',
            type: 'HubService',
            serviceEndpoint: 'https://hub.example.com/',
        });
    })
        .then(didDocument => res.send(didDocument))
        .catch(reason => res.status(500).send(reason));
});

This creates and responds the didDoc but when trying to resolve it I don't get anything.

router.get('/resolve', function (req, res) {
    let did = req.query["did"]
    if (did !== undefined && did.length > 0) {
        ipid.resolve(did)
            .then(r => res.send(r))
            .catch(reason => res.status(404).send(reason));
    } else {
        res.status(400).send("Missing did");
    }
});

Register response: {

    "publicKey": [
        {
            "type": "RsaVerificationKey2018",
            "publicKeyHex": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAp2wSSx0XuixPRjE9bVjj\nBotpLmgQ4j6QTXjkgEO8db8woXTLXKyv7k0Qlg3/o+/BaCFoqq7eCgYPzuLQtsV4\nmKmUWGs8i783wtx9ChdsvNUJtQDYLvY60tdEredCxzr4+IocQEeAp6oqHiuuQ3mX\nAtEh1909vsootLcNinK74ysOiTKhNeUWGYCKIMtMqUSqSIGP617os+IJVcGbZ1fk\nf9ofrVcQMTW+9LAohs1KYuFuNACRUP2EoQTkM890Mv0hp0kTKfexsKd7bjxfazo0\nDebrtYCwnFJyHaA+AB6+n1eskCGIgmM6KECLKZoLq1CPXn+AHDWc5MHJNKNN2kqt\nuQIDAQAB\n-----END PUBLIC KEY-----\n",
            "id": "did:ipid:QmWDmXuHmm2RDhFDrVpL7487MB26NpVMWvS8jv59pARMMb#5y3dyogt2to",
            "controller": "did:ipid:QmWDmXuHmm2RDhFDrVpL7487MB26NpVMWvS8jv59pARMMb"
        }
    ],
    "authentication": [
        "did:ipid:QmWDmXuHmm2RDhFDrVpL7487MB26NpVMWvS8jv59pARMMb#5y3dyogt2to"
    ],
    "service": [
        {
            "id": "did:ipid:QmWDmXuHmm2RDhFDrVpL7487MB26NpVMWvS8jv59pARMMb;hub",
            "type": "HubService",
            "serviceEndpoint": "https://hub.example.com/"
        }
    ],
    "@context": "https://w3id.org/did/v1",
    "id": "did:ipid:QmWDmXuHmm2RDhFDrVpL7487MB26NpVMWvS8jv59pARMMb",
    "created": "2020-06-17T12:19:38.247Z",
    "updated": "2020-06-17T12:19:38.247Z"
}

Response to localhost:3000/did/resolve?did=did:ipid:QmWDmXuHmm2RDhFDrVpL7487MB26NpVMWvS8jv59pARMMb
Code 404

{
    "originalError": "Cannot read property 'replace' of undefined",
    "code": "INVALID_DID",
    "name": "InvalidDid"
}

It's the replace on path in line 97 of the ipid index.js

const {
        path
      } = await _classPrivateFieldGet(this, _ipfs).name.resolve(identifier);
      const cidStr = path.replace(/^\/ipfs\//, '');

So it looks like it can't resolve the identifier

Manually resolving the did ipfs.name.resolve returns /ipfs/bafyreihnyf7hwzeo7gzfpxdys5kyz6v3o7pvh7dd3riird3krpfqyxx2lm but ipfs.cat returns Error: this dag node has no content. and the cloudflare gateway unknown node type

So I guess I'm doing something wrong but I can't figure it out. Maybe you can help.

Thanks,
Lukas

@HLK65
Copy link
Author

HLK65 commented Jun 17, 2020

Full file for a better understanding https://pastebin.com/tjyDTCBf

@autonome
Copy link

@patrickdet
Copy link

I am running into the exact same issue that @HLK65 is describing. The part of await _classPrivateFieldGet(this, _ipfs).name.resolve(identifier); returns undefined in all cases I have tried.

@patrickdet
Copy link

So from the ipfs-js docs (https://github.com/ipfs/js-ipfs/blob/master/docs/core-api/NAME.md#ipfsnameresolvevalue-options) it looks like the publish identifier needs to look like /ipns/....

The publish function of the js-did-ipid library calls ipfs.name.publish with a path that starts with /ipfs/...

js-did-ipid/src/index.js

Lines 68 to 70 in a32bec2

const path = `/ipfs/${cid.toBaseEncodedString()}`;
await this.#ipfs.name.publish(path, {

I might be wrong.

@patrickdet
Copy link

I have dug into this some more and it appears to me that the problem happens due to the switch to Async Iterables https://gist.github.com/alanshaw/04b2ddc35a6fff25c040c011ac6acf26#file-migration-md

I will have a look whether I can send a PR with the fix

@autonome
Copy link

Ahhhh. Thanks for investigating @patrickdet!

@satazor can you review or suggest a reviewer?

@HLK65
Copy link
Author

HLK65 commented Jun 20, 2020

Thank you for digging in and fixing @patrickdet !
I'll hopefully find the time to test it tomorrow.

@HLK65
Copy link
Author

HLK65 commented Jun 23, 2020

It's working, thank you so much!

@satazor
Copy link
Contributor

satazor commented Jun 24, 2020

Reviewed!

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

Successfully merging a pull request may close this issue.

4 participants