@automata-network/pom-js-sdk
Advanced tools
Comparing version
import { POMSocket, getSocket, SocketConnectionResult } from '@automata-network/pom-socket'; | ||
import { ChainId } from '@automata-network/pom-web3'; | ||
export { ChainId } from '@automata-network/pom-web3'; | ||
@@ -28,2 +26,6 @@ declare enum POMOperation { | ||
declare enum ChainId { | ||
Ethereum = "0x1", | ||
LineaSepolia = "0xe705" | ||
} | ||
declare enum POMPlatform { | ||
@@ -122,2 +124,2 @@ Android = "android", | ||
export { type AttestDeviceOptions, type AttestDeviceResult, type ChainIdOptions, type DeepLinkQuery, ERR_GET_IDENTITY_STATUS_TIMEOUT, ERR_IDENTITY_IS_EMPTY, ERR_INVALID_DEEP_LINK, ERR_INVALID_DEEP_LINK_PARAMETERS, ERR_OPERATION_CANCELLED, ERR_SOCKET_IS_CONNECTING, type GetIdentityOnChainOptions, type GetIdentityStatusOptions, IdentityStatus, type IdentityStatusPayload, type IdentityStatusResult, type MessageResult, POMClinet, POMOperation, POMPlatform, type RenderQrcodeData, type SignMessageOptions, type SignatureOptions, type SignatureResult, decodeMessageData, encodeMessageData }; | ||
export { type AttestDeviceOptions, type AttestDeviceResult, ChainId, type ChainIdOptions, type DeepLinkQuery, ERR_GET_IDENTITY_STATUS_TIMEOUT, ERR_IDENTITY_IS_EMPTY, ERR_INVALID_DEEP_LINK, ERR_INVALID_DEEP_LINK_PARAMETERS, ERR_OPERATION_CANCELLED, ERR_SOCKET_IS_CONNECTING, type GetIdentityOnChainOptions, type GetIdentityStatusOptions, IdentityStatus, type IdentityStatusPayload, type IdentityStatusResult, type MessageResult, POMClinet, POMOperation, POMPlatform, type RenderQrcodeData, type SignMessageOptions, type SignatureOptions, type SignatureResult, decodeMessageData, encodeMessageData }; |
@@ -1,2 +0,2 @@ | ||
"use strict";var e,t,n=require("@automata-network/pom-socket"),r=require("qs"),o=require("@nuintun/qrcode"),s=require("./util.js"),i=require("@automata-network/pom-web3");exports.POMPlatform=void 0,(e=exports.POMPlatform||(exports.POMPlatform={})).Android="android",e.iOS="iOS",e.macOS="macOS",exports.IdentityStatus=void 0,(t=exports.IdentityStatus||(exports.IdentityStatus={})).None="none",t.Generated="generated",t.Registered="registered";const a="pom://pomrn.ata.network/connect",c=new Error("deep link is invalid"),d=new Error("deep link parameters is invalid"),p=new Error("socket is connecting"),u=new Error("get identity status timeout"),E=new Error("identity is empty");class S{pomSocket;constructor(...[e,t]){this.pomSocket=n.getSocket(e,t)}static generateDeepLink(e){const{sessionId:t,dhSharedPublicNumber:n,hkdfSalt:o}=e,s={id:t,dh:n,s:o};return`${a}?${r.stringify(s)}`}static parseDeepLinkQuery(e){const[t,n]=e.split("?");if(t!==a)throw c;const o=r.parse(n);if("string"!=typeof o.id||"string"!=typeof o.dh||"string"!=typeof o.s||""===o.id||""===o.dh||""===o.s)throw d;return r.parse(n)}static generateQrcode(e,t){return new o.Encoder({level:t?.level||"M"}).encode(new o.Byte(e)).toDataURL()}async sign(e){const{chainId:t,caller:r,message:o,qrcodeLevel:i,onRenderQrcode:a,onGetIdentityOnChain:c,onRegisterIdentity:d}=e;if(this.pomSocket.status===n.SocketStatus.Connecting)throw p;this.pomSocket.status===n.SocketStatus.Disconnected&&await this.connectSocketAndWait({qrcodeLevel:i,onRenderQrcode:a});const u=await this.getIdentityStatus({chainId:t}).promise;let S;if(u.status!==exports.IdentityStatus.None&&u.status!==exports.IdentityStatus.Generated||(S=await this.attestDevice({chainId:t,caller:r}).promise),u.status===exports.IdentityStatus.None||u.status===exports.IdentityStatus.Generated){if(null==S)throw E;await d(S),await s.runWithErrorRetry((()=>{const e=c({chainId:t,identity:S.identity});if(!e)throw s.ERR_NEED_RETRY;return e}))}return await this.signMessage({chainId:t,caller:r,message:o}).promise}async connectSocketAndWait(e){try{const{qrcodeLevel:t,onRenderQrcode:n}=e,r=await this.connectSocket(),o=S.generateDeepLink(r);n({deepLink:o,imageBase64:S.generateQrcode(o,t?{level:t}:void 0)}),await this.waitForConnectedEvent(),await this.waitForKeyExchangeEvent()}catch(t){if(t!==n.ERR_SESSION_IS_EXPIRED)throw t;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:t}=e;let n;return{promise:new Promise(((e,r)=>{n=s.sendMessageAndWaitForResponse({socket:this.pomSocket,op:s.POMOperation.GetIdentityStatus,data:{chainId:t},resolver:e,rejecter:r})})),cancel:n}}attestDevice(e){let t;return{promise:new Promise(((n,r)=>{t=s.sendMessageAndWaitForResponse({socket:this.pomSocket,op:s.POMOperation.AttestDevice,data:e,resolver:n,rejecter:r})})),cancel:t}}signMessage(e){let t;return{promise:new Promise(((n,r)=>{t=s.sendMessageAndWaitForResponse({socket:this.pomSocket,op:s.POMOperation.SignMessage,data:e,resolver:n,rejecter:r})})),cancel:t}}}exports.ERR_OPERATION_CANCELLED=s.ERR_OPERATION_CANCELLED,Object.defineProperty(exports,"POMOperation",{enumerable:!0,get:function(){return s.POMOperation}}),exports.decodeMessageData=s.decodeMessageData,exports.encodeMessageData=s.encodeMessageData,Object.defineProperty(exports,"ChainId",{enumerable:!0,get:function(){return i.ChainId}}),exports.ERR_GET_IDENTITY_STATUS_TIMEOUT=u,exports.ERR_IDENTITY_IS_EMPTY=E,exports.ERR_INVALID_DEEP_LINK=c,exports.ERR_INVALID_DEEP_LINK_PARAMETERS=d,exports.ERR_SOCKET_IS_CONNECTING=p,exports.POMClinet=S; | ||
"use strict";var e,t,n,r=require("@automata-network/pom-socket"),o=require("qs"),s=require("@nuintun/qrcode"),i=require("./util.js");exports.ChainId=void 0,(e=exports.ChainId||(exports.ChainId={})).Ethereum="0x1",e.LineaSepolia="0xe705",exports.POMPlatform=void 0,(t=exports.POMPlatform||(exports.POMPlatform={})).Android="android",t.iOS="iOS",t.macOS="macOS",exports.IdentityStatus=void 0,(n=exports.IdentityStatus||(exports.IdentityStatus={})).None="none",n.Generated="generated",n.Registered="registered";const a="pom://pomrn.ata.network/connect",c=new Error("deep link is invalid"),d=new Error("deep link parameters is invalid"),p=new Error("socket is connecting"),E=new Error("get identity status timeout"),u=new Error("identity is empty");class S{pomSocket;constructor(...[e,t]){this.pomSocket=r.getSocket(e,t)}static generateDeepLink(e){const{sessionId:t,dhSharedPublicNumber:n,hkdfSalt:r}=e,s={id:t,dh:n,s:r};return`${a}?${o.stringify(s)}`}static parseDeepLinkQuery(e){const[t,n]=e.split("?");if(t!==a)throw c;const r=o.parse(n);if("string"!=typeof r.id||"string"!=typeof r.dh||"string"!=typeof r.s||""===r.id||""===r.dh||""===r.s)throw d;return o.parse(n)}static generateQrcode(e,t){return new s.Encoder({level:t?.level||"M"}).encode(new s.Byte(e)).toDataURL()}async sign(e){const{chainId:t,caller:n,message:o,qrcodeLevel:s,onRenderQrcode:a,onGetIdentityOnChain:c,onRegisterIdentity:d}=e;if(this.pomSocket.status===r.SocketStatus.Connecting)throw p;this.pomSocket.status===r.SocketStatus.Disconnected&&await this.connectSocketAndWait({qrcodeLevel:s,onRenderQrcode:a});const E=await this.getIdentityStatus({chainId:t}).promise;let S;if(E.status!==exports.IdentityStatus.None&&E.status!==exports.IdentityStatus.Generated||(S=await this.attestDevice({chainId:t,caller:n}).promise),E.status===exports.IdentityStatus.None||E.status===exports.IdentityStatus.Generated){if(null==S)throw u;await d(S),await i.runWithErrorRetry((()=>{const e=c({chainId:t,identity:S.identity});if(!e)throw i.ERR_NEED_RETRY;return e}))}return await this.signMessage({chainId:t,caller:n,message:o}).promise}async connectSocketAndWait(e){try{const{qrcodeLevel:t,onRenderQrcode:n}=e,r=await this.connectSocket(),o=S.generateDeepLink(r);n({deepLink:o,imageBase64:S.generateQrcode(o,t?{level:t}:void 0)}),await this.waitForConnectedEvent(),await this.waitForKeyExchangeEvent()}catch(t){if(t!==r.ERR_SESSION_IS_EXPIRED)throw t;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:t}=e;let n;return{promise:new Promise(((e,r)=>{n=i.sendMessageAndWaitForResponse({socket:this.pomSocket,op:i.POMOperation.GetIdentityStatus,data:{chainId:t},resolver:e,rejecter:r})})),cancel:n}}attestDevice(e){let t;return{promise:new Promise(((n,r)=>{t=i.sendMessageAndWaitForResponse({socket:this.pomSocket,op:i.POMOperation.AttestDevice,data:e,resolver:n,rejecter:r})})),cancel:t}}signMessage(e){let t;return{promise:new Promise(((n,r)=>{t=i.sendMessageAndWaitForResponse({socket:this.pomSocket,op:i.POMOperation.SignMessage,data:e,resolver:n,rejecter:r})})),cancel:t}}}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.ERR_GET_IDENTITY_STATUS_TIMEOUT=E,exports.ERR_IDENTITY_IS_EMPTY=u,exports.ERR_INVALID_DEEP_LINK=c,exports.ERR_INVALID_DEEP_LINK_PARAMETERS=d,exports.ERR_SOCKET_IS_CONNECTING=p,exports.POMClinet=S; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@automata-network/pom-js-sdk", | ||
"version": "0.0.18", | ||
"version": "0.0.19", | ||
"description": "A socket clinet for automata's Proof Of Machinehood", | ||
@@ -26,3 +26,2 @@ "main": "dist/index.js", | ||
"@automata-network/pom-socket": "^0.0.5", | ||
"@automata-network/pom-web3": "^0.0.4", | ||
"@nuintun/qrcode": "^4.0.0", | ||
@@ -29,0 +28,0 @@ "qs": "^6.11.2" |
@@ -16,6 +16,3 @@ import { | ||
} from './util'; | ||
import {ChainId} from '@automata-network/pom-web3'; | ||
export {ChainId} from '@automata-network/pom-web3'; | ||
export { | ||
@@ -28,2 +25,7 @@ POMOperation, | ||
export enum ChainId { | ||
Ethereum = '0x1', | ||
LineaSepolia = '0xe705', | ||
} | ||
export enum POMPlatform { | ||
@@ -30,0 +32,0 @@ Android = 'android', |
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
40738
0.23%3
-25%614
0.66%- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed