@3id/manager
Version:
3 lines (2 loc) • 27.2 kB
JavaScript
"use strict";function t(t){return t&&"object"==typeof t&&"default"in t?t.default:t}Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@3id/common"),r=t(require("store")),n=require("dids"),i=t(require("@ceramicnetwork/http-client")),a=require("@ceramicstudio/idx"),o=require("@stablelib/sha256"),s=t(require("3id-did-provider")),c=require("uint8arrays"),u=t(require("key-did-resolver")),p=t(require("@ceramicnetwork/3id-did-resolver")),h=require("did-resolver"),f=require("@ethersproject/hdnode"),d=require("caip"),l=t(require("cross-fetch")),v=require("@ceramicnetwork/stream-caip10-link");function x(t,e,r,n,i,a,o){try{var s=t[a](o),c=s.value}catch(t){return void r(t)}s.done?e(c):Promise.resolve(c).then(n,i)}function y(t){return function(){var e=this,r=arguments;return new Promise((function(n,i){var a=t.apply(e,r);function o(t){x(a,n,i,o,s,"next",t)}function s(t){x(a,n,i,o,s,"throw",t)}o(void 0)}))}}function m(){return(m=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t}).apply(this,arguments)}function w(t,e){return t(e={exports:{}},e.exports),e.exports}var g=w((function(t){var e=function(t){var e=Object.prototype,r=e.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},i=n.iterator||"@@iterator",a=n.asyncIterator||"@@asyncIterator",o=n.toStringTag||"@@toStringTag";function s(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{s({},"")}catch(t){s=function(t,e,r){return t[e]=r}}function c(t,e,r,n){var i=Object.create((e&&e.prototype instanceof h?e:h).prototype),a=new I(n||[]);return i._invoke=function(t,e,r){var n="suspendedStart";return function(i,a){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===i)throw a;return{value:void 0,done:!0}}for(r.method=i,r.arg=a;;){var o=r.delegate;if(o){var s=g(o,r);if(s){if(s===p)continue;return s}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var c=u(t,e,r);if("normal"===c.type){if(n=r.done?"completed":"suspendedYield",c.arg===p)continue;return{value:c.arg,done:r.done}}"throw"===c.type&&(n="completed",r.method="throw",r.arg=c.arg)}}}(t,r,a),i}function u(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=c;var p={};function h(){}function f(){}function d(){}var l={};s(l,i,(function(){return this}));var v=Object.getPrototypeOf,x=v&&v(v(D([])));x&&x!==e&&r.call(x,i)&&(l=x);var y=d.prototype=h.prototype=Object.create(l);function m(t){["next","throw","return"].forEach((function(e){s(t,e,(function(t){return this._invoke(e,t)}))}))}function w(t,e){var n;this._invoke=function(i,a){function o(){return new e((function(n,o){!function n(i,a,o,s){var c=u(t[i],t,a);if("throw"!==c.type){var p=c.arg,h=p.value;return h&&"object"==typeof h&&r.call(h,"__await")?e.resolve(h.__await).then((function(t){n("next",t,o,s)}),(function(t){n("throw",t,o,s)})):e.resolve(h).then((function(t){p.value=t,o(p)}),(function(t){return n("throw",t,o,s)}))}s(c.arg)}(i,a,n,o)}))}return n=n?n.then(o,o):o()}}function g(t,e){var r=t.iterator[e.method];if(void 0===r){if(e.delegate=null,"throw"===e.method){if(t.iterator.return&&(e.method="return",e.arg=void 0,g(t,e),"throw"===e.method))return p;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return p}var n=u(r,t.iterator,e.arg);if("throw"===n.type)return e.method="throw",e.arg=n.arg,e.delegate=null,p;var i=n.arg;return i?i.done?(e[t.resultName]=i.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,p):i:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,p)}function b(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function k(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function I(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(b,this),this.reset(!0)}function D(t){if(t){var e=t[i];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,a=function e(){for(;++n<t.length;)if(r.call(t,n))return e.value=t[n],e.done=!1,e;return e.value=void 0,e.done=!0,e};return a.next=a}}return{next:L}}function L(){return{value:void 0,done:!0}}return f.prototype=d,s(y,"constructor",d),s(d,"constructor",f),f.displayName=s(d,o,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===f||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,d):(t.__proto__=d,s(t,o,"GeneratorFunction")),t.prototype=Object.create(y),t},t.awrap=function(t){return{__await:t}},m(w.prototype),s(w.prototype,a,(function(){return this})),t.AsyncIterator=w,t.async=function(e,r,n,i,a){void 0===a&&(a=Promise);var o=new w(c(e,r,n,i),a);return t.isGeneratorFunction(r)?o:o.next().then((function(t){return t.done?t.value:o.next()}))},m(y),s(y,o,"Generator"),s(y,i,(function(){return this})),s(y,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function r(){for(;e.length;){var n=e.pop();if(n in t)return r.value=n,r.done=!1,r}return r.done=!0,r}},t.values=D,I.prototype={constructor:I,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(k),!t)for(var e in this)"t"===e.charAt(0)&&r.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function n(r,n){return o.type="throw",o.arg=t,e.next=r,n&&(e.method="next",e.arg=void 0),!!n}for(var i=this.tryEntries.length-1;i>=0;--i){var a=this.tryEntries[i],o=a.completion;if("root"===a.tryLoc)return n("end");if(a.tryLoc<=this.prev){var s=r.call(a,"catchLoc"),c=r.call(a,"finallyLoc");if(s&&c){if(this.prev<a.catchLoc)return n(a.catchLoc,!0);if(this.prev<a.finallyLoc)return n(a.finallyLoc)}else if(s){if(this.prev<a.catchLoc)return n(a.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return n(a.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var i=this.tryEntries[n];if(i.tryLoc<=this.prev&&r.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var a=i;break}}a&&("break"===t||"continue"===t)&&a.tryLoc<=e&&e<=a.finallyLoc&&(a=null);var o=a?a.completion:{};return o.type=t,o.arg=e,a?(this.method="next",this.next=a.finallyLoc,p):this.complete(o)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),p},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),k(r),p}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var i=n.arg;k(r)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:D(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),p}},t}(t.exports);try{regeneratorRuntime=e}catch(t){"object"==typeof globalThis?globalThis.regeneratorRuntime=e:Function("r","regeneratorRuntime = r")(e)}})),b=function(t){return"ACC_"+t},k=function(t){return"LINK_"+t},I=function(){function t(t){this.store=t||r}var n=t.prototype;return n.storeDID=function(){var t=y(g.mark((function t(r,n){return g.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:this.store.set(b(r),e.toHex(n));case 1:case"end":return t.stop()}}),t,this)})));return function(e,r){return t.apply(this,arguments)}}(),n.getStoredDID=function(){var t=y(g.mark((function t(r){var n;return g.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return n=this.store.get(b(r)),t.abrupt("return",n?e.fromHex(n):null);case 2:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),n.getDIDs=function(){var t=y(g.mark((function t(){var e;return g.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return e=[],r.each((function(t,r){r.startsWith("ACC_")&&e.push(r.replace("ACC_",""))})),t.abrupt("return",e);case 3:case"end":return t.stop()}}),t)})));return function(){return t.apply(this,arguments)}}(),t}(),D=function(){function t(t){this.store=t||r}var e=t.prototype;return e.setLinkedDid=function(){var t=y(g.mark((function t(e,r){return g.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:this.store.set(k(e),r);case 1:case"end":return t.stop()}}),t,this)})));return function(e,r){return t.apply(this,arguments)}}(),e.getLinkedDid=function(){var t=y(g.mark((function t(e){return g.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",this.store.get(k(e))||null);case 1:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),e.getLinkedAccounts=function(){var t=y(g.mark((function t(){var e;return g.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return e=[],r.each((function(t,r){r.startsWith("LINK_")&&e.push(r.replace("LINK_",""))})),t.abrupt("return",e);case 3:case"end":return t.stop()}}),t)})));return function(){return t.apply(this,arguments)}}(),t}(),L=function(){var t=y(g.mark((function t(e,r){var n,i,a;return g.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r&&(n={body:JSON.stringify(r),method:"POST",headers:{"Content-Type":"application/json"}}),t.next=3,l(e,n);case 3:return i=t.sent,t.next=6,i.json();case 6:if(a=t.sent,!i.ok){t.next=11;break}return t.abrupt("return",a);case 11:throw o=i.status,s=void 0,(s=new Error(a.message)).statusCode=o,s;case 12:case"end":return t.stop()}var o,s}),t)})));return function(e,r){return t.apply(this,arguments)}}(),_="https://verifications-clay.3boxlabs.com";"undefined"!=typeof process&&(_=process.env.VERIFICATION_SERVICE||"https://verifications-clay.3boxlabs.com");var E=function(){function t(t,e){this.idx=e,this.ceramic=e.ceramic,this.user=new n.DID({provider:t,resolver:p.getResolver(this.ceramic)})}t.legacySeedCreate=function(){var t=y(g.mark((function t(r){var n;return g.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=3,r.authenticate("This app wants to view and update your 3Box profile.");case 3:return n=f.mnemonicToSeed(f.entropyToMnemonic(t.sent)),t.abrupt("return",e.fromHex(n.slice(2)));case 6:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}();var r=t.prototype;return r.userDIDAuthenticated=function(){var t=y(g.mark((function t(){return g.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(this.user.authenticated){t.next=3;break}return t.next=3,this.user.authenticate();case 3:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),r.migrateAKALinks=function(){var t=y(g.mark((function t(e,r){var n,i;return g.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return void 0===r&&(r={}),t.next=3,this.userDIDAuthenticated();case 3:return n=function(){var t=y(g.mark((function t(e){var r;return g.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,e.get("alsoKnownAs");case 2:if(t.t1=r=t.sent,null!=t.t1){t.next=7;break}t.t2=void 0,t.next=8;break;case 7:t.t2=r.accounts;case 8:if(t.t0=t.t2,t.t0){t.next=11;break}t.t0=[];case 11:return t.abrupt("return",t.t0);case 12:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),t.next=6,Promise.all([n(this.idx),this._twitterVerify(e,r),this._githubVerify(e,r)]);case 6:return i=t.sent.filter(Boolean).flat(),t.next=10,this.idx.set("alsoKnownAs",{accounts:i});case 10:case"end":return t.stop()}}),t,this)})));return function(e,r){return t.apply(this,arguments)}}(),r.migrate3BoxProfile=function(){var t=y(g.mark((function t(e){var r,n;return g.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,C(e);case 2:return n=R(r=t.sent),t.next=6,this.idx.merge("basicProfile",n);case 6:return t.abrupt("return",r);case 7:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),r._twitterVerify=function(){var t=y(g.mark((function t(e,r){var n,i,a,o,s,u,p,h;return g.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.userDIDAuthenticated();case 2:if(t.prev=2,r.proof_twitter){t.next=5;break}return t.abrupt("return",null);case 5:return a="twitter",f=r.proof_twitter.split(".")[1],d=c.fromString(f,"base64"),o=JSON.parse(c.toString(d)),s=null==(n=o.claim)?void 0:n.twitter_handle,u=null==(i=o.claim)?void 0:i.twitter_proof,t.next=11,M(a,e,s);case 11:return p=t.sent,t.next=14,this.user.createJWS({challengeCode:p});case 14:return h=t.sent,t.next=17,B(a,h,u);case 17:return t.abrupt("return",{protocol:"https",host:"twitter.com",id:s,claim:u,attestations:[{"did-jwt-vc":t.sent}]});case 21:return t.prev=21,t.t0=t.catch(2),t.abrupt("return",null);case 24:case"end":return t.stop()}var f,d}),t,this,[[2,21]])})));return function(e,r){return t.apply(this,arguments)}}(),r._githubVerify=function(){var t=y(g.mark((function t(e,r){var n,i,a,o,s,c,u;return g.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.userDIDAuthenticated();case 2:if(t.prev=2,r.proof_github){t.next=5;break}return t.abrupt("return",null);case 5:if(a="github",o=r.proof_github,s=null==(n=r.proof_github)||null==(i=n.split("//")[1])?void 0:i.split("/")[1]){t.next=10;break}throw new Error("link fail");case 10:return t.next=12,M(a,e,s);case 12:return c=t.sent,t.next=15,this.user.createJWS({challengeCode:c});case 15:return u=t.sent,t.next=18,B(a,u,o);case 18:return t.abrupt("return",{protocol:"https",host:"github.com",id:s,claim:o,attestations:[{"did-jwt-vc":t.sent}]});case 22:return t.prev=22,t.t0=t.catch(2),t.abrupt("return",null);case 25:case"end":return t.stop()}}),t,this,[[2,22]])})));return function(e,r){return t.apply(this,arguments)}}(),t}(),P=function(t){return!!t.statusCode&&404===(null==t?void 0:t.statusCode)},A=function(){var t=y(g.mark((function t(e){var r,n;return g.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if("eip155"===(r=new d.AccountID(e)).chainId.namespace){t.next=3;break}return t.abrupt("return",null);case 3:return n=r.address.toLowerCase(),t.prev=4,t.next=7,L("https://beta.3box.io/address-server/odbAddress/"+n);case 7:return t.abrupt("return",t.sent.data.did);case 12:if(t.prev=12,t.t0=t.catch(4),console.log("Note: 404 Error is expected behavior, and indicates the user does not have a legacy 3Box profile."),!P(t.t0)){t.next=17;break}return t.abrupt("return",null);case 17:throw new Error("Error while resolve V03ID");case 18:case"end":return t.stop()}}),t,null,[[4,12]])})));return function(e){return t.apply(this,arguments)}}(),C=function(){var t=y(g.mark((function t(e){var r;return g.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,r="https://ipfs.3box.io/profile?did="+encodeURIComponent(e),t.abrupt("return",L(r));case 5:if(t.prev=5,t.t0=t.catch(0),!P(t.t0)){t.next=9;break}return t.abrupt("return",null);case 9:throw new Error("Error while fetching 3Box Profile");case 10:case"end":return t.stop()}}),t,null,[[0,5]])})));return function(e){return t.apply(this,arguments)}}(),S=function(){var t=y(g.mark((function t(e){var r;return g.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=3,j(e);case 3:if(r=t.sent.links.filter((function(t){return"ethereum-eoa"===t.type}))[0]){t.next=8;break}return t.abrupt("return",null);case 8:return t.abrupt("return",{account:r.address+"@eip155:1",message:r.message,signature:r.signature,timestamp:r.timestamp,type:"ethereum-eoa",version:2});case 11:if(t.prev=11,t.t0=t.catch(0),console.log(t.t0),!P(t.t0)){t.next=16;break}return t.abrupt("return",null);case 16:throw new Error("Error while fetching 3Box Config");case 17:case"end":return t.stop()}}),t,null,[[0,11]])})));return function(e){return t.apply(this,arguments)}}(),j=function(){var t=y(g.mark((function t(e){var r;return g.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r="https://ipfs.3box.io/config?did="+encodeURIComponent(e),t.abrupt("return",L(r));case 2:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),O=function(){var t=y(g.mark((function t(e){var r,n;return g.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=e.split(":").pop(),n="https://ipfs.3box.io/did-doc?cid="+encodeURIComponent(r),t.next=4,L(n);case 4:return t.abrupt("return",t.sent.value);case 7:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),N=function(){var t=y(g.mark((function t(e,r){var n,i,a,o;return g.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return n=new d.AccountID(e).address.toLowerCase(),t.next=3,O(r);case 3:i=t.sent,t.prev=4,o=i.publicKey.findIndex((function(t){return t.id.endsWith("managementKey")})),a=i.publicKey[o].ethereumAddress,t.next=12;break;case 9:return t.prev=9,t.t0=t.catch(4),t.abrupt("return",!0);case 12:return t.abrupt("return",n!==a);case 13:case"end":return t.stop()}}),t,null,[[4,9]])})));return function(e,r){return t.apply(this,arguments)}}(),q={name:150,description:420,location:140,website:240,emoji:2,employer:140,school:140},T=function(t,e){return!!q[e]&&"string"==typeof t[e]&&t[e].length<=q[e]},R=function(t){var e,r,n,i,a={};return T(t,"name")&&(a.name=t.name),T(t,"description")&&(a.description=t.description),T(t,"location")&&(a.homeLocation=t.location),T(t,"website")&&(a.url=t.website),T(t,"emoji")&&(a.emoji=t.emoji),T(t,"employer")&&(a.affiliations=[t.employer]),T(t,"school")&&(a.affiliations=(a.affiliations||[]).concat([t.school])),t.image&&(n=null==(e=t.image[0])?void 0:e.contentUrl["/"]),n&&"string"==typeof n&&(a.image={original:{src:"ipfs://"+n,mimeType:"application/octet-stream",width:170,height:170}}),t.coverPhoto&&(i=null==(r=t.coverPhoto[0])?void 0:r.contentUrl["/"]),i&&"string"==typeof i&&(a.background={original:{src:"ipfs://"+i,mimeType:"application/octet-stream",width:1e3,height:175}}),a},M=function(){var t=y(g.mark((function t(e,r,n){var i,a;return g.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,i={username:n,did:r},a=_+"/api/v0/request-"+e,t.next=5,L(a,i);case 5:return t.abrupt("return",t.sent.data.challengeCode);case 9:throw t.prev=9,t.t0=t.catch(0),console.error(t.t0),new Error("Error while requesting "+e+" link request.");case 13:case"end":return t.stop()}}),t,null,[[0,9]])})));return function(e,r,n){return t.apply(this,arguments)}}(),B=function(){var t=y(g.mark((function t(e,r,n){var i,a;return g.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,i={jws:r,verificationUrl:n},a=_+"/api/v0/confirm-"+e,t.next=5,L(a,i);case 5:return t.abrupt("return",t.sent.data.attestation);case 9:throw t.prev=9,t.t0=t.catch(0),console.error(t.t0),new Error("Error while verifying "+e+" link request.");case 13:case"end":return t.stop()}}),t,null,[[0,9]])})));return function(e,r,n){return t.apply(this,arguments)}}(),G="https://ceramic-clay.3boxlabs.com",K=!0;"undefined"!=typeof process&&(G=process.env.CERAMIC_API||"https://ceramic-clay.3boxlabs.com"),"undefined"!=typeof process&&(K=!process.env.MIGRATION||"true"===process.env.MIGRATION);var F=function(){function t(t,e){this.authProvider=t,this.store=e.store||new I,this.cache=e.cache||new D,this.ceramic=e.ceramic||new i(G),this.idx=new a.IDX({ceramic:this.ceramic}),this.threeIdProviders={}}var r=t.prototype;return r.createAccount=function(){var t=y(g.mark((function t(r){var n,i,a,o,s,c,u,p,h,f,d,l,v,x;return g.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return n=K&&!(null!=r&&r.skipMigration),t.next=3,this.authProvider.accountId();case 3:if(i=t.sent.toString(),!this.threeIdProviders[i]){t.next=6;break}return t.abrupt("return",this.threeIdProviders[i].id);case 6:return t.prev=6,t.next=9,this.setDidByAccountId(i);case 9:return t.abrupt("return",t.sent.id);case 13:t.prev=13,t.t0=t.catch(6);case 15:return t.next=17,this.linkInNetwork(i);case 17:if(a=t.sent,t.prev=18,a){t.next=21;break}throw new Error("Expects didNetwork Link");case 21:return t.next=23,this.setDid(a);case 23:return t.abrupt("return",t.sent.id);case 27:t.prev=27,t.t1=t.catch(18);case 29:return t.next=31,this._authCreate();case 31:if(o=t.sent,!n){t.next=48;break}if(!r||!("legacyDid"in r)){t.next=37;break}t.t2=r.legacyDid,t.next=40;break;case 37:return t.next=39,A(i);case 39:t.t2=t.sent;case 40:if(!(s=t.t2)||a){t.next=48;break}return t.next=44,E.legacySeedCreate(this.authProvider);case 44:p=o,c={v03ID:s,seed:t.sent},u=!0;case 48:return e.assert.isDefined(h=u?c:{authSecret:o,authId:i},"Identity Config to initialize identity"),t.next=52,this._initIdentity(h);case 52:if(f=t.sent,!u||!s){t.next=67;break}return t.prev=54,l=this.threeIdProviders[f].getDidProvider(),v=new E(l,this.idx),x=function(){var t=y(g.mark((function t(){var e;return g.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,v.migrate3BoxProfile(f);case 2:return e=t.sent,t.next=5,v.migrateAKALinks(f,e);case 5:case"end":return t.stop()}}),t)})));return function(){return t.apply(this,arguments)}}(),t.next=60,Promise.all([S(f),x()]);case 60:d=t.sent[0],t.next=67;break;case 64:t.prev=64,t.t3=t.catch(54),console.error(t.t3);case 67:if(!p){t.next=70;break}return t.next=70,this._addAuthMethod(f,p);case 70:return t.next=72,this._addLink(f,d);case 72:return t.abrupt("return",f);case 73:case"end":return t.stop()}}),t,this,[[6,13],[18,27],[54,64]])})));return function(e){return t.apply(this,arguments)}}(),r._initIdentity=function(){var t=y(g.mark((function t(e){var r,n;return g.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=Object.assign(e,{getPermission:function(){return Promise.resolve([])},ceramic:this.ceramic}),t.next=4,s.create(r);case 4:return this.threeIdProviders[(n=t.sent).id]=n,t.next=8,this.store.storeDID(n.id,this.threeIdProviders[n.id].keychain._keyring.seed);case 8:return t.abrupt("return",n.id);case 9:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),r._addAuthMethod=function(){var t=y(g.mark((function t(e,r){var n,i;return g.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.setDid(e);case 2:return n=t.sent,t.next=5,this.authProvider.accountId();case 5:return i=t.sent.toString(),t.next=8,n.keychain.add(i,r);case 8:return t.next=10,n.keychain.commit();case 10:case"end":return t.stop()}}),t,this)})));return function(e,r){return t.apply(this,arguments)}}(),r._authCreate=function(){var t=y(g.mark((function t(){var e;return g.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=3,this.authProvider.authenticate("Allow this account to control your identity");case 3:return e=o.hash(c.fromString(t.sent.slice(2))),t.abrupt("return",e);case 6:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),r.setDid=function(){var t=y(g.mark((function t(r){var i,a,o,s,c,f;return g.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(this.threeIdProviders[r]){t.next=7;break}return t.next=3,this.store.getStoredDID(r);case 3:return e.assert.isDefined(i=t.sent,"Account does not exist"),t.next=7,this._initIdentity({seed:i,did:r});case 7:return a=this.threeIdProviders[r].getDidProvider(),o=u.getResolver(),s=p.getResolver(this.ceramic),c=new h.Resolver(m({},s,o)),f=new n.DID({provider:a,resolver:c}),t.next=14,f.authenticate();case 14:return t.next=16,this.ceramic.setDID(f);case 16:return t.abrupt("return",this.threeIdProviders[r]);case 17:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),r.setDidByAccountId=function(){var t=y(g.mark((function t(r){var n;return g.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.cache.getLinkedDid(r);case 2:return e.assert.isDefined(n=t.sent,"Account does not exist"),t.abrupt("return",this.setDid(n));case 5:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),r._addLink=function(){var t=y(g.mark((function t(e,r){var n,i,a,o,s;return g.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.authProvider.accountId();case 2:return i=t.sent,t.next=5,this.setDid(e);case 5:return t.next=7,this.idx.get("cryptoAccounts");case 7:if(t.t0=t.sent,t.t0){t.next=10;break}t.t0={};case 10:if(!(a=t.t0)||!a[i.toString()]){t.next=13;break}return t.abrupt("return");case 13:if(r){t.next=17;break}return t.next=16,this.authProvider.createLink(e);case 16:r=t.sent;case 17:return t.next=19,v.Caip10Link.fromAccount(this.ceramic,i,{anchor:!1,publish:!1});case 19:return o=t.sent,t.next=22,o.setDidProof(r);case 22:return t.next=24,this.ceramic.pin.add(o.id);case 24:return s=Object.assign(a,((n={})[i.toString()]=o.id.toUrl(),n)),t.next=27,this.idx.set("cryptoAccounts",s);case 27:return t.next=29,this.cache.setLinkedDid(i.toString(),e);case 29:case"end":return t.stop()}}),t,this)})));return function(e,r){return t.apply(this,arguments)}}(),r.addAuthAndLink=function(){var t=y(g.mark((function t(e){var r;return g.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this._addLink(e);case 2:return t.next=4,this._authCreate();case 4:return r=t.sent,t.next=7,this._addAuthMethod(e,r);case 7:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),r.linkInNetwork=function(){var t=y(g.mark((function t(e){var r;return g.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=3,this.idx.caip10ToDid(e);case 3:return r=t.sent,t.next=6,this.didExist(r);case 6:if(!t.sent){t.next=9;break}return t.next=9,this.cache.setLinkedDid(e,r);case 9:return t.abrupt("return",r);case 12:return t.prev=12,t.t0=t.catch(0),t.abrupt("return",null);case 15:case"end":return t.stop()}}),t,this,[[0,12]])})));return function(e){return t.apply(this,arguments)}}(),r.listDIDS=function(){var t=y(g.mark((function t(){return g.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",this.store.getDIDs());case 1:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),r.didExist=function(){var t=y(g.mark((function t(e){var r;return g.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.listDIDS();case 2:return r=t.sent,t.abrupt("return",Boolean(r&&r.includes(e)));case 4:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),r.didProvider=function(t){var e;return null==(e=this.threeIdProviders[t])?void 0:e.getDidProvider()},t}();exports.DIDStore=I,exports.LinkCache=D,exports.Manager=F,exports.Migrate3IDV0=E,exports.legacyDIDLinkExist=A,exports.willMigrationFail=N;
//# sourceMappingURL=manager.cjs.production.min.js.map