New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@automata-network/pom-js-sdk

Package Overview
Dependencies
Maintainers
0
Versions
80
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@automata-network/pom-js-sdk - npm Package Compare versions

Comparing version

to
0.0.71

2

dist/index.js

@@ -1,2 +0,2 @@

"use strict";var e,r,a,o,t=require("@automata-network/pom-socket"),s=require("qrcode"),i=require("./util.js");exports.ChainId=void 0,(e=exports.ChainId||(exports.ChainId={})).LineaSepolia="0xe705",e.AutomataTestnet="0x1555e3",e.AutomataMainnet="0x10000",exports.POMPlatform=void 0,(r=exports.POMPlatform||(exports.POMPlatform={})).Android="android",r.iOS="iOS",r.macOS="macOS",exports.IdentityStatus=void 0,(a=exports.IdentityStatus||(exports.IdentityStatus={})).None="none",a.Generated="generated",a.Registered="registered",exports.CallbackBrowser=void 0,(o=exports.CallbackBrowser||(exports.CallbackBrowser={})).iOSChrome="iOSChrome",o.iOSSafari="iOSSafari",o.iOSEdge="iOSEdge",o.iOSFirefox="iOSFirefox",o.iOSOpera="iOSOpera",o.iOSBrave="iOSBrave",o.iOSAloha="iOSAloha",o.androidChrome="androidChrome",o.androidEdge="androidEdge",o.androidFirefox="androidFirefox",o.androidOpera="androidOpera",o.androidBrave="androidBrave",o.androidAloha="androidAloha",o.macOSChrome="macOSChrome",o.macOSSafari="macOSSafari",o.macOSEdge="macOSEdge",o.macOSFirefox="macOSFirefox",o.macOSOpera="macOSOpera",o.macOSBrave="macOSBrave",o.macOSAloha="macOSAloha";const c={macOS:{[exports.CallbackBrowser.macOSChrome]:"com.google.Chrome",[exports.CallbackBrowser.macOSSafari]:"com.apple.safari",[exports.CallbackBrowser.macOSFirefox]:"org.mozilla.firefox",[exports.CallbackBrowser.macOSEdge]:"com.microsoft.edgemac",[exports.CallbackBrowser.macOSBrave]:"com.brave.Browser",[exports.CallbackBrowser.macOSOpera]:"com.operasoftware.Opera",[exports.CallbackBrowser.macOSAloha]:"com.alohabrowser.alohabrowser"},iOS:{[exports.CallbackBrowser.iOSChrome]:"com.google.chrome.ios",[exports.CallbackBrowser.iOSSafari]:"com.apple.mobilesafari",[exports.CallbackBrowser.iOSFirefox]:"org.mozilla.ios.Firefox",[exports.CallbackBrowser.iOSEdge]:"com.microsoft.msedge",[exports.CallbackBrowser.iOSBrave]:"com.brave.ios.browser",[exports.CallbackBrowser.iOSOpera]:"com.opera.OperaTouch",[exports.CallbackBrowser.iOSAloha]:"com.alohabrowser.alohabrowser"},android:{[exports.CallbackBrowser.androidChrome]:"com.android.chrome",[exports.CallbackBrowser.androidFirefox]:"org.mozilla.firefox",[exports.CallbackBrowser.androidEdge]:"com.microsoft.emmx",[exports.CallbackBrowser.androidBrave]:"com.brave.browser",[exports.CallbackBrowser.androidOpera]:"com.opera.browser",[exports.CallbackBrowser.androidAloha]:"com.aloha.browser"}},n="pom-universal-link.ata.network",d="https:",l=new Error("deep link is invalid"),p=new Error("deep link parameters is invalid"),m=new Error("socket is connecting"),S=new Error("get identity status timeout"),h=new Error("identity is empty");class O{pomSocket;constructor(...[e,r]){this.pomSocket=t.getSocket(e,r)}static generateDeepLink(e){const{sessionId:r,dhSharedPublicNumber:a,hkdfSalt:o,callbackBrowser:t,callbackDeepLinkUrl:s}=e,i=new URL(`${d}://${n}#download`);return r&&i.searchParams.set("id",r),a&&i.searchParams.set("dh",a),o&&i.searchParams.set("s",o),t&&i.searchParams.set("cb",t),s&&i.searchParams.set("cu",s),i.href}static parseDeepLinkQuery(e){const r=new URL(e);if(console.log("url",e,r.hostname,r.protocol,r.search,n,d),r.hostname!==n||r.protocol!==d)throw l;const a=r.searchParams.get("id"),o=r.searchParams.get("dh"),t=r.searchParams.get("s"),s=r.searchParams.get("cu"),i=r.searchParams.get("cb");if(console.log("url",r.searchParams.entries(),{id:a,dh:o,s:t,cu:s,cb:i}),null!=a&&"string"!=typeof a||null!=o&&"string"!=typeof o||null!=t&&"string"!=typeof t||null!=s&&"string"!=typeof s||null!=i&&"string"!=typeof i)throw p;return{id:a,dh:o,s:t,cu:s,cb:i}}static async generateQrcode(e,r){const{sessionId:a,dhSharedPublicNumber:o,hkdfSalt:t}=e,i=[o?{data:o.toUpperCase(),mode:"alphanumeric"}:void 0,t?{data:t,mode:"alphanumeric"}:void 0,a?{data:a}:void 0];return await s.toDataURL(i.filter((e=>null!=e)),{errorCorrectionLevel:r?.level||"L"})}static parseQrcode(e){const r=e.slice(0,128).toLowerCase(),a=e.slice(128,160);return{id:e.slice(160),dh:r,s:a}}async sign(e){const{chainId:r,caller:a,message:o,qrcodeLevel:s,onRenderQrcode:c,onGetIdentityOnChain:n,onRegisterIdentity:d}=e;let l=this.pomSocket.getSocketStatus();if(l===t.SocketStatus.Connecting)throw m;l===t.SocketStatus.Disconnected&&await this.connectSocketAndWait({qrcodeLevel:s,onRenderQrcode:c});const p=await this.getIdentityStatus({chainId:r}).promise;let S;if(p.status!==exports.IdentityStatus.None&&p.status!==exports.IdentityStatus.Generated||(S=await this.attestDevice({chainId:r,caller:a}).promise),p.status===exports.IdentityStatus.None||p.status===exports.IdentityStatus.Generated){if(null==S)throw h;await d(S),await i.runWithErrorRetry((()=>{const e=n({chainId:r,identity:S.identity});if(!e)throw i.ERR_NEED_RETRY;return e}))}return await this.signMessage({chainId:r,caller:a,message:o}).promise}async connectSocketAndWait(e){try{const{qrcodeLevel:r,onRenderQrcode:a}=e,o=await this.connectSocket(),t=O.generateDeepLink(o);a({deepLink:t,imageBase64:await O.generateQrcode(o,r?{level:r}:void 0)}),await this.waitForConnectedEvent(),await this.waitForKeyExchangeEvent()}catch(r){if(r!==t.ERR_SESSION_IS_EXPIRED)throw r;this.connectSocketAndWait(e)}}async connectSocket(){return this.pomSocket.connect()}async waitForConnectedEvent(){return this.pomSocket.waitForConnectedEvent()}async waitForKeyExchangeEvent(){return this.pomSocket.waitForKeyExchangeEvent()}getIdentityStatus(e){const{chainId:r}=e;let a;return{promise:new Promise(((e,o)=>{a=i.sendMessageAndWaitForResponse({socket:this.pomSocket,op:i.POMOperation.GetIdentityStatus,data:{chainId:r},resolver:e,rejecter:o})})),cancel:a}}attestDevice(e){let r;return{promise:new Promise(((a,o)=>{r=i.sendMessageAndWaitForResponse({socket:this.pomSocket,op:i.POMOperation.AttestDevice,data:e,resolver:a,rejecter:o})})),cancel:r}}signMessage(e){let r;return{promise:new Promise(((a,o)=>{r=i.sendMessageAndWaitForResponse({socket:this.pomSocket,op:i.POMOperation.SignMessage,data:e,resolver:a,rejecter:o})})),cancel:r}}}exports.ERR_OPERATION_CANCELLED=i.ERR_OPERATION_CANCELLED,Object.defineProperty(exports,"POMOperation",{enumerable:!0,get:function(){return i.POMOperation}}),exports.decodeMessageData=i.decodeMessageData,exports.encodeMessageData=i.encodeMessageData,exports.getCallbackBrowser=i.getCallbackBrowser,exports.ERR_GET_IDENTITY_STATUS_TIMEOUT=S,exports.ERR_IDENTITY_IS_EMPTY=h,exports.ERR_INVALID_DEEP_LINK=l,exports.ERR_INVALID_DEEP_LINK_PARAMETERS=p,exports.ERR_SOCKET_IS_CONNECTING=m,exports.POMClinet=O,exports.bundleIds=c;
"use strict";var e,r,a,t,o=require("@automata-network/pom-socket"),s=require("qrcode"),i=require("./util.js");exports.ChainId=void 0,(e=exports.ChainId||(exports.ChainId={})).LineaSepolia="0xe705",e.AutomataTestnet="0x1555e3",e.AutomataMainnet="0x10000",exports.POMPlatform=void 0,(r=exports.POMPlatform||(exports.POMPlatform={})).Android="android",r.iOS="iOS",r.macOS="macOS",exports.IdentityStatus=void 0,(a=exports.IdentityStatus||(exports.IdentityStatus={})).None="none",a.Generated="generated",a.Registered="registered",exports.CallbackBrowser=void 0,(t=exports.CallbackBrowser||(exports.CallbackBrowser={})).iOSChrome="iOSChrome",t.iOSSafari="iOSSafari",t.iOSEdge="iOSEdge",t.iOSFirefox="iOSFirefox",t.iOSOpera="iOSOpera",t.iOSBrave="iOSBrave",t.iOSAloha="iOSAloha",t.androidChrome="androidChrome",t.androidEdge="androidEdge",t.androidFirefox="androidFirefox",t.androidOpera="androidOpera",t.androidBrave="androidBrave",t.androidAloha="androidAloha",t.macOSChrome="macOSChrome",t.macOSSafari="macOSSafari",t.macOSEdge="macOSEdge",t.macOSFirefox="macOSFirefox",t.macOSOpera="macOSOpera",t.macOSBrave="macOSBrave",t.macOSAloha="macOSAloha";const n={macOS:{[exports.CallbackBrowser.macOSChrome]:"com.google.Chrome",[exports.CallbackBrowser.macOSSafari]:"com.apple.safari",[exports.CallbackBrowser.macOSFirefox]:"org.mozilla.firefox",[exports.CallbackBrowser.macOSEdge]:"com.microsoft.edgemac",[exports.CallbackBrowser.macOSBrave]:"com.brave.Browser",[exports.CallbackBrowser.macOSOpera]:"com.operasoftware.Opera",[exports.CallbackBrowser.macOSAloha]:"com.alohabrowser.alohabrowser"},iOS:{[exports.CallbackBrowser.iOSChrome]:"com.google.chrome.ios",[exports.CallbackBrowser.iOSSafari]:"com.apple.mobilesafari",[exports.CallbackBrowser.iOSFirefox]:"org.mozilla.ios.Firefox",[exports.CallbackBrowser.iOSEdge]:"com.microsoft.msedge",[exports.CallbackBrowser.iOSBrave]:"com.brave.ios.browser",[exports.CallbackBrowser.iOSOpera]:"com.opera.OperaTouch",[exports.CallbackBrowser.iOSAloha]:"com.alohabrowser.alohabrowser"},android:{[exports.CallbackBrowser.androidChrome]:"com.android.chrome",[exports.CallbackBrowser.androidFirefox]:"org.mozilla.firefox",[exports.CallbackBrowser.androidEdge]:"com.microsoft.emmx",[exports.CallbackBrowser.androidBrave]:"com.brave.browser",[exports.CallbackBrowser.androidOpera]:"com.opera.browser",[exports.CallbackBrowser.androidAloha]:"com.aloha.browser"}},c="pom-universal-link.ata.network",d="https:",l=new Error("deep link is invalid"),p=new Error("deep link parameters is invalid"),m=new Error("socket is connecting"),S=new Error("get identity status timeout"),h=new Error("identity is empty");class O{pomSocket;constructor(...[e,r]){this.pomSocket=o.getSocket(e,r)}static generateDeepLink(e){const{sessionId:r,dhSharedPublicNumber:a,hkdfSalt:t,callbackBrowser:o,callbackDeepLinkUrl:s}=e,i=new URL(`${d}://${c}`);return i.hash="download",r&&i.searchParams.set("id",r),a&&i.searchParams.set("dh",a),t&&i.searchParams.set("s",t),o&&i.searchParams.set("cb",o),s&&i.searchParams.set("cu",s),i.toString()}static parseDeepLinkQuery(e){const r=new URL(e);if(r.hostname!==c||r.protocol!==d)throw l;const a=r.searchParams.get("id"),t=r.searchParams.get("dh"),o=r.searchParams.get("s"),s=r.searchParams.get("cu"),i=r.searchParams.get("cb");if(null!=a&&"string"!=typeof a||null!=t&&"string"!=typeof t||null!=o&&"string"!=typeof o||null!=s&&"string"!=typeof s||null!=i&&"string"!=typeof i)throw p;return{id:a,dh:t,s:o,cu:s,cb:i}}static async generateQrcode(e,r){const{sessionId:a,dhSharedPublicNumber:t,hkdfSalt:o}=e,i=[t?{data:t.toUpperCase(),mode:"alphanumeric"}:void 0,o?{data:o,mode:"alphanumeric"}:void 0,a?{data:a}:void 0];return await s.toDataURL(i.filter((e=>null!=e)),{errorCorrectionLevel:r?.level||"L"})}static parseQrcode(e){const r=e.slice(0,128).toLowerCase(),a=e.slice(128,160);return{id:e.slice(160),dh:r,s:a}}async sign(e){const{chainId:r,caller:a,message:t,qrcodeLevel:s,onRenderQrcode:n,onGetIdentityOnChain:c,onRegisterIdentity:d}=e;let l=this.pomSocket.getSocketStatus();if(l===o.SocketStatus.Connecting)throw m;l===o.SocketStatus.Disconnected&&await this.connectSocketAndWait({qrcodeLevel:s,onRenderQrcode:n});const p=await this.getIdentityStatus({chainId:r}).promise;let S;if(p.status!==exports.IdentityStatus.None&&p.status!==exports.IdentityStatus.Generated||(S=await this.attestDevice({chainId:r,caller:a}).promise),p.status===exports.IdentityStatus.None||p.status===exports.IdentityStatus.Generated){if(null==S)throw h;await d(S),await i.runWithErrorRetry((()=>{const e=c({chainId:r,identity:S.identity});if(!e)throw i.ERR_NEED_RETRY;return e}))}return await this.signMessage({chainId:r,caller:a,message:t}).promise}async connectSocketAndWait(e){try{const{qrcodeLevel:r,onRenderQrcode:a}=e,t=await this.connectSocket(),o=O.generateDeepLink(t);a({deepLink:o,imageBase64:await O.generateQrcode(t,r?{level:r}:void 0)}),await this.waitForConnectedEvent(),await this.waitForKeyExchangeEvent()}catch(r){if(r!==o.ERR_SESSION_IS_EXPIRED)throw r;this.connectSocketAndWait(e)}}async connectSocket(){return this.pomSocket.connect()}async waitForConnectedEvent(){return this.pomSocket.waitForConnectedEvent()}async waitForKeyExchangeEvent(){return this.pomSocket.waitForKeyExchangeEvent()}getIdentityStatus(e){const{chainId:r}=e;let a;return{promise:new Promise(((e,t)=>{a=i.sendMessageAndWaitForResponse({socket:this.pomSocket,op:i.POMOperation.GetIdentityStatus,data:{chainId:r},resolver:e,rejecter:t})})),cancel:a}}attestDevice(e){let r;return{promise:new Promise(((a,t)=>{r=i.sendMessageAndWaitForResponse({socket:this.pomSocket,op:i.POMOperation.AttestDevice,data:e,resolver:a,rejecter:t})})),cancel:r}}signMessage(e){let r;return{promise:new Promise(((a,t)=>{r=i.sendMessageAndWaitForResponse({socket:this.pomSocket,op:i.POMOperation.SignMessage,data:e,resolver:a,rejecter:t})})),cancel:r}}}exports.ERR_OPERATION_CANCELLED=i.ERR_OPERATION_CANCELLED,Object.defineProperty(exports,"POMOperation",{enumerable:!0,get:function(){return i.POMOperation}}),exports.decodeMessageData=i.decodeMessageData,exports.encodeMessageData=i.encodeMessageData,exports.getCallbackBrowser=i.getCallbackBrowser,exports.ERR_GET_IDENTITY_STATUS_TIMEOUT=S,exports.ERR_IDENTITY_IS_EMPTY=h,exports.ERR_INVALID_DEEP_LINK=l,exports.ERR_INVALID_DEEP_LINK_PARAMETERS=p,exports.ERR_SOCKET_IS_CONNECTING=m,exports.POMClinet=O,exports.bundleIds=n;
//# sourceMappingURL=index.js.map
{
"name": "@automata-network/pom-js-sdk",
"version": "0.0.70",
"version": "0.0.71",
"description": "A socket clinet for automata's Proof Of Machinehood",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -222,4 +222,6 @@ import {

const url = new URL(`${pomAppProtocol}://${pomAppHost}#${pomAppHash}`);
const url = new URL(`${pomAppProtocol}://${pomAppHost}`);
url.hash = pomAppHash;
if (sessionId) {

@@ -245,3 +247,3 @@ url.searchParams.set('id', sessionId);

return url.href;
return url.toString();
}

@@ -252,12 +254,2 @@

console.log(
'url',
deepLink,
url.hostname,
url.protocol,
url.search,
pomAppHost,
pomAppProtocol,
);
if (url.hostname !== pomAppHost || url.protocol !== pomAppProtocol) {

@@ -273,4 +265,2 @@ throw ERR_INVALID_DEEP_LINK;

console.log('url', url.searchParams.entries(), {id, dh, s, cu, cb});
if (

@@ -277,0 +267,0 @@ (id != null && typeof id !== 'string') ||

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet