@tonomy/antelope-did
Version:
Create, resolve, update and deactivate Decentralized Identifier (DID) documents based on Antelope blockchains
3 lines (2 loc) • 14.9 kB
JavaScript
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@tonomy/did-resolver"),e=require("@tonomy/antelope-did-resolver"),r=require("eosjs"),n=require("util");function o(){o=function(){return t};var t={},e=Object.prototype,r=e.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},a=n.iterator||"@@iterator",i=n.asyncIterator||"@@asyncIterator",c=n.toStringTag||"@@toStringTag";function u(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{u({},"")}catch(t){u=function(t,e,r){return t[e]=r}}function s(t,e,r,n){var o=Object.create((e&&e.prototype instanceof h?e:h).prototype),a=new _(n||[]);return o._invoke=function(t,e,r){var n="suspendedStart";return function(o,a){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw a;return{value:void 0,done:!0}}for(r.method=o,r.arg=a;;){var i=r.delegate;if(i){var c=x(i,r);if(c){if(c===p)continue;return c}}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 u=f(t,e,r);if("normal"===u.type){if(n=r.done?"completed":"suspendedYield",u.arg===p)continue;return{value:u.arg,done:r.done}}"throw"===u.type&&(n="completed",r.method="throw",r.arg=u.arg)}}}(t,r,a),o}function f(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=s;var p={};function h(){}function l(){}function d(){}var v={};u(v,a,(function(){return this}));var y=Object.getPrototypeOf,m=y&&y(y(O([])));m&&m!==e&&r.call(m,a)&&(v=m);var w=d.prototype=h.prototype=Object.create(v);function g(t){["next","throw","return"].forEach((function(e){u(t,e,(function(t){return this._invoke(e,t)}))}))}function b(t,e){var n;this._invoke=function(o,a){function i(){return new e((function(n,i){!function n(o,a,i,c){var u=f(t[o],t,a);if("throw"!==u.type){var s=u.arg,p=s.value;return p&&"object"==typeof p&&r.call(p,"__await")?e.resolve(p.__await).then((function(t){n("next",t,i,c)}),(function(t){n("throw",t,i,c)})):e.resolve(p).then((function(t){s.value=t,i(s)}),(function(t){return n("throw",t,i,c)}))}c(u.arg)}(o,a,n,i)}))}return n=n?n.then(i,i):i()}}function x(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,x(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=f(r,t.iterator,e.arg);if("throw"===n.type)return e.method="throw",e.arg=n.arg,e.delegate=null,p;var o=n.arg;return o?o.done?(e[t.resultName]=o.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,p):o:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,p)}function E(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 _(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(E,this),this.reset(!0)}function O(t){if(t){var e=t[a];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,o=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 o.next=o}}return{next:L}}function L(){return{value:void 0,done:!0}}return l.prototype=d,u(w,"constructor",d),u(d,"constructor",l),l.displayName=u(d,c,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===l||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,d):(t.__proto__=d,u(t,c,"GeneratorFunction")),t.prototype=Object.create(w),t},t.awrap=function(t){return{__await:t}},g(b.prototype),u(b.prototype,i,(function(){return this})),t.AsyncIterator=b,t.async=function(e,r,n,o,a){void 0===a&&(a=Promise);var i=new b(s(e,r,n,o),a);return t.isGeneratorFunction(r)?i:i.next().then((function(t){return t.done?t.value:i.next()}))},g(w),u(w,c,"Generator"),u(w,a,(function(){return this})),u(w,"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=O,_.prototype={constructor:_,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 i.type="throw",i.arg=t,e.next=r,n&&(e.method="next",e.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var a=this.tryEntries[o],i=a.completion;if("root"===a.tryLoc)return n("end");if(a.tryLoc<=this.prev){var c=r.call(a,"catchLoc"),u=r.call(a,"finallyLoc");if(c&&u){if(this.prev<a.catchLoc)return n(a.catchLoc,!0);if(this.prev<a.finallyLoc)return n(a.finallyLoc)}else if(c){if(this.prev<a.catchLoc)return n(a.catchLoc,!0)}else{if(!u)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 o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var a=o;break}}a&&("break"===t||"continue"===t)&&a.tryLoc<=e&&e<=a.finallyLoc&&(a=null);var i=a?a.completion:{};return i.type=t,i.arg=e,a?(this.method="next",this.next=a.finallyLoc,p):this.complete(i)},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 o=n.arg;k(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:O(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),p}},t}function a(t,e,r,n,o,a,i){try{var c=t[a](i),u=c.value}catch(t){return void r(t)}c.done?e(u):Promise.resolve(u).then(n,o)}function i(t){return function(){var e=this,r=arguments;return new Promise((function(n,o){var i=t.apply(e,r);function c(t){a(i,n,o,c,u,"next",t)}function u(t){a(i,n,o,c,u,"throw",t)}c(void 0)}))}}function c(){return(c=Object.assign?Object.assign.bind():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 u(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function s(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(r)return(r=r.call(t)).next.bind(r);if(Array.isArray(t)||(r=function(t,e){if(t){if("string"==typeof t)return u(t,void 0);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?u(t,void 0):void 0}}(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var n=0;return function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function f(t,r){var n=r.match(e.REGEX_CHAIN_NAME);if(n){var o=t[n[1]];if(o)return o;throw new Error("No matching chain registry entry for supplied chain name.")}var a=r.match(e.REGEX_CHAIN_ID);if(a)for(var i=0,c=Object.keys(t);i<c.length;i++){var u=t[c[i]];if(u.chainId===a[1])return u;throw new Error("No matching chain registry entry for supplied chain id.")}throw new Error("Supplied chain id or name does not conform to specification.")}function p(t){if(null===t.match(e.REGEX_ACCOUNT_NAME))throw new Error(t+" does not conform to account name specification.")}var h=new t.Resolver(e.getResolver());function l(t,e,r,n,o){return d.apply(this,arguments)}function d(){return(d=i(o().mark((function t(a,i,u,l,d){var v,y,m,w,g,b,x,E,k,_,O;return o().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:p(a),p(i),v=c({},e.antelopeChainRegistry,d.registry),y=f(v,d.chain),m=[{actor:a,permission:d.accountPermission}],w=s(y.service);case 6:if((g=w()).done){t.next=33;break}return b=new r.JsonRpc(g.value.serviceEndpoint,d.fetch?{fetch:d.fetch}:void 0),x=new r.Api({rpc:b,signatureProvider:d.signatureProvider,textDecoder:new n.TextDecoder,textEncoder:new n.TextEncoder}),t.prev=10,t.next=13,x.transact({actions:[{account:"eosio",name:"newaccount",authorization:m,data:{creator:a,name:i,owner:u,active:l}},{account:"eosio",name:"buyrambytes",authorization:m,data:{payer:a,receiver:i,bytes:d.buyrambytes}},{account:"eosio",name:"delegatebw",authorization:m,data:{from:a,receiver:i,stake_net_quantity:d.stakeNetQuantity,stake_cpu_quantity:d.stakeNetQuantity,transfer:d.transfer}}]},d.transactionOptions);case 13:return E=t.sent,k="did:antelope:"+d.chain+":"+i,t.next=17,h.resolve(k,c({},d));case 17:if(!(O=(_=t.sent).didResolutionMetadata.error)){t.next=21;break}return t.abrupt("return",{didCreateMetadata:{tx:E,error:O}});case 21:if(_.didDocument){t.next=23;break}return t.abrupt("return",{didCreateMetadata:{error:"notFound"}});case 23:return t.abrupt("return",{didCreateMetadata:{tx:E},didDocument:_.didDocument});case 26:if(t.prev=26,t.t0=t.catch(10),!(t.t0 instanceof r.RpcError)){t.next=30;break}return t.abrupt("return",{didCreateMetadata:{error:t.t0}});case 30:console.error(t.t0);case 31:t.next=6;break;case 33:throw new Error("Could not create DID.");case 34:case"end":return t.stop()}}),t,null,[[10,26]])})))).apply(this,arguments)}var v=new t.Resolver(e.getResolver());function y(t,e,r,n,o){return m.apply(this,arguments)}function m(){return(m=i(o().mark((function t(a,i,u,h,l){var d,y,m,w,g,b,x,E,k,_,O;return o().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:p(a),d=c({},e.antelopeChainRegistry,l.registry),y=f(d,l.chain),m=s(y.service);case 4:if((w=m()).done){t.next=32;break}return g=new r.JsonRpc(w.value.serviceEndpoint,l.fetch?{fetch:l.fetch}:void 0),b=new r.Api({rpc:g,signatureProvider:l.signatureProvider,textDecoder:new n.TextDecoder,textEncoder:new n.TextEncoder}),t.prev=8,x={actions:[{account:"eosio",name:"updateauth",authorization:[{actor:a,permission:u}],data:{account:a,permission:i,parent:u,auth:h}}]},t.next=12,b.transact(x,l.transactionOptions);case 12:return E=t.sent,k="did:antelope:"+l.chain+":"+a,t.next=16,v.resolve(k,c({},l));case 16:if(!(O=(_=t.sent).didResolutionMetadata.error)){t.next=20;break}return t.abrupt("return",{didUpdateMetadata:{tx:E,error:O}});case 20:if(_.didDocument){t.next=22;break}return t.abrupt("return",{didUpdateMetadata:{error:"notFound"}});case 22:return t.abrupt("return",{didUpdateMetadata:{tx:E},didDocument:_.didDocument});case 25:if(t.prev=25,t.t0=t.catch(8),!(t.t0 instanceof r.RpcError)){t.next=29;break}return t.abrupt("return",{didUpdateMetadata:{error:t.t0}});case 29:console.error(t.t0);case 30:t.next=4;break;case 32:throw new Error("Could not update DID.");case 33:case"end":return t.stop()}}),t,null,[[8,25]])})))).apply(this,arguments)}function w(t,e){return g.apply(this,arguments)}function g(){return(g=i(o().mark((function t(e,r){return o().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:throw Error("Antelope DID deactivate not supported. If this Antelope chain support deactivation of accounts, please override this function with the appropriate functionality");case 1:case"end":return t.stop()}}),t)})))).apply(this,arguments)}var b=new t.Resolver(e.getResolver());function x(t,e){return E.apply(this,arguments)}function E(){return(E=i(o().mark((function t(e,r){return o().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,b.resolve(e,c({},r));case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}}),t)})))).apply(this,arguments)}var k={accountPermission:"active",transactionOptions:{blocksBehind:3,expireSeconds:30}},_={buyrambytes:8192,stakeNetQuantity:"1.0000 EOS",stakeCpuQuantity:"1.0000 EOS",transfer:!1},O=function(){function t(t){this._options=c({},k,t)}var e,r,n=t.prototype;return n.create=function(){var t=i(o().mark((function t(e,r,n,a,i){return o().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,l(e,r,n,a,c({},_,this._options,i));case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}}),t,this)})));return function(e,r,n,o,a){return t.apply(this,arguments)}}(),n.resolve=function(){var t=i(o().mark((function t(e,r){return o().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,x(e,c({},this._options,r));case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}}),t,this)})));return function(e,r){return t.apply(this,arguments)}}(),n.update=function(){var t=i(o().mark((function t(e,r,n,a,i){return o().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,y(e,r,n,a,c({},this._options,i));case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}}),t,this)})));return function(e,r,n,o,a){return t.apply(this,arguments)}}(),n.deactivate=function(){var t=i(o().mark((function t(e,r){return o().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,w(e,c({},this._options,r));case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}}),t,this)})));return function(e,r){return t.apply(this,arguments)}}(),e=t,(r=[{key:"options",get:function(){return this._options},set:function(t){this._options=t}}])&&function(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}(e.prototype,r),Object.defineProperty(e,"prototype",{writable:!1}),t}();Object.defineProperty(exports,"antelopeChainRegistry",{enumerable:!0,get:function(){return e.antelopeChainRegistry}}),Object.defineProperty(exports,"checkDID",{enumerable:!0,get:function(){return e.checkDID}}),Object.defineProperty(exports,"createDIDDocument",{enumerable:!0,get:function(){return e.createDIDDocument}}),Object.defineProperty(exports,"fetchAccount",{enumerable:!0,get:function(){return e.fetchAccount}}),exports.default=O;
//# sourceMappingURL=antelope-did.cjs.production.min.js.map