@aeternity/aepp-sdk 13.1.0 → 13.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/aepp-sdk.browser-script.js +1 -1
- package/dist/aepp-sdk.browser-script.js.map +1 -1
- package/dist/aepp-sdk.browser.js +1 -1
- package/dist/aepp-sdk.browser.js.map +1 -1
- package/dist/aepp-sdk.js +2162 -1566
- package/dist/aepp-sdk.js.map +1 -1
- package/es/AeSdkAepp.mjs.map +1 -1
- package/es/AeSdkBase.d.ts +10 -0
- package/es/AeSdkBase.mjs +27 -0
- package/es/AeSdkBase.mjs.map +1 -1
- package/es/AeSdkMethods.mjs.map +1 -1
- package/es/AeSdkWallet.d.ts +1 -1
- package/es/AeSdkWallet.mjs +53 -20
- package/es/AeSdkWallet.mjs.map +1 -1
- package/es/Middleware.mjs.map +1 -1
- package/es/MiddlewareSubscriber.mjs +3 -3
- package/es/MiddlewareSubscriber.mjs.map +1 -1
- package/es/Node.mjs.map +1 -1
- package/es/account/Base.d.ts +44 -2
- package/es/account/Base.mjs +95 -1
- package/es/account/Base.mjs.map +1 -1
- package/es/account/Generalized.d.ts +3 -0
- package/es/account/Generalized.mjs +15 -0
- package/es/account/Generalized.mjs.map +1 -1
- package/es/account/Ledger.d.ts +3 -0
- package/es/account/Ledger.mjs +15 -0
- package/es/account/Ledger.mjs.map +1 -1
- package/es/account/LedgerFactory.mjs.map +1 -1
- package/es/account/Memory.d.ts +10 -0
- package/es/account/Memory.mjs +34 -0
- package/es/account/Memory.mjs.map +1 -1
- package/es/account/Rpc.d.ts +4 -0
- package/es/account/Rpc.mjs +29 -0
- package/es/account/Rpc.mjs.map +1 -1
- package/es/aens.mjs.map +1 -1
- package/es/aepp-wallet-communication/connection/Browser.mjs.map +1 -1
- package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs.map +1 -1
- package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs.map +1 -1
- package/es/aepp-wallet-communication/connection-proxy.mjs.map +1 -1
- package/es/aepp-wallet-communication/rpc/RpcClient.mjs.map +1 -1
- package/es/aepp-wallet-communication/rpc/types.d.ts +9 -0
- package/es/aepp-wallet-communication/rpc/types.mjs.map +1 -1
- package/es/aepp-wallet-communication/schema.d.ts +1 -0
- package/es/aepp-wallet-communication/schema.mjs +20 -19
- package/es/aepp-wallet-communication/schema.mjs.map +1 -1
- package/es/aepp-wallet-communication/wallet-detector.mjs.map +1 -1
- package/es/apis/compiler/compiler.mjs.map +1 -1
- package/es/apis/middleware/middleware.mjs.map +1 -1
- package/es/apis/middleware/models/index.mjs +340 -124
- package/es/apis/middleware/models/index.mjs.map +1 -1
- package/es/apis/node/node.mjs.map +1 -1
- package/es/chain.mjs +1 -1
- package/es/chain.mjs.map +1 -1
- package/es/channel/Base.mjs.map +1 -1
- package/es/channel/Contract.mjs.map +1 -1
- package/es/channel/Spend.mjs.map +1 -1
- package/es/channel/handlers.mjs +2 -2
- package/es/channel/handlers.mjs.map +1 -1
- package/es/channel/internal.mjs +6 -6
- package/es/channel/internal.mjs.map +1 -1
- package/es/contract/Contract.mjs +1 -1
- package/es/contract/Contract.mjs.map +1 -1
- package/es/contract/compiler/Cli.mjs.map +1 -1
- package/es/contract/compiler/Http.mjs.map +1 -1
- package/es/contract/delegation-signature.d.ts +2 -1
- package/es/contract/delegation-signature.mjs +39 -8
- package/es/contract/delegation-signature.mjs.map +1 -1
- package/es/contract/ga.mjs.map +1 -1
- package/es/oracle.mjs.map +1 -1
- package/es/spend.d.ts +2 -1
- package/es/spend.mjs +4 -2
- package/es/spend.mjs.map +1 -1
- package/es/tx/builder/constants.mjs +26 -23
- package/es/tx/builder/constants.mjs.map +1 -1
- package/es/tx/builder/field-types/abi-version.mjs.map +1 -1
- package/es/tx/builder/field-types/coin-amount.mjs.map +1 -1
- package/es/tx/builder/field-types/ct-version.mjs.map +1 -1
- package/es/tx/builder/field-types/deposit.mjs.map +1 -1
- package/es/tx/builder/field-types/entry.mjs.map +1 -1
- package/es/tx/builder/field-types/fee.mjs.map +1 -1
- package/es/tx/builder/field-types/field.mjs.map +1 -1
- package/es/tx/builder/field-types/gas-limit.mjs.map +1 -1
- package/es/tx/builder/field-types/gas-price.mjs.map +1 -1
- package/es/tx/builder/field-types/index.d.ts +28 -150
- package/es/tx/builder/field-types/index.mjs +28 -56
- package/es/tx/builder/field-types/index.mjs.map +1 -1
- package/es/tx/builder/field-types/map.mjs.map +1 -1
- package/es/tx/builder/field-types/mptree.mjs +3 -3
- package/es/tx/builder/field-types/mptree.mjs.map +1 -1
- package/es/tx/builder/field-types/name-fee.mjs.map +1 -1
- package/es/tx/builder/field-types/pointers.mjs.map +1 -1
- package/es/tx/builder/field-types/string.mjs.map +1 -1
- package/es/tx/builder/field-types/ttl.mjs.map +1 -1
- package/es/tx/builder/field-types/u-int.mjs +1 -1
- package/es/tx/builder/field-types/u-int.mjs.map +1 -1
- package/es/tx/builder/helpers.mjs.map +1 -1
- package/es/tx/builder/index.mjs.map +1 -1
- package/es/tx/builder/schema.mjs +11 -10
- package/es/tx/builder/schema.mjs.map +1 -1
- package/es/tx/execution-cost.mjs.map +1 -1
- package/es/tx/transaction-signer.mjs.map +1 -1
- package/es/tx/validator.mjs.map +1 -1
- package/es/utils/amount-formatter.mjs +7 -7
- package/es/utils/amount-formatter.mjs.map +1 -1
- package/es/utils/autorest.mjs.map +1 -1
- package/es/utils/bignumber.mjs.map +1 -1
- package/es/utils/bytes.mjs.map +1 -1
- package/es/utils/crypto.mjs.map +1 -1
- package/es/utils/encoder-types.mjs +3 -3
- package/es/utils/encoder-types.mjs.map +1 -1
- package/es/utils/encoder.mjs.map +1 -1
- package/es/utils/errors.mjs.map +1 -1
- package/es/utils/hd-wallet.mjs.map +1 -1
- package/es/utils/keystore.mjs.map +1 -1
- package/es/utils/other.mjs.map +1 -1
- package/es/utils/semver-satisfies.mjs.map +1 -1
- package/es/utils/string.mjs.map +1 -1
- package/es/utils/typed-data.mjs +0 -1
- package/es/utils/typed-data.mjs.map +1 -1
- package/package.json +35 -35
- package/src/AeSdkBase.ts +36 -0
- package/src/AeSdkWallet.ts +36 -12
- package/src/account/Base.ts +84 -3
- package/src/account/Generalized.ts +15 -0
- package/src/account/Ledger.ts +15 -0
- package/src/account/Memory.ts +53 -1
- package/src/account/Rpc.ts +35 -0
- package/src/aepp-wallet-communication/rpc/types.ts +10 -0
- package/src/aepp-wallet-communication/schema.ts +1 -0
- package/src/chain.ts +1 -1
- package/src/contract/Contract.ts +1 -1
- package/src/contract/delegation-signature.ts +37 -11
- package/src/spend.ts +2 -2
- package/src/tx/builder/field-types/index.ts +28 -58
- package/src/tx/builder/field-types/u-int.ts +1 -1
- package/types-legacy/ts4.2/AeSdkBase.d.ts +10 -0
- package/types-legacy/ts4.2/AeSdkWallet.d.ts +1 -1
- package/types-legacy/ts4.2/account/Base.d.ts +44 -2
- package/types-legacy/ts4.2/account/Generalized.d.ts +3 -0
- package/types-legacy/ts4.2/account/Ledger.d.ts +3 -0
- package/types-legacy/ts4.2/account/Memory.d.ts +10 -0
- package/types-legacy/ts4.2/account/Rpc.d.ts +4 -0
- package/types-legacy/ts4.2/aepp-wallet-communication/rpc/types.d.ts +9 -0
- package/types-legacy/ts4.2/aepp-wallet-communication/schema.d.ts +1 -0
- package/types-legacy/ts4.2/contract/delegation-signature.d.ts +2 -1
- package/types-legacy/ts4.2/spend.d.ts +2 -1
- package/types-legacy/ts4.2/tx/builder/field-types/index.d.ts +28 -153
- package/types-legacy/ts4.5/AeSdkBase.d.ts +10 -0
- package/types-legacy/ts4.5/AeSdkWallet.d.ts +1 -1
- package/types-legacy/ts4.5/account/Base.d.ts +44 -2
- package/types-legacy/ts4.5/account/Generalized.d.ts +3 -0
- package/types-legacy/ts4.5/account/Ledger.d.ts +3 -0
- package/types-legacy/ts4.5/account/Memory.d.ts +10 -0
- package/types-legacy/ts4.5/account/Rpc.d.ts +4 -0
- package/types-legacy/ts4.5/aepp-wallet-communication/rpc/types.d.ts +9 -0
- package/types-legacy/ts4.5/aepp-wallet-communication/schema.d.ts +1 -0
- package/types-legacy/ts4.5/contract/delegation-signature.d.ts +2 -1
- package/types-legacy/ts4.5/spend.d.ts +2 -1
- package/types-legacy/ts4.5/tx/builder/field-types/index.d.ts +28 -153
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Memory.mjs","names":["AccountBase","generateKeyPairFromSecret","sign","generateKeyPair","hash","messageToHash","ArgumentError","decode","encode","Encoding","concatBuffers","hashTypedData","buildTx","Tag","secretKeys","WeakMap","getBufferToSign","transaction","networkId","innerTx","prefixes","push","rlpBinaryTx","_Buffer","from","join","AccountMemory","constructor","secretKey","length","set","address","get","publicKey","AccountAddress","generate","data","options","signTransaction","arguments","undefined","txWithNetworkId","signatures","tag","SignedTx","encodedTx","signMessage","message","signTypedData","aci","name","version","contractAddress","dHash","signature","Signature"],"sources":["../../src/account/Memory.ts"],"sourcesContent":["import AccountBase from './Base';\nimport {\n generateKeyPairFromSecret, sign, generateKeyPair, hash, messageToHash,\n} from '../utils/crypto';\nimport { ArgumentError } from '../utils/errors';\nimport {\n decode, encode, Encoded, Encoding,\n} from '../utils/encoder';\nimport { concatBuffers } from '../utils/other';\nimport { hashTypedData, AciValue } from '../utils/typed-data';\nimport { buildTx } from '../tx/builder';\nimport { Tag } from '../tx/builder/constants';\n\nconst secretKeys = new WeakMap();\n\nexport function getBufferToSign(\n transaction: Encoded.Transaction,\n networkId: string,\n innerTx: boolean,\n): Uint8Array {\n const prefixes = [networkId];\n if (innerTx) prefixes.push('inner_tx');\n const rlpBinaryTx = decode(transaction);\n return concatBuffers([Buffer.from(prefixes.join('-')), hash(rlpBinaryTx)]);\n}\n\n/**\n * In-memory account class\n */\nexport default class AccountMemory extends AccountBase {\n override readonly address: Encoded.AccountAddress;\n\n /**\n * @param secretKey - Secret key\n */\n constructor(secretKey: string | Uint8Array) {\n super();\n secretKey = typeof secretKey === 'string' ? Buffer.from(secretKey, 'hex') : secretKey;\n if (secretKey.length !== 64) {\n throw new ArgumentError('secretKey', '64 bytes', secretKey.length);\n }\n secretKeys.set(this, secretKey);\n this.address = encode(\n generateKeyPairFromSecret(secretKeys.get(this)).publicKey,\n Encoding.AccountAddress,\n );\n }\n\n /**\n * Generates a new AccountMemory using a random secret key\n */\n static generate(): AccountMemory {\n return new AccountMemory(generateKeyPair().secretKey);\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n override async sign(data: string | Uint8Array, options?: any): Promise<Uint8Array> {\n return sign(data, secretKeys.get(this));\n }\n\n override async signTransaction(\n transaction: Encoded.Transaction,\n { innerTx, networkId, ...options }: { innerTx?: boolean; networkId?: string } = {},\n ): Promise<Encoded.Transaction> {\n if (networkId == null) {\n throw new ArgumentError('networkId', 'provided', networkId);\n }\n const rlpBinaryTx = decode(transaction);\n const txWithNetworkId = getBufferToSign(transaction, networkId, innerTx === true);\n\n const signatures = [await this.sign(txWithNetworkId, options)];\n return buildTx({ tag: Tag.SignedTx, encodedTx: rlpBinaryTx, signatures });\n }\n\n override async signMessage(message: string, options?: any): Promise<Uint8Array> {\n return this.sign(messageToHash(message), options);\n }\n\n override async signTypedData(\n data: Encoded.ContractBytearray,\n aci: AciValue,\n {\n name, version, networkId, contractAddress, ...options\n }: Parameters<AccountBase['signTypedData']>[2] = {},\n ): Promise<Encoded.Signature> {\n const dHash = hashTypedData(data, aci, {\n name, version, networkId, contractAddress,\n });\n const signature = await this.sign(dHash, options);\n return encode(signature, Encoding.Signature);\n }\n}\n"],"mappings":";;;;OAAOA,WAAW;AAAA,SAEhBC,yBAAyB,EAAEC,IAAI,EAAEC,eAAe,EAAEC,IAAI,EAAEC,aAAa;AAAA,SAE9DC,aAAa;AAAA,SAEpBC,MAAM,EAAEC,MAAM,EAAWC,QAAQ;AAAA,SAE1BC,aAAa;AAAA,SACbC,aAAa;AAAA,SACbC,OAAO;AAAA,SACPC,GAAG;AAEZ,MAAMC,UAAU,GAAG,IAAIC,OAAO,EAAE;AAEhC,OAA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GAAG,MAAM,IAAI,CAACpD,IAAI,CAACmD,KAAK,EAAEhB,OAAO,CAAC;IACjD,OAAO7B,MAAM,CAAC8C,SAAS,EAAE7C,QAAQ,CAAC8C,SAAS,CAAC;EAC9C;AACF"}
|
|
1
|
+
{"version":3,"file":"Memory.mjs","names":["AccountBase","generateKeyPairFromSecret","sign","generateKeyPair","hash","messageToHash","ArgumentError","decode","encode","Encoding","concatBuffers","hashTypedData","buildTx","Tag","produceNameId","secretKeys","WeakMap","getBufferToSign","transaction","networkId","innerTx","prefixes","push","rlpBinaryTx","_Buffer","from","join","AccountMemory","constructor","secretKey","length","set","address","get","publicKey","AccountAddress","generate","data","options","signTransaction","arguments","undefined","txWithNetworkId","signatures","tag","SignedTx","encodedTx","signMessage","message","signTypedData","aci","name","version","contractAddress","dHash","signature","Signature","signDelegationToContract","payload","signNameDelegationToContract","signOracleQueryDelegationToContract","oracleQueryId","oracleQueryIdDecoded","addressDecoded","compare"],"sources":["../../src/account/Memory.ts"],"sourcesContent":["import AccountBase from './Base';\nimport {\n generateKeyPairFromSecret, sign, generateKeyPair, hash, messageToHash,\n} from '../utils/crypto';\nimport { ArgumentError } from '../utils/errors';\nimport {\n decode, encode, Encoded, Encoding,\n} from '../utils/encoder';\nimport { concatBuffers } from '../utils/other';\nimport { hashTypedData, AciValue } from '../utils/typed-data';\nimport { buildTx } from '../tx/builder';\nimport { Tag, AensName } from '../tx/builder/constants';\nimport { produceNameId } from '../tx/builder/helpers';\n\nconst secretKeys = new WeakMap();\n\nexport function getBufferToSign(\n transaction: Encoded.Transaction,\n networkId: string,\n innerTx: boolean,\n): Uint8Array {\n const prefixes = [networkId];\n if (innerTx) prefixes.push('inner_tx');\n const rlpBinaryTx = decode(transaction);\n return concatBuffers([Buffer.from(prefixes.join('-')), hash(rlpBinaryTx)]);\n}\n\n/**\n * In-memory account class\n */\nexport default class AccountMemory extends AccountBase {\n override readonly address: Encoded.AccountAddress;\n\n /**\n * @param secretKey - Secret key\n */\n constructor(secretKey: string | Uint8Array) {\n super();\n secretKey = typeof secretKey === 'string' ? Buffer.from(secretKey, 'hex') : secretKey;\n if (secretKey.length !== 64) {\n throw new ArgumentError('secretKey', '64 bytes', secretKey.length);\n }\n secretKeys.set(this, secretKey);\n this.address = encode(\n generateKeyPairFromSecret(secretKeys.get(this)).publicKey,\n Encoding.AccountAddress,\n );\n }\n\n /**\n * Generates a new AccountMemory using a random secret key\n */\n static generate(): AccountMemory {\n return new AccountMemory(generateKeyPair().secretKey);\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n override async sign(data: string | Uint8Array, options?: any): Promise<Uint8Array> {\n return sign(data, secretKeys.get(this));\n }\n\n override async signTransaction(\n transaction: Encoded.Transaction,\n { innerTx, networkId, ...options }: { innerTx?: boolean; networkId?: string } = {},\n ): Promise<Encoded.Transaction> {\n if (networkId == null) {\n throw new ArgumentError('networkId', 'provided', networkId);\n }\n const rlpBinaryTx = decode(transaction);\n const txWithNetworkId = getBufferToSign(transaction, networkId, innerTx === true);\n\n const signatures = [await this.sign(txWithNetworkId, options)];\n return buildTx({ tag: Tag.SignedTx, encodedTx: rlpBinaryTx, signatures });\n }\n\n override async signMessage(message: string, options?: any): Promise<Uint8Array> {\n return this.sign(messageToHash(message), options);\n }\n\n override async signTypedData(\n data: Encoded.ContractBytearray,\n aci: AciValue,\n {\n name, version, networkId, contractAddress, ...options\n }: Parameters<AccountBase['signTypedData']>[2] = {},\n ): Promise<Encoded.Signature> {\n const dHash = hashTypedData(data, aci, {\n name, version, networkId, contractAddress,\n });\n const signature = await this.sign(dHash, options);\n return encode(signature, Encoding.Signature);\n }\n\n override async signDelegationToContract(\n contractAddress: Encoded.ContractAddress,\n { networkId }: { networkId?: string } = {},\n ): Promise<Encoded.Signature> {\n if (networkId == null) throw new ArgumentError('networkId', 'provided', networkId);\n const payload = concatBuffers([\n Buffer.from(networkId),\n decode(this.address),\n decode(contractAddress),\n ]);\n const signature = await this.sign(payload);\n return encode(signature, Encoding.Signature);\n }\n\n override async signNameDelegationToContract(\n contractAddress: Encoded.ContractAddress,\n name: AensName,\n { networkId }: { networkId?: string } = {},\n ): Promise<Encoded.Signature> {\n if (networkId == null) throw new ArgumentError('networkId', 'provided', networkId);\n const payload = concatBuffers([\n Buffer.from(networkId),\n decode(this.address),\n decode(produceNameId(name)),\n decode(contractAddress),\n ]);\n const signature = await this.sign(payload);\n return encode(signature, Encoding.Signature);\n }\n\n override async signOracleQueryDelegationToContract(\n contractAddress: Encoded.ContractAddress,\n oracleQueryId: Encoded.OracleQueryId,\n { networkId }: { networkId?: string } = {},\n ): Promise<Encoded.Signature> {\n const oracleQueryIdDecoded = decode(oracleQueryId);\n const addressDecoded = decode(this.address);\n // TODO: remove after fixing https://github.com/aeternity/aesophia/issues/475\n if (oracleQueryIdDecoded.compare(addressDecoded) === 0) {\n throw new ArgumentError('oracleQueryId', 'not equal to account address', oracleQueryId);\n }\n if (networkId == null) throw new ArgumentError('networkId', 'provided', networkId);\n const payload = concatBuffers([\n Buffer.from(networkId),\n oracleQueryIdDecoded,\n decode(contractAddress),\n ]);\n const signature = await this.sign(payload);\n return encode(signature, Encoding.Signature);\n }\n}\n"],"mappings":";;;;OAAOA,WAAW;AAAA,SAEhBC,yBAAyB,EAAEC,IAAI,EAAEC,eAAe,EAAEC,IAAI,EAAEC,aAAa;AAAA,SAE9DC,aAAa;AAAA,SAEpBC,MAAM,EAAEC,MAAM,EAAWC,QAAQ;AAAA,SAE1BC,aAAa;AAAA,SACbC,aAAa;AAAA,SACbC,OAAO;AAAA,SACPC,GAAG;AAAA,SACHC,aAAa;AAEtB,MAAMC,UAAU,GAAG,IAAIC,OAAO,CAAC,CAAC;AAEhC,OAAO,SAASC,eAAeA,CAC7BC,WAAgC,EAChCC,SAAiB,EACjBC,OAAgB,EACJ;EACZ,MAAMC,QAAQ,GAAG,CAACF,SAAS,CAAC;EAC5B,IAAIC,OAAO,EAAEC,QAAQ,CAACC,IAAI,CAAC,UAAU,CAAC;EACtC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EAEA,MAAeI,mCAAmCA,CAChDP,eAAwC,EACxCQ,aAAoC,EAER;IAAA,IAD5B;MAAE1C;IAAkC,CAAC,GAAAqB,SAAA,CAAAV,MAAA,QAAAU,SAAA,QAAAC,SAAA,GAAAD,SAAA,MAAG,CAAC,CAAC;IAE1C,MAAMsB,oBAAoB,GAAGvD,MAAM,CAACsD,aAAa,CAAC;IAClD,MAAME,cAAc,GAAGxD,MAAM,CAAC,IAAI,CAACyB,OAAO,CAAC;IAC3C;IACA,IAAI8B,oBAAoB,CAACE,OAAO,CAACD,cAAc,CAAC,KAAK,CAAC,EAAE;MACtD,MAAM,IAAIzD,aAAa,CAAC,eAAe,EAAE,8BAA8B,EAAEuD,aAAa,CAAC;IACzF;IACA,IAAI1C,SAAS,IAAI,IAAI,EAAE,MAAM,IAAIb,aAAa,CAAC,WAAW,EAAE,UAAU,EAAEa,SAAS,CAAC;IAClF,MAAMuC,OAAO,GAAGhD,aAAa,CAAC,CAC5Bc,OAAA,CAAOC,IAAI,CAACN,SAAS,CAAC,EACtB2C,oBAAoB,EACpBvD,MAAM,CAAC8C,eAAe,CAAC,CACxB,CAAC;IACF,MAAME,SAAS,GAAG,MAAM,IAAI,CAACrD,IAAI,CAACwD,OAAO,CAAC;IAC1C,OAAOlD,MAAM,CAAC+C,SAAS,EAAE9C,QAAQ,CAAC+C,SAAS,CAAC;EAC9C;AACF"}
|
package/es/account/Rpc.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import AccountBase from './Base';
|
|
|
2
2
|
import { Encoded } from '../utils/encoder';
|
|
3
3
|
import RpcClient from '../aepp-wallet-communication/rpc/RpcClient';
|
|
4
4
|
import { AeppApi, WalletApi } from '../aepp-wallet-communication/rpc/types';
|
|
5
|
+
import { AensName } from '../tx/builder/constants';
|
|
5
6
|
/**
|
|
6
7
|
* Account provided by wallet
|
|
7
8
|
* @param params - Params
|
|
@@ -17,4 +18,7 @@ export default class AccountRpc extends AccountBase {
|
|
|
17
18
|
signTransaction(tx: Encoded.Transaction, { innerTx, networkId }?: Parameters<AccountBase['signTransaction']>[1]): Promise<Encoded.Transaction>;
|
|
18
19
|
signMessage(message: string): Promise<Uint8Array>;
|
|
19
20
|
signTypedData(data: Encoded.ContractBytearray, aci: Parameters<AccountBase['signTypedData']>[1], { name, version, contractAddress, networkId, }?: Parameters<AccountBase['signTypedData']>[2]): Promise<Encoded.Signature>;
|
|
21
|
+
signDelegationToContract(contractAddress: Encoded.ContractAddress): Promise<Encoded.Signature>;
|
|
22
|
+
signNameDelegationToContract(contractAddress: Encoded.ContractAddress, name: AensName): Promise<Encoded.Signature>;
|
|
23
|
+
signOracleQueryDelegationToContract(contractAddress: Encoded.ContractAddress, oracleQueryId: Encoded.OracleQueryId): Promise<Encoded.Signature>;
|
|
20
24
|
}
|
package/es/account/Rpc.mjs
CHANGED
|
@@ -72,5 +72,34 @@ export default class AccountRpc extends AccountBase {
|
|
|
72
72
|
});
|
|
73
73
|
return signature;
|
|
74
74
|
}
|
|
75
|
+
async signDelegationToContract(contractAddress) {
|
|
76
|
+
const {
|
|
77
|
+
signature
|
|
78
|
+
} = await this._rpcClient.request(METHODS.signDelegationToContract, {
|
|
79
|
+
onAccount: this.address,
|
|
80
|
+
contractAddress
|
|
81
|
+
});
|
|
82
|
+
return signature;
|
|
83
|
+
}
|
|
84
|
+
async signNameDelegationToContract(contractAddress, name) {
|
|
85
|
+
const {
|
|
86
|
+
signature
|
|
87
|
+
} = await this._rpcClient.request(METHODS.signDelegationToContract, {
|
|
88
|
+
onAccount: this.address,
|
|
89
|
+
contractAddress,
|
|
90
|
+
name
|
|
91
|
+
});
|
|
92
|
+
return signature;
|
|
93
|
+
}
|
|
94
|
+
async signOracleQueryDelegationToContract(contractAddress, oracleQueryId) {
|
|
95
|
+
const {
|
|
96
|
+
signature
|
|
97
|
+
} = await this._rpcClient.request(METHODS.signDelegationToContract, {
|
|
98
|
+
onAccount: this.address,
|
|
99
|
+
contractAddress,
|
|
100
|
+
oracleQueryId
|
|
101
|
+
});
|
|
102
|
+
return signature;
|
|
103
|
+
}
|
|
75
104
|
}
|
|
76
105
|
//# sourceMappingURL=Rpc.mjs.map
|
package/es/account/Rpc.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Rpc.mjs","names":["AccountBase","METHODS","ArgumentError","NotImplementedError","UnsupportedProtocolError","AccountRpc","constructor","rpcClient","address","_rpcClient","sign","signTransaction","tx","innerTx","networkId","arguments","length","undefined","res","request","onAccount","returnSigned","signedTransaction","signMessage","message","signature","_Buffer","from","signTypedData","data","aci","name","version","contractAddress","domain"],"sources":["../../src/account/Rpc.ts"],"sourcesContent":["import AccountBase from './Base';\nimport { METHODS } from '../aepp-wallet-communication/schema';\nimport { ArgumentError, NotImplementedError, UnsupportedProtocolError } from '../utils/errors';\nimport { Encoded } from '../utils/encoder';\nimport RpcClient from '../aepp-wallet-communication/rpc/RpcClient';\nimport { AeppApi, WalletApi } from '../aepp-wallet-communication/rpc/types';\n\n/**\n * Account provided by wallet\n * @param params - Params\n * @param params.rpcClient - RpcClient instance\n * @param params.address - RPC account address\n * @returns AccountRpc instance\n */\nexport default class AccountRpc extends AccountBase {\n _rpcClient: RpcClient<WalletApi, AeppApi>;\n\n override readonly address: Encoded.AccountAddress;\n\n constructor(rpcClient: RpcClient<WalletApi, AeppApi>, address: Encoded.AccountAddress) {\n super();\n this._rpcClient = rpcClient;\n this.address = address;\n }\n\n // eslint-disable-next-line class-methods-use-this\n async sign(): Promise<Uint8Array> {\n throw new NotImplementedError('RAW signing using wallet');\n }\n\n override async signTransaction(\n tx: Encoded.Transaction,\n { innerTx, networkId }: Parameters<AccountBase['signTransaction']>[1] = {},\n ): Promise<Encoded.Transaction> {\n if (networkId == null) throw new ArgumentError('networkId', 'provided', networkId);\n const res = await this._rpcClient.request(METHODS.sign, {\n onAccount: this.address,\n tx,\n returnSigned: true,\n networkId,\n innerTx,\n });\n if (res.signedTransaction == null) {\n throw new UnsupportedProtocolError('signedTransaction is missed in wallet response');\n }\n return res.signedTransaction;\n }\n\n override async signMessage(message: string): Promise<Uint8Array> {\n const { signature } = await this._rpcClient\n .request(METHODS.signMessage, { onAccount: this.address, message });\n return Buffer.from(signature, 'hex');\n }\n\n override async signTypedData(\n data: Encoded.ContractBytearray,\n aci: Parameters<AccountBase['signTypedData']>[1],\n {\n name, version, contractAddress, networkId,\n }: Parameters<AccountBase['signTypedData']>[2] = {},\n ): Promise<Encoded.Signature> {\n const { signature } = await this._rpcClient.request(METHODS.signTypedData, {\n onAccount: this.address,\n domain: {\n name, version, networkId, contractAddress,\n },\n aci,\n data,\n });\n return signature;\n }\n}\n"],"mappings":";;;;OAAOA,WAAW;AAAA,SACTC,OAAO;AAAA,SACPC,aAAa,EAAEC,mBAAmB,EAAEC,wBAAwB;
|
|
1
|
+
{"version":3,"file":"Rpc.mjs","names":["AccountBase","METHODS","ArgumentError","NotImplementedError","UnsupportedProtocolError","AccountRpc","constructor","rpcClient","address","_rpcClient","sign","signTransaction","tx","innerTx","networkId","arguments","length","undefined","res","request","onAccount","returnSigned","signedTransaction","signMessage","message","signature","_Buffer","from","signTypedData","data","aci","name","version","contractAddress","domain","signDelegationToContract","signNameDelegationToContract","signOracleQueryDelegationToContract","oracleQueryId"],"sources":["../../src/account/Rpc.ts"],"sourcesContent":["import AccountBase from './Base';\nimport { METHODS } from '../aepp-wallet-communication/schema';\nimport { ArgumentError, NotImplementedError, UnsupportedProtocolError } from '../utils/errors';\nimport { Encoded } from '../utils/encoder';\nimport RpcClient from '../aepp-wallet-communication/rpc/RpcClient';\nimport { AeppApi, WalletApi } from '../aepp-wallet-communication/rpc/types';\nimport { AensName } from '../tx/builder/constants';\n\n/**\n * Account provided by wallet\n * @param params - Params\n * @param params.rpcClient - RpcClient instance\n * @param params.address - RPC account address\n * @returns AccountRpc instance\n */\nexport default class AccountRpc extends AccountBase {\n _rpcClient: RpcClient<WalletApi, AeppApi>;\n\n override readonly address: Encoded.AccountAddress;\n\n constructor(rpcClient: RpcClient<WalletApi, AeppApi>, address: Encoded.AccountAddress) {\n super();\n this._rpcClient = rpcClient;\n this.address = address;\n }\n\n // eslint-disable-next-line class-methods-use-this\n async sign(): Promise<Uint8Array> {\n throw new NotImplementedError('RAW signing using wallet');\n }\n\n override async signTransaction(\n tx: Encoded.Transaction,\n { innerTx, networkId }: Parameters<AccountBase['signTransaction']>[1] = {},\n ): Promise<Encoded.Transaction> {\n if (networkId == null) throw new ArgumentError('networkId', 'provided', networkId);\n const res = await this._rpcClient.request(METHODS.sign, {\n onAccount: this.address,\n tx,\n returnSigned: true,\n networkId,\n innerTx,\n });\n if (res.signedTransaction == null) {\n throw new UnsupportedProtocolError('signedTransaction is missed in wallet response');\n }\n return res.signedTransaction;\n }\n\n override async signMessage(message: string): Promise<Uint8Array> {\n const { signature } = await this._rpcClient\n .request(METHODS.signMessage, { onAccount: this.address, message });\n return Buffer.from(signature, 'hex');\n }\n\n override async signTypedData(\n data: Encoded.ContractBytearray,\n aci: Parameters<AccountBase['signTypedData']>[1],\n {\n name, version, contractAddress, networkId,\n }: Parameters<AccountBase['signTypedData']>[2] = {},\n ): Promise<Encoded.Signature> {\n const { signature } = await this._rpcClient.request(METHODS.signTypedData, {\n onAccount: this.address,\n domain: {\n name, version, networkId, contractAddress,\n },\n aci,\n data,\n });\n return signature;\n }\n\n override async signDelegationToContract(\n contractAddress: Encoded.ContractAddress,\n ): Promise<Encoded.Signature> {\n const { signature } = await this._rpcClient.request(METHODS.signDelegationToContract, {\n onAccount: this.address,\n contractAddress,\n });\n return signature;\n }\n\n override async signNameDelegationToContract(\n contractAddress: Encoded.ContractAddress,\n name: AensName,\n ): Promise<Encoded.Signature> {\n const { signature } = await this._rpcClient.request(METHODS.signDelegationToContract, {\n onAccount: this.address,\n contractAddress,\n name,\n });\n return signature;\n }\n\n override async signOracleQueryDelegationToContract(\n contractAddress: Encoded.ContractAddress,\n oracleQueryId: Encoded.OracleQueryId,\n ): Promise<Encoded.Signature> {\n const { signature } = await this._rpcClient.request(METHODS.signDelegationToContract, {\n onAccount: this.address,\n contractAddress,\n oracleQueryId,\n });\n return signature;\n }\n}\n"],"mappings":";;;;OAAOA,WAAW;AAAA,SACTC,OAAO;AAAA,SACPC,aAAa,EAAEC,mBAAmB,EAAEC,wBAAwB;AAMrE;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,MAAMC,UAAU,SAASL,WAAW,CAAC;EAKlDM,WAAWA,CAACC,SAAwC,EAAEC,OAA+B,EAAE;IACrF,KAAK,CAAC,CAAC;IACP,IAAI,CAACC,UAAU,GAAGF,SAAS;IAC3B,IAAI,CAACC,OAAO,GAAGA,OAAO;EACxB;;EAEA;EACA,MAAME,IAAIA,CAAA,EAAwB;IAChC,MAAM,IAAIP,mBAAmB,CAAC,0BAA0B,CAAC;EAC3D;EAEA,MAAeQ,eAAeA,CAC5BC,EAAuB,EAEO;IAAA,IAD9B;MAAEC,OAAO;MAAEC;IAAyD,CAAC,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;IAE1E,IAAID,SAAS,IAAI,IAAI,EAAE,MAAM,IAAIZ,aAAa,CAAC,WAAW,EAAE,UAAU,EAAEY,SAAS,CAAC;IAClF,MAAMI,GAAG,GAAG,MAAM,IAAI,CAACT,UAAU,CAACU,OAAO,CAAClB,OAAO,CAACS,IAAI,EAAE;MACtDU,SAAS,EAAE,IAAI,CAACZ,OAAO;MACvBI,EAAE;MACFS,YAAY,EAAE,IAAI;MAClBP,SAAS;MACTD;IACF,CAAC,CAAC;IACF,IAAIK,GAAG,CAACI,iBAAiB,IAAI,IAAI,EAAE;MACjC,MAAM,IAAIlB,wBAAwB,CAAC,gDAAgD,CAAC;IACtF;IACA,OAAOc,GAAG,CAACI,iBAAiB;EAC9B;EAEA,MAAeC,WAAWA,CAACC,OAAe,EAAuB;IAC/D,MAAM;MAAEC;IAAU,CAAC,GAAG,MAAM,IAAI,CAAChB,U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CK,aAAoC,EACR;IAC5B,MAAM;MAAEb;IAAU,CAAC,GAAG,MAAM,IAAI,CAAChB,UAAU,CAACU,OAAO,CAAClB,OAAO,CAACkC,wBAAwB,EAAE;MACpFf,SAAS,EAAE,IAAI,CAACZ,OAAO;MACvByB,eAAe;MACfK;IACF,CAAC,CAAC;IACF,OAAOb,SAAS;EAClB;AACF"}
|
package/es/aens.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aens.mjs","names":["genSalt","commitmentHash","isAuctionName","CLIENT_TTL","NAME_TTL","Tag","ArgumentError","sendTransaction","getName","buildTxAsync","aensRevoke","name","options","nameRevokeTx","tag","NameRevokeTx","nameId","accountId","onAccount","address","aensUpdate","pointers","_ref","extendPointers","allPointers","Object","fromEntries","map","_ref2","key","id","nameUpdateTx","clientTtl","nameTtl","NameUpdateTx","entries","_ref3","aensTransfer","account","nameTransferTx","NameTransferTx","recipientId","aensQuery","opt","nameEntry","freeze","owner","update","transfer","revoke","extendTtl","arguments","length","undefined","aensClaim","salt","claimTx","NameClaimTx","nameSalt","result","nameInter","blockHeight","assign","aensPreclaim","commitmentId","preclaimTx","NamePreclaimTx","claim","opts","version","otherOptions","aensBid","nameFee"],"sources":["../src/aens.ts"],"sourcesContent":["/**\n * Aens methods - routines to interact with the æternity naming system\n *\n * The high-level description of the naming system is\n * https://github.com/aeternity/protocol/blob/master/AENS.md in the protocol\n * repository.\n */\n\nimport BigNumber from 'bignumber.js';\nimport { genSalt } from './utils/crypto';\nimport { commitmentHash, isAuctionName } from './tx/builder/helpers';\nimport {\n CLIENT_TTL, NAME_TTL, Tag, AensName,\n} from './tx/builder/constants';\nimport { ArgumentError } from './utils/errors';\nimport { Encoded } from './utils/encoder';\nimport { sendTransaction, SendTransactionOptions, getName } from './chain';\nimport { buildTxAsync, BuildTxOptions } from './tx/builder';\nimport { TransformNodeType } from './Node';\nimport { NameEntry, NamePointer } from './apis/node';\nimport AccountBase from './account/Base';\nimport { AddressEncodings } from './tx/builder/field-types/address';\n\ninterface KeyPointers {\n [key: string]: Encoded.Generic<AddressEncodings>;\n}\n\n/**\n * Revoke a name\n * @category AENS\n * @param name - Name hash\n * @param options - Options\n * @param options.onAccount - Make operation on specific account from sdk (you pass\n * publickKey) or using provided KeyPair(Can be keypair object or MemoryAccount)\n * @param options.fee - fee\n * @param options.ttl - ttl\n * @param options.nonce - nonce\n * @returns Transaction result\n * @example\n * ```js\n * const name = 'test.chain'\n * const nameObject = await sdkInstance.aensQuery(name)\n *\n * await sdkInstance.aensRevoke(name, { fee, ttl , nonce })\n * // or\n * await nameObject.revoke({ fee, ttl, nonce })\n * ```\n */\nexport async function aensRevoke(\n name: AensName,\n options: AensRevokeOptions,\n): ReturnType<typeof sendTransaction> {\n const nameRevokeTx = await buildTxAsync({\n ...options,\n tag: Tag.NameRevokeTx,\n nameId: name,\n accountId: options.onAccount.address,\n });\n return sendTransaction(nameRevokeTx, options);\n}\n\ninterface AensRevokeOptions extends\n BuildTxOptions<Tag.NameRevokeTx, 'nameId' | 'accountId' | 'onNode'>,\n SendTransactionOptions {}\n\n/**\n * Update a name\n * @category AENS\n * @param name - AENS name\n * @param pointers - Map of pointer keys to corresponding addresses\n * @param options - Options\n * @param options.extendPointers - Get the pointers from the node and merge with provided\n * ones. Pointers with the same type will be overwritten\n * @param options.onAccount - Make operation on specific account from sdk (you\n * pass publickKey) or using provided KeyPair(Can be keypair object or MemoryAccount)\n * @param options.fee - fee\n * @param options.ttl - ttl\n * @param options.nonce - nonce\n * @param options.nameTtl - Name ttl represented in number of\n * blocks (Max value is 50000 blocks)\n * @param options.clientTtl=84600 a suggestion as to how long any\n * clients should cache this information\n * @throws Invalid pointer array error\n * @example\n * ```js\n * const name = 'test.chain'\n * const pointersArray = ['ak_asd23dasdas...,' 'ct_asdf34fasdasd...']\n * const nameObject = await sdkInstance.aensQuery(name)\n *\n * await sdkInstance.aensUpdate(name, pointersArray, { nameTtl, ttl, fee, nonce, clientTtl })\n * // or\n * await nameObject.update(pointers, { nameTtl, ttl, fee, nonce, clientTtl })\n * ```\n */\nexport async function aensUpdate(\n name: AensName,\n pointers: KeyPointers,\n { extendPointers, ...options }: AensUpdateOptions,\n): ReturnType<typeof sendTransaction> {\n const allPointers = {\n ...extendPointers === true && Object.fromEntries(\n (await getName(name, options)).pointers.map(({ key, id }) => [key, id]),\n ),\n ...pointers,\n };\n\n const nameUpdateTx = await buildTxAsync({\n clientTtl: CLIENT_TTL,\n nameTtl: NAME_TTL,\n ...options,\n tag: Tag.NameUpdateTx,\n nameId: name,\n accountId: options.onAccount.address,\n pointers: Object.entries(allPointers)\n .map(([key, id]: [string, Encoded.Generic<AddressEncodings>]) => ({ key, id })),\n });\n\n return sendTransaction(nameUpdateTx, options);\n}\n\ninterface AensUpdateOptions extends\n BuildTxOptions<Tag.NameUpdateTx, 'nameId' | 'accountId' | 'pointers' | 'clientTtl' | 'nameTtl' | 'onNode'>,\n SendTransactionOptions {\n extendPointers?: boolean;\n clientTtl?: number;\n nameTtl?: number;\n}\n\n/**\n * Transfer a domain to another account\n * @category AENS\n * @param name - AENS name\n * @param account - Recipient account publick key\n * @param options - Options\n * @param options.onAccount - Make operation on specific account from sdk (you pass\n * publickKey) or using provided KeyPair(Can be keypair object or MemoryAccount)\n * @param options.fee - fee\n * @param options.ttl - ttl\n * @param options.nonce - nonce\n * @returns Transaction result\n * @example\n * ```js\n * const name = 'test.chain'\n * const recipientPub = 'ak_asd23dasdas...'\n * const nameObject = await sdkInstance.aensQuery(name)\n *\n * await sdkInstance.aensTransfer(name, recipientPub, { ttl, fee, nonce })\n * // or\n * await nameObject.transfer(recipientPub, { ttl, fee, nonce })\n * ```\n */\nexport async function aensTransfer(\n name: AensName,\n account: Encoded.AccountAddress,\n options: AensTransferOptions,\n): ReturnType<typeof sendTransaction> {\n const nameTransferTx = await buildTxAsync({\n ...options,\n tag: Tag.NameTransferTx,\n nameId: name,\n accountId: options.onAccount.address,\n recipientId: account,\n });\n\n return sendTransaction(nameTransferTx, options);\n}\n\ninterface AensTransferOptions extends\n BuildTxOptions<Tag.NameTransferTx, 'nameId' | 'accountId' | 'recipientId' | 'onNode'>,\n SendTransactionOptions {}\n\n/**\n * Query the AENS name info from the node\n * and return the object with info and predefined functions for manipulating name\n * @category AENS\n * @param name - AENS name\n * @param opt - Options\n * @returns\n * @example\n * ```js\n * const nameObject = sdkInstance.aensQuery('test.chain')\n * console.log(nameObject)\n * {\n * id, // name hash\n * pointers, // array of pointers\n * update, // Update name function\n * extendTtl, // Extend Ttl name function\n * transfer, // Transfer name function\n * revoke // Revoke name function\n * }\n * ```\n */\nexport async function aensQuery(\n name: AensName,\n opt: Parameters<typeof getName>[1] & Parameters<typeof aensUpdate>[2]\n & Parameters<typeof aensTransfer>[2],\n): Promise<Readonly<\n TransformNodeType<NameEntry> & {\n id: Encoded.Name;\n owner: Encoded.AccountAddress;\n pointers: KeyPointers | NamePointer[];\n ttl: number;\n update: (\n pointers: KeyPointers,\n options?: Omit<Parameters<typeof aensQuery>[1], 'onNode' | 'onCompiler' | 'onAccount'> & {\n onAccount?: AccountBase;\n }\n ) => ReturnType<typeof aensUpdate> & ReturnType<typeof aensQuery>;\n transfer: (\n account: Encoded.AccountAddress,\n options?: Parameters<typeof aensQuery>[1]\n ) => ReturnType<typeof aensUpdate> & ReturnType<typeof aensQuery>;\n revoke: (options?: Omit<Parameters<typeof aensRevoke>[1], 'onNode' | 'onCompiler' | 'onAccount'> & {\n onAccount?: AccountBase;\n }\n ) => ReturnType<typeof aensRevoke>;\n extendTtl: (\n nameTtl: number,\n options?: Omit<Parameters<typeof aensQuery>[1], 'onNode' | 'onCompiler' | 'onAccount'>\n ) => ReturnType<typeof aensUpdate> & ReturnType<typeof aensQuery>;\n }\n >> {\n const nameEntry = await getName(name, opt);\n return Object.freeze({\n ...nameEntry,\n id: nameEntry.id as Encoded.Name,\n owner: nameEntry.owner as Encoded.AccountAddress,\n async update(pointers, options) {\n return {\n ...await aensUpdate(name, pointers, { ...opt, ...options }),\n ...await aensQuery(name, { ...opt, ...options }),\n };\n },\n async transfer(account, options) {\n return {\n ...await aensTransfer(name, account, { ...opt, ...options }),\n ...await aensQuery(name, { ...opt, ...options }),\n };\n },\n async revoke(options) {\n return aensRevoke(name, { ...opt, ...options });\n },\n async extendTtl(nameTtl = NAME_TTL, options = {}) {\n if (nameTtl > NAME_TTL || nameTtl <= 0) {\n throw new ArgumentError('nameTtl', `a number between 1 and ${NAME_TTL} blocks`, nameTtl);\n }\n\n return {\n ...await aensUpdate(name, {}, {\n ...opt, ...options, nameTtl, extendPointers: true,\n }),\n ...await aensQuery(name, { ...opt, ...options }),\n };\n },\n });\n}\n\n/**\n * Claim a previously preclaimed registration. This can only be done after the\n * preclaim step\n * @category AENS\n * @param name - AENS name\n * @param salt - Salt from pre-claim, or 0 if it's a bid\n * @param options - options\n * @param options.onAccount - Make operation on specific account from sdk (you pass\n * publickKey) or using provided KeyPair(Can be keypair object or MemoryAccount)\n * @param options.fee - fee\n * @param options.ttl - ttl\n * @param options.nonce - nonce\n * @param options.nameFee - Name Fee (By default calculated by sdk)\n * @returns the result of the claim\n * @example\n * ```js\n * const name = 'test.chain'\n * const salt = preclaimResult.salt // salt from pre-claim transaction\n *\n * await sdkInstance.aensClaim(name, salt, { ttl, fee, nonce, nameFee })\n * ```\n */\nexport async function aensClaim(\n name: AensName,\n salt: number,\n options: AensClaimOptions,\n): Promise<AensClaimReturnType> {\n const claimTx = await buildTxAsync({\n ...options,\n tag: Tag.NameClaimTx,\n accountId: options.onAccount.address,\n nameSalt: salt,\n name,\n });\n\n const result = await sendTransaction(claimTx, options);\n if (!isAuctionName(name)) {\n const nameInter = result.blockHeight != null && result.blockHeight > 0\n ? await aensQuery(name, options)\n : {};\n return Object.assign(result, nameInter);\n }\n return result;\n}\n\ntype AensClaimOptionsType = BuildTxOptions<Tag.NameClaimTx, 'accountId' | 'nameSalt' | 'name'>\n& SendTransactionOptions & Parameters<typeof aensQuery>[1];\ninterface AensClaimOptions extends AensClaimOptionsType {}\ninterface AensClaimReturnType extends\n Awaited<ReturnType<typeof sendTransaction>>,\n Partial<Awaited<ReturnType<typeof aensQuery>>> {}\n\n/**\n * Preclaim a name. Sends a hash of the name and a random salt to the node\n * @category AENS\n * @param name - AENS name\n * @param options - Options\n * @param options.onAccount - Make operation on specific account from sdk (you pass\n * publickKey) or using provided KeyPair(Can be keypair object or MemoryAccount)\n * @param options.fee - fee\n * @param options.ttl - ttl\n * @param options.nonce - nonce\n * @example\n * ```js\n * const name = 'test.chain'\n * const salt = preclaimResult.salt // salt from pre-claim transaction\n *\n * await sdkInstance.aensPreclaim(name, { ttl, fee, nonce })\n * {\n * ...transactionResult,\n * claim, // Claim function (options={}) => claimTransactionResult\n * salt,\n * commitmentId\n * }\n * ```\n */\nexport async function aensPreclaim(name: AensName, options: AensPreclaimOptions): Promise<Readonly<\nAwaited<ReturnType<typeof sendTransaction>> & {\n salt: number;\n commitmentId: string;\n claim: (opts?: Parameters<typeof aensClaim>[2]) => ReturnType<typeof aensClaim>;\n}\n>> {\n const salt = genSalt();\n const commitmentId = commitmentHash(name, salt);\n\n const preclaimTx = await buildTxAsync({\n ...options,\n tag: Tag.NamePreclaimTx,\n accountId: options.onAccount.address,\n commitmentId,\n });\n\n return Object.freeze({\n ...await sendTransaction(preclaimTx, options),\n salt,\n commitmentId,\n async claim(opts?: Parameters<typeof aensClaim>[2]) {\n const { version, ...otherOptions } = options;\n return aensClaim(name, salt, { ...otherOptions, ...opts });\n },\n });\n}\n\ninterface AensPreclaimOptions extends\n BuildTxOptions<Tag.NamePreclaimTx, 'accountId' | 'commitmentId' | 'onNode'>,\n SendTransactionOptions,\n Omit<AensClaimOptions, 'version'> {}\n\n/**\n * Bid to name auction\n * @category AENS\n * @param name - Domain name\n * @param nameFee - Name fee (bid fee)\n * @param options - Options\n * @param options.onAccount - Make operation on specific account from sdk (you pass\n * publickKey) or using provided KeyPair(Can be keypair object or MemoryAccount)\n * @param options.fee - fee\n * @param options.ttl - ttl\n * @param options.nonce - nonce\n * @returns Transaction result\n * @example\n * ```js\n * const name = 'test.chain'\n * const bidFee = computeBidFee(name, { startFee, increment: 0.42 })\n *\n * await sdkInstance.aensBid(name, 213109412839123, { ttl, fee, nonce })\n * ```\n */\nexport async function aensBid(\n name: AensName,\n nameFee: number | string | BigNumber,\n options: Omit<Parameters<typeof aensClaim>[2], 'nameFee'>,\n): ReturnType<typeof aensClaim> {\n return aensClaim(name, 0, { ...options, nameFee });\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AANA,SASSA,OAAO;AAAA,SACPC,cAAc,EAAEC,aAAa;AAAA,SAEpCC,UAAU,EAAEC,QAAQ,EAAEC,GAAG;AAAA,SAElBC,aAAa;AAAA,SAEbC,eAAe,EAA0BC,OAAO;AAAA,SAChDC,YAAY;AAUrB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeC,UAAUA,CAC9BC,IAAc,EACdC,OAA0B,EACU;EACpC,MAAMC,YAAY,GAAG,MAAMJ,YAAY,CAAC;IACtC,GAAGG,OAAO;IACVE,GAAG,EAAET,GAAG,CAACU,YAAY;IACrBC,MAAM,EAAEL,IAAI;IACZM,SAAS,EAAEL,OAAO,CAACM,SAAS,CAACC;EAC/B,CAAC,CAAC;EACF,OAAOZ,eAAe,CAACM,YAAY,EAAED,OAAO,CAAC;AAC/C;AAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeQ,UAAUA,CAC9BT,IAAc,EACdU,QAAqB,EAAAC,IAAA,EAEe;EAAA,IADpC;IAAEC,cAAc;IAAE,GAAGX;EAA2B,CAAC,GAAAU,IAAA;EAEjD,MAAME,WAAW,GAAG;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CAAC3C,IAAI,EAAE,CAAC,EAAE;IAAE,GAAGC,OAAO;IAAE4D;EAAQ,CAAC,CAAC;AACpD"}
|
|
1
|
+
{"version":3,"file":"aens.mjs","names":["genSalt","commitmentHash","isAuctionName","CLIENT_TTL","NAME_TTL","Tag","ArgumentError","sendTransaction","getName","buildTxAsync","aensRevoke","name","options","nameRevokeTx","tag","NameRevokeTx","nameId","accountId","onAccount","address","aensUpdate","pointers","_ref","extendPointers","allPointers","Object","fromEntries","map","_ref2","key","id","nameUpdateTx","clientTtl","nameTtl","NameUpdateTx","entries","_ref3","aensTransfer","account","nameTransferTx","NameTransferTx","recipientId","aensQuery","opt","nameEntry","freeze","owner","update","transfer","revoke","extendTtl","arguments","length","undefined","aensClaim","salt","claimTx","NameClaimTx","nameSalt","result","nameInter","blockHeight","assign","aensPreclaim","commitmentId","preclaimTx","NamePreclaimTx","claim","opts","version","otherOptions","aensBid","nameFee"],"sources":["../src/aens.ts"],"sourcesContent":["/**\n * Aens methods - routines to interact with the æternity naming system\n *\n * The high-level description of the naming system is\n * https://github.com/aeternity/protocol/blob/master/AENS.md in the protocol\n * repository.\n */\n\nimport BigNumber from 'bignumber.js';\nimport { genSalt } from './utils/crypto';\nimport { commitmentHash, isAuctionName } from './tx/builder/helpers';\nimport {\n CLIENT_TTL, NAME_TTL, Tag, AensName,\n} from './tx/builder/constants';\nimport { ArgumentError } from './utils/errors';\nimport { Encoded } from './utils/encoder';\nimport { sendTransaction, SendTransactionOptions, getName } from './chain';\nimport { buildTxAsync, BuildTxOptions } from './tx/builder';\nimport { TransformNodeType } from './Node';\nimport { NameEntry, NamePointer } from './apis/node';\nimport AccountBase from './account/Base';\nimport { AddressEncodings } from './tx/builder/field-types/address';\n\ninterface KeyPointers {\n [key: string]: Encoded.Generic<AddressEncodings>;\n}\n\n/**\n * Revoke a name\n * @category AENS\n * @param name - Name hash\n * @param options - Options\n * @param options.onAccount - Make operation on specific account from sdk (you pass\n * publickKey) or using provided KeyPair(Can be keypair object or MemoryAccount)\n * @param options.fee - fee\n * @param options.ttl - ttl\n * @param options.nonce - nonce\n * @returns Transaction result\n * @example\n * ```js\n * const name = 'test.chain'\n * const nameObject = await sdkInstance.aensQuery(name)\n *\n * await sdkInstance.aensRevoke(name, { fee, ttl , nonce })\n * // or\n * await nameObject.revoke({ fee, ttl, nonce })\n * ```\n */\nexport async function aensRevoke(\n name: AensName,\n options: AensRevokeOptions,\n): ReturnType<typeof sendTransaction> {\n const nameRevokeTx = await buildTxAsync({\n ...options,\n tag: Tag.NameRevokeTx,\n nameId: name,\n accountId: options.onAccount.address,\n });\n return sendTransaction(nameRevokeTx, options);\n}\n\ninterface AensRevokeOptions extends\n BuildTxOptions<Tag.NameRevokeTx, 'nameId' | 'accountId' | 'onNode'>,\n SendTransactionOptions {}\n\n/**\n * Update a name\n * @category AENS\n * @param name - AENS name\n * @param pointers - Map of pointer keys to corresponding addresses\n * @param options - Options\n * @param options.extendPointers - Get the pointers from the node and merge with provided\n * ones. Pointers with the same type will be overwritten\n * @param options.onAccount - Make operation on specific account from sdk (you\n * pass publickKey) or using provided KeyPair(Can be keypair object or MemoryAccount)\n * @param options.fee - fee\n * @param options.ttl - ttl\n * @param options.nonce - nonce\n * @param options.nameTtl - Name ttl represented in number of\n * blocks (Max value is 50000 blocks)\n * @param options.clientTtl=84600 a suggestion as to how long any\n * clients should cache this information\n * @throws Invalid pointer array error\n * @example\n * ```js\n * const name = 'test.chain'\n * const pointersArray = ['ak_asd23dasdas...,' 'ct_asdf34fasdasd...']\n * const nameObject = await sdkInstance.aensQuery(name)\n *\n * await sdkInstance.aensUpdate(name, pointersArray, { nameTtl, ttl, fee, nonce, clientTtl })\n * // or\n * await nameObject.update(pointers, { nameTtl, ttl, fee, nonce, clientTtl })\n * ```\n */\nexport async function aensUpdate(\n name: AensName,\n pointers: KeyPointers,\n { extendPointers, ...options }: AensUpdateOptions,\n): ReturnType<typeof sendTransaction> {\n const allPointers = {\n ...extendPointers === true && Object.fromEntries(\n (await getName(name, options)).pointers.map(({ key, id }) => [key, id]),\n ),\n ...pointers,\n };\n\n const nameUpdateTx = await buildTxAsync({\n clientTtl: CLIENT_TTL,\n nameTtl: NAME_TTL,\n ...options,\n tag: Tag.NameUpdateTx,\n nameId: name,\n accountId: options.onAccount.address,\n pointers: Object.entries(allPointers)\n .map(([key, id]: [string, Encoded.Generic<AddressEncodings>]) => ({ key, id })),\n });\n\n return sendTransaction(nameUpdateTx, options);\n}\n\ninterface AensUpdateOptions extends\n BuildTxOptions<Tag.NameUpdateTx, 'nameId' | 'accountId' | 'pointers' | 'clientTtl' | 'nameTtl' | 'onNode'>,\n SendTransactionOptions {\n extendPointers?: boolean;\n clientTtl?: number;\n nameTtl?: number;\n}\n\n/**\n * Transfer a domain to another account\n * @category AENS\n * @param name - AENS name\n * @param account - Recipient account publick key\n * @param options - Options\n * @param options.onAccount - Make operation on specific account from sdk (you pass\n * publickKey) or using provided KeyPair(Can be keypair object or MemoryAccount)\n * @param options.fee - fee\n * @param options.ttl - ttl\n * @param options.nonce - nonce\n * @returns Transaction result\n * @example\n * ```js\n * const name = 'test.chain'\n * const recipientPub = 'ak_asd23dasdas...'\n * const nameObject = await sdkInstance.aensQuery(name)\n *\n * await sdkInstance.aensTransfer(name, recipientPub, { ttl, fee, nonce })\n * // or\n * await nameObject.transfer(recipientPub, { ttl, fee, nonce })\n * ```\n */\nexport async function aensTransfer(\n name: AensName,\n account: Encoded.AccountAddress,\n options: AensTransferOptions,\n): ReturnType<typeof sendTransaction> {\n const nameTransferTx = await buildTxAsync({\n ...options,\n tag: Tag.NameTransferTx,\n nameId: name,\n accountId: options.onAccount.address,\n recipientId: account,\n });\n\n return sendTransaction(nameTransferTx, options);\n}\n\ninterface AensTransferOptions extends\n BuildTxOptions<Tag.NameTransferTx, 'nameId' | 'accountId' | 'recipientId' | 'onNode'>,\n SendTransactionOptions {}\n\n/**\n * Query the AENS name info from the node\n * and return the object with info and predefined functions for manipulating name\n * @category AENS\n * @param name - AENS name\n * @param opt - Options\n * @returns\n * @example\n * ```js\n * const nameObject = sdkInstance.aensQuery('test.chain')\n * console.log(nameObject)\n * {\n * id, // name hash\n * pointers, // array of pointers\n * update, // Update name function\n * extendTtl, // Extend Ttl name function\n * transfer, // Transfer name function\n * revoke // Revoke name function\n * }\n * ```\n */\nexport async function aensQuery(\n name: AensName,\n opt: Parameters<typeof getName>[1] & Parameters<typeof aensUpdate>[2]\n & Parameters<typeof aensTransfer>[2],\n): Promise<Readonly<\n TransformNodeType<NameEntry> & {\n id: Encoded.Name;\n owner: Encoded.AccountAddress;\n pointers: KeyPointers | NamePointer[];\n ttl: number;\n update: (\n pointers: KeyPointers,\n options?: Omit<Parameters<typeof aensQuery>[1], 'onNode' | 'onCompiler' | 'onAccount'> & {\n onAccount?: AccountBase;\n }\n ) => ReturnType<typeof aensUpdate> & ReturnType<typeof aensQuery>;\n transfer: (\n account: Encoded.AccountAddress,\n options?: Parameters<typeof aensQuery>[1]\n ) => ReturnType<typeof aensUpdate> & ReturnType<typeof aensQuery>;\n revoke: (options?: Omit<Parameters<typeof aensRevoke>[1], 'onNode' | 'onCompiler' | 'onAccount'> & {\n onAccount?: AccountBase;\n }\n ) => ReturnType<typeof aensRevoke>;\n extendTtl: (\n nameTtl: number,\n options?: Omit<Parameters<typeof aensQuery>[1], 'onNode' | 'onCompiler' | 'onAccount'>\n ) => ReturnType<typeof aensUpdate> & ReturnType<typeof aensQuery>;\n }\n >> {\n const nameEntry = await getName(name, opt);\n return Object.freeze({\n ...nameEntry,\n id: nameEntry.id as Encoded.Name,\n owner: nameEntry.owner as Encoded.AccountAddress,\n async update(pointers, options) {\n return {\n ...await aensUpdate(name, pointers, { ...opt, ...options }),\n ...await aensQuery(name, { ...opt, ...options }),\n };\n },\n async transfer(account, options) {\n return {\n ...await aensTransfer(name, account, { ...opt, ...options }),\n ...await aensQuery(name, { ...opt, ...options }),\n };\n },\n async revoke(options) {\n return aensRevoke(name, { ...opt, ...options });\n },\n async extendTtl(nameTtl = NAME_TTL, options = {}) {\n if (nameTtl > NAME_TTL || nameTtl <= 0) {\n throw new ArgumentError('nameTtl', `a number between 1 and ${NAME_TTL} blocks`, nameTtl);\n }\n\n return {\n ...await aensUpdate(name, {}, {\n ...opt, ...options, nameTtl, extendPointers: true,\n }),\n ...await aensQuery(name, { ...opt, ...options }),\n };\n },\n });\n}\n\n/**\n * Claim a previously preclaimed registration. This can only be done after the\n * preclaim step\n * @category AENS\n * @param name - AENS name\n * @param salt - Salt from pre-claim, or 0 if it's a bid\n * @param options - options\n * @param options.onAccount - Make operation on specific account from sdk (you pass\n * publickKey) or using provided KeyPair(Can be keypair object or MemoryAccount)\n * @param options.fee - fee\n * @param options.ttl - ttl\n * @param options.nonce - nonce\n * @param options.nameFee - Name Fee (By default calculated by sdk)\n * @returns the result of the claim\n * @example\n * ```js\n * const name = 'test.chain'\n * const salt = preclaimResult.salt // salt from pre-claim transaction\n *\n * await sdkInstance.aensClaim(name, salt, { ttl, fee, nonce, nameFee })\n * ```\n */\nexport async function aensClaim(\n name: AensName,\n salt: number,\n options: AensClaimOptions,\n): Promise<AensClaimReturnType> {\n const claimTx = await buildTxAsync({\n ...options,\n tag: Tag.NameClaimTx,\n accountId: options.onAccount.address,\n nameSalt: salt,\n name,\n });\n\n const result = await sendTransaction(claimTx, options);\n if (!isAuctionName(name)) {\n const nameInter = result.blockHeight != null && result.blockHeight > 0\n ? await aensQuery(name, options)\n : {};\n return Object.assign(result, nameInter);\n }\n return result;\n}\n\ntype AensClaimOptionsType = BuildTxOptions<Tag.NameClaimTx, 'accountId' | 'nameSalt' | 'name'>\n& SendTransactionOptions & Parameters<typeof aensQuery>[1];\ninterface AensClaimOptions extends AensClaimOptionsType {}\ninterface AensClaimReturnType extends\n Awaited<ReturnType<typeof sendTransaction>>,\n Partial<Awaited<ReturnType<typeof aensQuery>>> {}\n\n/**\n * Preclaim a name. Sends a hash of the name and a random salt to the node\n * @category AENS\n * @param name - AENS name\n * @param options - Options\n * @param options.onAccount - Make operation on specific account from sdk (you pass\n * publickKey) or using provided KeyPair(Can be keypair object or MemoryAccount)\n * @param options.fee - fee\n * @param options.ttl - ttl\n * @param options.nonce - nonce\n * @example\n * ```js\n * const name = 'test.chain'\n * const salt = preclaimResult.salt // salt from pre-claim transaction\n *\n * await sdkInstance.aensPreclaim(name, { ttl, fee, nonce })\n * {\n * ...transactionResult,\n * claim, // Claim function (options={}) => claimTransactionResult\n * salt,\n * commitmentId\n * }\n * ```\n */\nexport async function aensPreclaim(name: AensName, options: AensPreclaimOptions): Promise<Readonly<\nAwaited<ReturnType<typeof sendTransaction>> & {\n salt: number;\n commitmentId: string;\n claim: (opts?: Parameters<typeof aensClaim>[2]) => ReturnType<typeof aensClaim>;\n}\n>> {\n const salt = genSalt();\n const commitmentId = commitmentHash(name, salt);\n\n const preclaimTx = await buildTxAsync({\n ...options,\n tag: Tag.NamePreclaimTx,\n accountId: options.onAccount.address,\n commitmentId,\n });\n\n return Object.freeze({\n ...await sendTransaction(preclaimTx, options),\n salt,\n commitmentId,\n async claim(opts?: Parameters<typeof aensClaim>[2]) {\n const { version, ...otherOptions } = options;\n return aensClaim(name, salt, { ...otherOptions, ...opts });\n },\n });\n}\n\ninterface AensPreclaimOptions extends\n BuildTxOptions<Tag.NamePreclaimTx, 'accountId' | 'commitmentId' | 'onNode'>,\n SendTransactionOptions,\n Omit<AensClaimOptions, 'version'> {}\n\n/**\n * Bid to name auction\n * @category AENS\n * @param name - Domain name\n * @param nameFee - Name fee (bid fee)\n * @param options - Options\n * @param options.onAccount - Make operation on specific account from sdk (you pass\n * publickKey) or using provided KeyPair(Can be keypair object or MemoryAccount)\n * @param options.fee - fee\n * @param options.ttl - ttl\n * @param options.nonce - nonce\n * @returns Transaction result\n * @example\n * ```js\n * const name = 'test.chain'\n * const bidFee = computeBidFee(name, { startFee, increment: 0.42 })\n *\n * await sdkInstance.aensBid(name, 213109412839123, { ttl, fee, nonce })\n * ```\n */\nexport async function aensBid(\n name: AensName,\n nameFee: number | string | BigNumber,\n options: Omit<Parameters<typeof aensClaim>[2], 'nameFee'>,\n): ReturnType<typeof aensClaim> {\n return aensClaim(name, 0, { ...options, nameFee });\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AANA,SASSA,OAAO;AAAA,SACPC,cAAc,EAAEC,aAAa;AAAA,SAEpCC,UAAU,EAAEC,QAAQ,EAAEC,GAAG;AAAA,SAElBC,aAAa;AAAA,SAEbC,eAAe,EAA0BC,OAAO;AAAA,SAChDC,YAAY;AAUrB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeC,UAAUA,CAC9BC,IAAc,EACdC,OAA0B,EACU;EACpC,MAAMC,YAAY,GAAG,MAAMJ,YAAY,CAAC;IACtC,GAAGG,OAAO;IACVE,GAAG,EAAET,GAAG,CAACU,YAAY;IACrBC,MAAM,EAAEL,IAAI;IACZM,SAAS,EAAEL,OAAO,CAACM,SAAS,CAACC;EAC/B,CAAC,CAAC;EACF,OAAOZ,eAAe,CAACM,YAAY,EAAED,OAAO,CAAC;AAC/C;AAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeQ,UAAUA,CAC9BT,IAAc,EACdU,QAAqB,EAAAC,IAAA,EAEe;EAAA,IADpC;IAAEC,cAAc;IAAE,GAAGX;EAA2B,CAAC,GAAAU,IAAA;EAEjD,MAAME,WAAW,GAAG;IAClB,IAAGD,cAAc,KAAK,IAAI,IAAIE,MAAM,CAACC,WAAW,CAC9C,CAAC,MAAMlB,OAAO,CAACG,IAAI,EAAEC,OAAO,CAAC,EAAES,QAAQ,CAACM,GAAG,CAACC,KAAA;MAAA,IAAC;QAAEC,GAAG;QAAEC;MAA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,MAAM;AACf;AASA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeI,YAAYA,CAACpD,IAAc,EAAEC,OAA4B,EAM5E;EACD,MAAM2C,IAAI,GAAGvD,OAAO,CAAC,CAAC;EACtB,MAAMgE,YAAY,GAAG/D,cAAc,CAACU,IAAI,EAAE4C,IAAI,CAAC;EAE/C,MAAMU,UAAU,GAAG,MAAMxD,YAAY,CAAC;IACpC,GAAGG,OAAO;IACVE,GAAG,EAAET,GAAG,CAAC6D,cAAc;IACvBjD,SAAS,EAAEL,OAAO,CAACM,SAAS,CAACC,OAAO;IACpC6C;EACF,CAAC,CAAC;EAEF,OAAOvC,MAAM,CAACoB,MAAM,CAAC;IACnB,IAAG,MAAMtC,eAAe,CAAC0D,UAAU,EAAErD,OAAO,CAAC;IAC7C2C,IAAI;IACJS,YAAY;IACZ,MAAMG,KAAKA,CAACC,IAAsC,EAAE;MAClD,MAAM;QAAEC,OAAO;QAAE,GAAGC;MAAa,CAAC,GAAG1D,OAAO;MAC5C,OAAO0C,SAAS,CAAC3C,IAAI,EAAE4C,IAAI,EAAE;QAAE,GAAGe,YAAY;QAAE,GAAGF;MAAK,CAAC,CAAC;IAC5D;EACF,CAAC,CAAC;AACJ;AAOA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeG,OAAOA,CAC3B5D,IAAc,EACd6D,OAAoC,EACpC5D,OAAyD,EAC3B;EAC9B,OAAO0C,SAAS,CAAC3C,IAAI,EAAE,CAAC,EAAE;IAAE,GAAGC,OAAO;IAAE4D;EAAQ,CAAC,CAAC;AACpD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Browser.mjs","names":["AlreadyConnectedError","NoWalletConnectedError","BrowserConnection","constructor","_ref","debug","connect","onMessage","onDisconnect","isConnected","disconnect","receiveMessage","message","console","log","sendMessage"],"sources":["../../../src/aepp-wallet-communication/connection/Browser.ts"],"sourcesContent":["import { AlreadyConnectedError, NoWalletConnectedError } from '../../utils/errors';\n\n/**\n * Browser connection base interface\n * @category aepp wallet communication\n */\nexport default abstract class BrowserConnection {\n debug: boolean;\n\n protected constructor({ debug = false }: { debug?: boolean }) {\n this.debug = debug;\n }\n\n /**\n * Connect\n * @param onMessage - Message handler\n * @param onDisconnect - trigger when runtime connection in closed\n */\n connect(\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n onMessage: (message: any, origin: string, source: any) => void,\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n onDisconnect: () => void,\n ): void {\n if (this.isConnected()) throw new AlreadyConnectedError('You already connected');\n }\n\n /**\n * Disconnect\n */\n disconnect(): void {\n if (!this.isConnected()) throw new NoWalletConnectedError('You dont have connection. Please connect before');\n }\n\n /**\n * Receive message\n */\n protected receiveMessage(message: any): void {\n if (this.debug) console.log('Receive message:', message);\n }\n\n /**\n * Send message\n */\n sendMessage(message: any): void {\n if (this.debug) console.log('Send message:', message);\n }\n\n /**\n * Check if connected\n * @returns Is connected\n */\n abstract isConnected(): boolean;\n}\n"],"mappings":"SAASA,qBAAqB,EAAEC,sBAAsB;AAEtD;AACA;AACA;AACA;AACA,eAAe,MAAeC,iBAAiB,CAAC;EAGpCC,WAAWA,CAAAC,IAAA,EAAyC;IAAA,IAAxC;MAAEC,KAAK,GAAG;IAA2B,CAAC,GAAAD,IAAA;IAC1D,IAAI,CAACC,KAAK,GAAGA,KAAK;EACpB;;EAEA;AACF;AACA;AACA;AACA;EACEC,OAAOA;EACL;EACAC,SAA8D;EAC9D;EACAC,YAAwB,EAClB;IACN,IAAI,IAAI,CAACC,WAAW,
|
|
1
|
+
{"version":3,"file":"Browser.mjs","names":["AlreadyConnectedError","NoWalletConnectedError","BrowserConnection","constructor","_ref","debug","connect","onMessage","onDisconnect","isConnected","disconnect","receiveMessage","message","console","log","sendMessage"],"sources":["../../../src/aepp-wallet-communication/connection/Browser.ts"],"sourcesContent":["import { AlreadyConnectedError, NoWalletConnectedError } from '../../utils/errors';\n\n/**\n * Browser connection base interface\n * @category aepp wallet communication\n */\nexport default abstract class BrowserConnection {\n debug: boolean;\n\n protected constructor({ debug = false }: { debug?: boolean }) {\n this.debug = debug;\n }\n\n /**\n * Connect\n * @param onMessage - Message handler\n * @param onDisconnect - trigger when runtime connection in closed\n */\n connect(\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n onMessage: (message: any, origin: string, source: any) => void,\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n onDisconnect: () => void,\n ): void {\n if (this.isConnected()) throw new AlreadyConnectedError('You already connected');\n }\n\n /**\n * Disconnect\n */\n disconnect(): void {\n if (!this.isConnected()) throw new NoWalletConnectedError('You dont have connection. Please connect before');\n }\n\n /**\n * Receive message\n */\n protected receiveMessage(message: any): void {\n if (this.debug) console.log('Receive message:', message);\n }\n\n /**\n * Send message\n */\n sendMessage(message: any): void {\n if (this.debug) console.log('Send message:', message);\n }\n\n /**\n * Check if connected\n * @returns Is connected\n */\n abstract isConnected(): boolean;\n}\n"],"mappings":"SAASA,qBAAqB,EAAEC,sBAAsB;AAEtD;AACA;AACA;AACA;AACA,eAAe,MAAeC,iBAAiB,CAAC;EAGpCC,WAAWA,CAAAC,IAAA,EAAyC;IAAA,IAAxC;MAAEC,KAAK,GAAG;IAA2B,CAAC,GAAAD,IAAA;IAC1D,IAAI,CAACC,KAAK,GAAGA,KAAK;EACpB;;EAEA;AACF;AACA;AACA;AACA;EACEC,OAAOA;EACL;EACAC,SAA8D;EAC9D;EACAC,YAAwB,EAClB;IACN,IAAI,IAAI,CAACC,WAAW,CAAC,CAAC,EAAE,MAAM,IAAIT,qBAAqB,CAAC,uBAAuB,CAAC;EAClF;;EAEA;AACF;AACA;EACEU,UAAUA,CAAA,EAAS;IACjB,IAAI,CAAC,IAAI,CAACD,WAAW,CAAC,CAAC,EAAE,MAAM,IAAIR,sBAAsB,CAAC,iDAAiD,CAAC;EAC9G;;EAEA;AACF;AACA;EACYU,cAAcA,CAACC,OAAY,EAAQ;IAC3C,IAAI,IAAI,CAACP,KAAK,EAAEQ,OAAO,CAACC,GAAG,CAAC,kBAAkB,EAAEF,OAAO,CAAC;EAC1D;;EAEA;AACF;AACA;EACEG,WAAWA,CAACH,OAAY,EAAQ;IAC9B,IAAI,IAAI,CAACP,KAAK,EAAEQ,OAAO,CAACC,GAAG,CAAC,eAAe,EAAEF,OAAO,CAAC;EACvD;;EAEA;AACF;AACA;AACA;AAEA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BrowserRuntime.mjs","names":["BrowserConnection","UnexpectedTsError","_listeners","WeakMap","BrowserRuntimeConnection","constructor","_ref","port","options","_classPrivateFieldInitSpec","writable","value","disconnect","_classPrivateFieldGet","onMessage","removeListener","onDisconnect","_classPrivateFieldSet","undefined","connect","message","_port$sender$url","_port$sender","receiveMessage","sender","url","addListener","sendMessage","postMessage","isConnected"],"sources":["../../../src/aepp-wallet-communication/connection/BrowserRuntime.ts"],"sourcesContent":["import { Runtime } from 'webextension-polyfill';\nimport BrowserConnection from './Browser';\nimport { UnexpectedTsError } from '../../utils/errors';\n\n/**\n * BrowserRuntimeConnection\n * Handle browser runtime communication\n * @category aepp wallet communication\n */\nexport default class BrowserRuntimeConnection extends BrowserConnection {\n port: Runtime.Port;\n\n #listeners?: [(message: any, port: Runtime.Port) => void, () => void];\n\n constructor({ port, ...options }: { port: Runtime.Port; debug: boolean }) {\n super(options);\n this.port = port;\n }\n\n override disconnect(): void {\n super.disconnect();\n this.port.disconnect();\n if (this.#listeners == null) throw new UnexpectedTsError();\n this.port.onMessage.removeListener(this.#listeners[0]);\n this.port.onDisconnect.removeListener(this.#listeners[1]);\n this.#listeners = undefined;\n }\n\n override connect(\n onMessage: (message: any, origin: string, source: Runtime.Port) => void,\n onDisconnect: () => void,\n ): void {\n super.connect(onMessage, onDisconnect);\n this.#listeners = [\n (message, port) => {\n this.receiveMessage(message);\n // TODO: make `origin` optional because sender url is not available on aepp side\n onMessage(message, port.sender?.url ?? '', port);\n },\n onDisconnect,\n ];\n this.port.onMessage.addListener(this.#listeners[0]);\n this.port.onDisconnect.addListener(this.#listeners[1]);\n }\n\n override sendMessage(message: any): void {\n super.sendMessage(message);\n this.port.postMessage(message);\n }\n\n isConnected(): boolean {\n return this.#listeners != null;\n }\n}\n"],"mappings":";;;;OACOA,iBAAiB;AAAA,SACfC,iBAAiB;AAE1B;AACA;AACA;AACA;AACA;AAJA,IAAAC,UAAA,oBAAAC,OAAA;AAKA,eAAe,MAAMC,wBAAwB,SAASJ,iBAAiB,CAAC;EAKtEK,WAAWA,CAAAC,IAAA,EAA+D;IAAA,IAA9D;MAAEC,IAAI;MAAE,GAAGC;IAAgD,CAAC,GAAAF,IAAA;IACtE,KAAK,CAACE,OAAO,CAAC;IAACC,0BAAA,OAAAP,UAAA;MAAAQ,QAAA;MAAAC,KAAA;IAAA;IACf,IAAI,CAACJ,IAAI,GAAGA,IAAI;EAClB;EAESK,UAAUA,CAAA,EAAS;IAC1B,KAAK,CAACA,UAAU,
|
|
1
|
+
{"version":3,"file":"BrowserRuntime.mjs","names":["BrowserConnection","UnexpectedTsError","_listeners","WeakMap","BrowserRuntimeConnection","constructor","_ref","port","options","_classPrivateFieldInitSpec","writable","value","disconnect","_classPrivateFieldGet","onMessage","removeListener","onDisconnect","_classPrivateFieldSet","undefined","connect","message","_port$sender$url","_port$sender","receiveMessage","sender","url","addListener","sendMessage","postMessage","isConnected"],"sources":["../../../src/aepp-wallet-communication/connection/BrowserRuntime.ts"],"sourcesContent":["import { Runtime } from 'webextension-polyfill';\nimport BrowserConnection from './Browser';\nimport { UnexpectedTsError } from '../../utils/errors';\n\n/**\n * BrowserRuntimeConnection\n * Handle browser runtime communication\n * @category aepp wallet communication\n */\nexport default class BrowserRuntimeConnection extends BrowserConnection {\n port: Runtime.Port;\n\n #listeners?: [(message: any, port: Runtime.Port) => void, () => void];\n\n constructor({ port, ...options }: { port: Runtime.Port; debug: boolean }) {\n super(options);\n this.port = port;\n }\n\n override disconnect(): void {\n super.disconnect();\n this.port.disconnect();\n if (this.#listeners == null) throw new UnexpectedTsError();\n this.port.onMessage.removeListener(this.#listeners[0]);\n this.port.onDisconnect.removeListener(this.#listeners[1]);\n this.#listeners = undefined;\n }\n\n override connect(\n onMessage: (message: any, origin: string, source: Runtime.Port) => void,\n onDisconnect: () => void,\n ): void {\n super.connect(onMessage, onDisconnect);\n this.#listeners = [\n (message, port) => {\n this.receiveMessage(message);\n // TODO: make `origin` optional because sender url is not available on aepp side\n onMessage(message, port.sender?.url ?? '', port);\n },\n onDisconnect,\n ];\n this.port.onMessage.addListener(this.#listeners[0]);\n this.port.onDisconnect.addListener(this.#listeners[1]);\n }\n\n override sendMessage(message: any): void {\n super.sendMessage(message);\n this.port.postMessage(message);\n }\n\n isConnected(): boolean {\n return this.#listeners != null;\n }\n}\n"],"mappings":";;;;OACOA,iBAAiB;AAAA,SACfC,iBAAiB;AAE1B;AACA;AACA;AACA;AACA;AAJA,IAAAC,UAAA,oBAAAC,OAAA;AAKA,eAAe,MAAMC,wBAAwB,SAASJ,iBAAiB,CAAC;EAKtEK,WAAWA,CAAAC,IAAA,EAA+D;IAAA,IAA9D;MAAEC,IAAI;MAAE,GAAGC;IAAgD,CAAC,GAAAF,IAAA;IACtE,KAAK,CAACE,OAAO,CAAC;IAACC,0BAAA,OAAAP,UAAA;MAAAQ,QAAA;MAAAC,KAAA;IAAA;IACf,IAAI,CAACJ,IAAI,GAAGA,IAAI;EAClB;EAESK,UAAUA,CAAA,EAAS;IAC1B,KAAK,CAACA,UAAU,CAAC,CAAC;IAClB,IAAI,CAACL,IAAI,CAACK,UAAU,CAAC,CAAC;IACtB,IAAIC,qBAAA,KAAI,EAAAX,UAAA,KAAe,IAAI,EAAE,MAAM,IAAID,iBAAiB,CAAC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file":"BrowserWindowMessage.mjs","names":["BrowserConnection","MESSAGE_DIRECTION","InternalError","RpcConnectionError","_onDisconnect","WeakMap","_target","_self","BrowserWindowMessageConnection","constructor","target","self","window","origin","sendDirection","receiveDirection","to_aepp","options","arguments","length","undefined","_classPrivateFieldInitSpec","writable","value","_classPrivateFieldSet","isConnected","listener","connect","onMessage","onDisconnect","message","_message$data$jsonrpc","_message$data$data","data","jsonrpc","_classPrivateFieldGet","source","receiveMessage","type","addEventListener","disconnect","removeEventListener","call","sendMessage","msg","_this$origin","postMessage"],"sources":["../../../src/aepp-wallet-communication/connection/BrowserWindowMessage.ts"],"sourcesContent":["import BrowserConnection from './Browser';\nimport { MESSAGE_DIRECTION } from '../schema';\nimport { InternalError, RpcConnectionError } from '../../utils/errors';\n\nexport type ImplPostMessage = Pick<Window, 'addEventListener' | 'removeEventListener' | 'postMessage'>;\n\n/**\n * Browser window Post Message connector module\n * @category aepp wallet communication\n */\nexport default class BrowserWindowMessageConnection extends BrowserConnection {\n origin?: string;\n\n sendDirection?: MESSAGE_DIRECTION;\n\n receiveDirection: MESSAGE_DIRECTION;\n\n listener?: (this: Window, ev: MessageEvent<any>) => void;\n\n #onDisconnect?: () => void;\n\n #target?: ImplPostMessage;\n\n #self: ImplPostMessage;\n\n /**\n * @param options - Options\n * @param options.target Target window for message\n * @param options.self Host window for message\n * @param options.origin Origin of receiver\n * @param options.sendDirection Wrapping messages into additional struct\n * `({ type: 'to_aepp' || 'to_waellet', data })`\n * Used for handling messages between content script and page\n * @param options.receiveDirection Unwrapping messages from additional struct\n */\n constructor({\n target,\n self = window,\n origin,\n sendDirection,\n receiveDirection = MESSAGE_DIRECTION.to_aepp,\n ...options\n }: {\n target?: ImplPostMessage;\n self?: ImplPostMessage;\n origin?: string;\n sendDirection?: MESSAGE_DIRECTION;\n receiveDirection?: MESSAGE_DIRECTION;\n debug?: boolean;\n } = {}) {\n super(options);\n this.#target = target;\n this.#self = self;\n this.origin = origin;\n this.sendDirection = sendDirection;\n this.receiveDirection = receiveDirection;\n }\n\n isConnected(): boolean {\n return this.listener != null;\n }\n\n override connect(\n onMessage: (message: any, origin: string, source: MessageEventSource | null) => void,\n onDisconnect: () => void,\n ): void {\n super.connect(onMessage, onDisconnect);\n this.listener = (message: MessageEvent<any>) => {\n // TODO: strict validate origin and source instead of checking message structure\n if (\n typeof message.data !== 'object'\n || (message.data.jsonrpc ?? message.data.data?.jsonrpc) !== '2.0'\n ) return;\n if (this.origin != null && this.origin !== message.origin) return;\n if (this.#target != null && this.#target !== message.source) return;\n this.receiveMessage(message);\n let { data } = message;\n if (data.type != null) {\n if (message.data.type !== this.receiveDirection) return;\n data = data.data;\n }\n onMessage(data, message.origin, message.source);\n };\n this.#self.addEventListener('message', this.listener);\n this.#onDisconnect = onDisconnect;\n }\n\n override disconnect(): void {\n super.disconnect();\n if (this.listener == null || this.#onDisconnect == null) {\n throw new InternalError('Expected to not happen, required for TS');\n }\n this.#self.removeEventListener('message', this.listener);\n delete this.listener;\n this.#onDisconnect();\n this.#onDisconnect = undefined;\n }\n\n override sendMessage(msg: any): void {\n if (this.#target == null) throw new RpcConnectionError('Can\\'t send messages without target');\n const message = this.sendDirection != null ? { type: this.sendDirection, data: msg } : msg;\n super.sendMessage(message);\n this.#target.postMessage(message, this.origin ?? '*');\n }\n}\n"],"mappings":";;;;OAAOA,iBAAiB;AAAA,SACfC,iBAAiB;AAAA,SACjBC,aAAa,EAAEC,kBAAkB;AAAA,IAAAC,aAAA,oBAAAC,OAAA;AAAA,IAAAC,OAAA,oBAAAD,OAAA;AAAA,IAAAE,KAAA,oBAAAF,OAAA;AAI1C;AACA;AACA;AACA;AACA,eAAe,MAAMG,8BAA8B,SAASR,iBAAiB,CAAC;EAe5E;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACES,WAAWA,CAAA,EAcH;IAAA,IAdI;MACVC,MAAM;MACNC,IAAI,GAAGC,MAAM;MACbC,MAAM;MACNC,aAAa;MACbC,gBAAgB,G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IAAI,IAAI6B,qBAAA,KAAI,EAAA7B,OAAA,MAAawB,OAAO,CAACM,MAAM,EAAE;MAC7D,IAAI,CAACC,cAAc,CAACP,OAAO,CAAC;MAC5B,IAAI;QAAEG;MAAK,CAAC,GAAGH,OAAO;MACtB,IAAIG,IAAI,CAACK,IAAI,IAAI,IAAI,EAAE;QACrB,IAAIR,OAAO,CAACG,IAAI,CAACK,IAAI,KAAK,IAAI,CAACvB,gBAAgB,EAAE;QACjDkB,IAAI,GAAGA,IAAI,CAACA,IAAI;MAClB;MACAL,SAAS,CAACK,IAAI,EAAEH,OAAO,CAACjB,MAAM,EAAEiB,OAAO,CAACM,MAAM,CAAC;IACjD,CAAC;IACDD,qBAAA,KAAI,EAAA5B,KAAA,EAAOgC,gBAAgB,CAAC,SAAS,EAAE,IAAI,CAACb,QAAQ,CAAC;IACrDF,qBAAA,KAAI,EAAApB,aAAA,EAAiByB,YAAY;EACnC;EAESW,UAAUA,CAAA,EAAS;IAC1B,KAAK,CAACA,UAAU,
|
|
1
|
+
{"version":3,"file":"BrowserWindowMessage.mjs","names":["BrowserConnection","MESSAGE_DIRECTION","InternalError","RpcConnectionError","_onDisconnect","WeakMap","_target","_self","BrowserWindowMessageConnection","constructor","target","self","window","origin","sendDirection","receiveDirection","to_aepp","options","arguments","length","undefined","_classPrivateFieldInitSpec","writable","value","_classPrivateFieldSet","isConnected","listener","connect","onMessage","onDisconnect","message","_message$data$jsonrpc","_message$data$data","data","jsonrpc","_classPrivateFieldGet","source","receiveMessage","type","addEventListener","disconnect","removeEventListener","call","sendMessage","msg","_this$origin","postMessage"],"sources":["../../../src/aepp-wallet-communication/connection/BrowserWindowMessage.ts"],"sourcesContent":["import BrowserConnection from './Browser';\nimport { MESSAGE_DIRECTION } from '../schema';\nimport { InternalError, RpcConnectionError } from '../../utils/errors';\n\nexport type ImplPostMessage = Pick<Window, 'addEventListener' | 'removeEventListener' | 'postMessage'>;\n\n/**\n * Browser window Post Message connector module\n * @category aepp wallet communication\n */\nexport default class BrowserWindowMessageConnection extends BrowserConnection {\n origin?: string;\n\n sendDirection?: MESSAGE_DIRECTION;\n\n receiveDirection: MESSAGE_DIRECTION;\n\n listener?: (this: Window, ev: MessageEvent<any>) => void;\n\n #onDisconnect?: () => void;\n\n #target?: ImplPostMessage;\n\n #self: ImplPostMessage;\n\n /**\n * @param options - Options\n * @param options.target Target window for message\n * @param options.self Host window for message\n * @param options.origin Origin of receiver\n * @param options.sendDirection Wrapping messages into additional struct\n * `({ type: 'to_aepp' || 'to_waellet', data })`\n * Used for handling messages between content script and page\n * @param options.receiveDirection Unwrapping messages from additional struct\n */\n constructor({\n target,\n self = window,\n origin,\n sendDirection,\n receiveDirection = MESSAGE_DIRECTION.to_aepp,\n ...options\n }: {\n target?: ImplPostMessage;\n self?: ImplPostMessage;\n origin?: string;\n sendDirection?: MESSAGE_DIRECTION;\n receiveDirection?: MESSAGE_DIRECTION;\n debug?: boolean;\n } = {}) {\n super(options);\n this.#target = target;\n this.#self = self;\n this.origin = origin;\n this.sendDirection = sendDirection;\n this.receiveDirection = receiveDirection;\n }\n\n isConnected(): boolean {\n return this.listener != null;\n }\n\n override connect(\n onMessage: (message: any, origin: string, source: MessageEventSource | null) => void,\n onDisconnect: () => void,\n ): void {\n super.connect(onMessage, onDisconnect);\n this.listener = (message: MessageEvent<any>) => {\n // TODO: strict validate origin and source instead of checking message structure\n if (\n typeof message.data !== 'object'\n || (message.data.jsonrpc ?? message.data.data?.jsonrpc) !== '2.0'\n ) return;\n if (this.origin != null && this.origin !== message.origin) return;\n if (this.#target != null && this.#target !== message.source) return;\n this.receiveMessage(message);\n let { data } = message;\n if (data.type != null) {\n if (message.data.type !== this.receiveDirection) return;\n data = data.data;\n }\n onMessage(data, message.origin, message.source);\n };\n this.#self.addEventListener('message', this.listener);\n this.#onDisconnect = onDisconnect;\n }\n\n override disconnect(): void {\n super.disconnect();\n if (this.listener == null || this.#onDisconnect == null) {\n throw new InternalError('Expected to not happen, required for TS');\n }\n this.#self.removeEventListener('message', this.listener);\n delete this.listener;\n this.#onDisconnect();\n this.#onDisconnect = undefined;\n }\n\n override sendMessage(msg: any): void {\n if (this.#target == null) throw new RpcConnectionError('Can\\'t send messages without target');\n const message = this.sendDirection != null ? { type: this.sendDirection, data: msg } : msg;\n super.sendMessage(message);\n this.#target.postMessage(message, this.origin ?? '*');\n }\n}\n"],"mappings":";;;;OAAOA,iBAAiB;AAAA,SACfC,iBAAiB;AAAA,SACjBC,aAAa,EAAEC,kBAAkB;AAAA,IAAAC,aAAA,oBAAAC,OAAA;AAAA,IAAAC,OAAA,oBAAAD,OAAA;AAAA,IAAAE,KAAA,oBAAAF,OAAA;AAI1C;AACA;AACA;AACA;AACA,eAAe,MAAMG,8BAA8B,SAASR,iBAAiB,CAAC;EAe5E;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACES,WAAWA,CAAA,EAcH;IAAA,IAdI;MACVC,MAAM;MACNC,IAAI,GAAGC,MAAM;MACbC,MAAM;MACNC,aAAa;MACbC,gBAAgB,GAAGd,iBAAiB,CAACe,OAAO;MAC5C,GAAGC;IAQL,CAAC,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;IACJ,KAAK,CAACD,OAAO,CAAC;IAACI,0BAAA,OAAAjB,aAAA;MAAAkB,QAAA;MAAAC,KAAA;IAAA;IAAAF,0BAAA,OAAAf,OAAA;MAAAgB,QAAA;MAAAC,KAAA;IAAA;IAAAF,0BAAA,OAAAd,KAAA;MAAAe,QAAA;MAAAC,KAAA;IAAA;IACfC,qBAAA,KAAI,EAAAlB,OAAA,EAAWI,MAAM;IACrBc,qBAAA,KAAI,EAAAjB,KAAA,EAASI,IAAI;IACjB,IAAI,CAACE,MAAM,GAAGA,MAAM;IACpB,IAAI,CAACC,aAAa,GAAGA,aAAa;IAClC,IAAI,CAACC,gBAAgB,GAAGA,gBAAgB;EAC1C;EAEAU,WAAWA,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,UAAUA,CAAA,EAAS;IAC1B,KAAK,CAACA,UAAU,CAAC,CAAC;IAClB,IAAI,IAAI,CAACd,QAAQ,IAAI,IAAI,IAAIS,qBAAA,KAAI,EAAA/B,aAAA,KAAkB,IAAI,EAAE;MACvD,MAAM,IAAIF,aAAa,CAAC,yCAAyC,CAAC;IACpE;IACAiC,qBAAA,KAAI,EAAA5B,KAAA,EAAOkC,mBAAmB,CAAC,SAAS,EAAE,IAAI,CAACf,QAAQ,CAAC;IACxD,OAAO,IAAI,CAACA,QAAQ;IACpBS,qBAAA,KAAI,EAAA/B,aAAA,EAAAsC,IAAA,CAAJ,IAAI;IACJlB,qBAAA,KAAI,EAAApB,aAAA,EAAiBgB,SAAS;EAChC;EAESuB,WAAWA,CAACC,GAAQ,EAAQ;IAAA,IAAAC,YAAA;IACnC,IAAIV,qBAAA,KAAI,EAAA7B,OAAA,KAAY,IAAI,EAAE,MAAM,IAAIH,kBAAkB,CAAC,qCAAqC,CAAC;IAC7F,MAAM2B,OAAO,GAAG,IAAI,CAAChB,aAAa,IAAI,IAAI,GAAG;MAAEwB,IAAI,EAAE,IAAI,CAACxB,aAAa;MAAEmB,IAAI,EAAEW;IAAI,CAAC,GAAGA,GAAG;IAC1F,KAAK,CAACD,WAAW,CAACb,OAAO,CAAC;IAC1BK,qBAAA,KAAI,EAAA7B,OAAA,EAASwC,WAAW,CAAChB,OAAO,GAAAe,YAAA,GAAE,IAAI,CAAChC,MAAM,cAAAgC,YAAA,cAAAA,YAAA,GAAI,GAAG,CAAC;EACvD;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection-proxy.mjs","names":["con1","con2","connect","msg","sendMessage","disconnect"],"sources":["../../src/aepp-wallet-communication/connection-proxy.ts"],"sourcesContent":["import BrowserConnection from './connection/Browser';\n\n/**\n * Browser connection proxy\n * Provide functionality to easily forward messages from one connection to another and back\n * @category aepp wallet communication\n * @param con1 - first connection\n * @param con2 - second connection\n * @returns a function to stop proxying\n */\nexport default (con1: BrowserConnection, con2: BrowserConnection): () => void => {\n con1.connect((msg: any) => con2.sendMessage(msg), () => con2.disconnect());\n con2.connect((msg: any) => con1.sendMessage(msg), () => con1.disconnect());\n\n return () => {\n con1.disconnect();\n con2.disconnect();\n };\n};\n"],"mappings":"AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,gBAAe,CAACA,IAAuB,EAAEC,IAAuB,KAAiB;EAC/ED,IAAI,CAACE,OAAO,CAAEC,GAAQ,IAAKF,IAAI,CAACG,WAAW,CAACD,GAAG,CAAC,EAAE,MAAMF,IAAI,CAACI,UAAU,
|
|
1
|
+
{"version":3,"file":"connection-proxy.mjs","names":["con1","con2","connect","msg","sendMessage","disconnect"],"sources":["../../src/aepp-wallet-communication/connection-proxy.ts"],"sourcesContent":["import BrowserConnection from './connection/Browser';\n\n/**\n * Browser connection proxy\n * Provide functionality to easily forward messages from one connection to another and back\n * @category aepp wallet communication\n * @param con1 - first connection\n * @param con2 - second connection\n * @returns a function to stop proxying\n */\nexport default (con1: BrowserConnection, con2: BrowserConnection): () => void => {\n con1.connect((msg: any) => con2.sendMessage(msg), () => con2.disconnect());\n con2.connect((msg: any) => con1.sendMessage(msg), () => con1.disconnect());\n\n return () => {\n con1.disconnect();\n con2.disconnect();\n };\n};\n"],"mappings":"AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,gBAAe,CAACA,IAAuB,EAAEC,IAAuB,KAAiB;EAC/ED,IAAI,CAACE,OAAO,CAAEC,GAAQ,IAAKF,IAAI,CAACG,WAAW,CAACD,GAAG,CAAC,EAAE,MAAMF,IAAI,CAACI,UAAU,CAAC,CAAC,CAAC;EAC1EJ,IAAI,CAACC,OAAO,CAAEC,GAAQ,IAAKH,IAAI,CAACI,WAAW,CAACD,GAAG,CAAC,EAAE,MAAMH,IAAI,CAACK,UAAU,CAAC,CAAC,CAAC;EAE1E,OAAO,MAAM;IACXL,IAAI,CAACK,UAAU,CAAC,CAAC;IACjBJ,IAAI,CAACI,UAAU,CAAC,CAAC;EACnB,CAAC;AACH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RpcClient.mjs","names":["RpcError","RpcInternalError","RpcMethodNotFoundError","InvalidRpcMessageError","MissingCallbackError","ensureError","_callbacks","WeakMap","_messageId","_methods","_handleMessage","WeakSet","_sendRequest","_sendResponse","_processResponse","RpcClient","constructor","connection","onDisconnect","methods","_classPrivateMethodInitSpec","_classPrivateFieldInitSpec","writable","value","Map","_classPrivateFieldSet","connect","_classPrivateMethodGet","_handleMessage2","bind","request","name","params","_sendRequest2","call","_classPrivateFieldGet","Promise","resolve","reject","set","notify","undefined","msg","origin","jsonrpc","JSON","stringify","_processResponse2","result","error","method","methodName","e","id","_sendResponse2","sendMessage","toJSON","_ref","callbacks","get","deserialize","delete"],"sources":["../../../src/aepp-wallet-communication/rpc/RpcClient.ts"],"sourcesContent":["import { RpcError, RpcInternalError, RpcMethodNotFoundError } from '../schema';\nimport BrowserConnection from '../connection/Browser';\nimport { InvalidRpcMessageError, MissingCallbackError } from '../../utils/errors';\nimport { ensureError } from '../../utils/other';\n\ninterface JsonRpcRequest {\n jsonrpc: '2.0';\n id: number;\n method: string;\n params?: any;\n}\n\ninterface JsonRpcResponse {\n jsonrpc: '2.0';\n id: number;\n method: string;\n result?: any;\n error?: {\n code: number;\n message: string;\n data?: any;\n };\n}\n\ntype RpcApiHandler = (p?: any) => any | undefined;\ntype RpcApi<Api> = { [k in keyof Api]: RpcApiHandler };\ntype WithOrigin<Api extends RpcApi<Api>> = {\n [k in keyof Api]: (p: Parameters<Api[k]>[0], origin: string) => ReturnType<Api[k]>\n};\n\n/**\n * Contain functionality for using RPC conection\n * @category aepp wallet communication\n * @param connection - Connection object\n * @param onDisconnect - Disconnect callback\n * @param methods - Object containing handlers for each request by name\n */\nexport default class RpcClient <\n RemoteApi extends RpcApi<RemoteApi>, LocalApi extends RpcApi<LocalApi>,\n> {\n connection: BrowserConnection;\n\n #callbacks = new Map<number, { resolve: (v: any) => void; reject: (e: Error) => void }>();\n\n #messageId = 0;\n\n #methods: WithOrigin<LocalApi>;\n\n constructor(\n connection: BrowserConnection,\n onDisconnect: () => void,\n methods: WithOrigin<LocalApi>,\n ) {\n this.connection = connection;\n this.#methods = methods;\n connection.connect(this.#handleMessage.bind(this), onDisconnect);\n }\n\n async #handleMessage(msg: JsonRpcRequest | JsonRpcResponse, origin: string): Promise<void> {\n if (msg?.jsonrpc !== '2.0') throw new InvalidRpcMessageError(JSON.stringify(msg));\n if ('result' in msg || 'error' in msg) {\n this.#processResponse(msg);\n return;\n }\n\n const request = msg as JsonRpcRequest;\n let result;\n let error: Error | undefined;\n try {\n if (!(request.method in this.#methods)) throw new RpcMethodNotFoundError();\n const methodName = request.method as keyof LocalApi;\n result = await this.#methods[methodName](request.params, origin);\n } catch (e) {\n ensureError(e);\n error = e;\n }\n if (request.id != null) {\n this.#sendResponse(\n request.id,\n request.method as keyof LocalApi,\n result,\n error == null || error instanceof RpcError ? error : new RpcInternalError(),\n );\n }\n if (error != null && !(error instanceof RpcError)) throw error;\n }\n\n #sendRequest(\n id: number | undefined,\n method: keyof RemoteApi | keyof LocalApi,\n params?: any,\n ): void {\n this.connection.sendMessage({\n jsonrpc: '2.0',\n ...id != null ? { id } : {},\n method,\n ...params != null ? { params } : {},\n });\n }\n\n #sendResponse(\n id: number,\n method: keyof RemoteApi | keyof LocalApi, // TODO: remove as far it is not required in JSON RPC\n result?: any,\n error?: RpcError,\n ): void {\n this.connection.sendMessage({\n jsonrpc: '2.0',\n id,\n method,\n ...error != null ? { error: error.toJSON() } : { result },\n });\n }\n\n /**\n * Make a request\n * @param name - Method name\n * @param params - Method params\n * @returns Promise which will be resolved after receiving response message\n */\n async request<Name extends keyof RemoteApi>(\n name: Name,\n params: Parameters<RemoteApi[Name]>[0],\n ): Promise<ReturnType<RemoteApi[Name]>> {\n this.#sendRequest(this.#messageId += 1, name, params);\n return new Promise((resolve, reject) => {\n this.#callbacks.set(this.#messageId, { resolve, reject });\n });\n }\n\n /**\n * Make a notification\n * @param name - Method name\n * @param params - Method params\n */\n notify<Name extends keyof RemoteApi>(name: Name, params: Parameters<RemoteApi[Name]>[0]): void {\n this.#sendRequest(undefined, name, params);\n }\n\n /**\n * Process response message\n * @param msg - Message object\n */\n #processResponse({ id, error, result }: { id: number; error?: any; result?: any }): void {\n const callbacks = this.#callbacks.get(id);\n if (callbacks == null) throw new MissingCallbackError(id);\n if (error != null) callbacks.reject(RpcError.deserialize(error));\n else callbacks.resolve(result);\n this.#callbacks.delete(id);\n }\n}\n"],"mappings":";;;;;;SAASA,QAAQ,EAAEC,gBAAgB,EAAEC,sBAAsB;AAAA,SAElDC,sBAAsB,EAAEC,oBAAoB;AAAA,SAC5CC,WAAW;AAAA,IAAAC,UAAA,oBAAAC,OAAA;AAAA,IAAAC,UAAA,oBAAAD,OAAA;AAAA,IAAAE,QAAA,oBAAAF,OAAA;AAAA,IAAAG,cAAA,oBAAAC,OAAA;AAAA,IAAAC,YAAA,oBAAAD,OAAA;AAAA,IAAAE,aAAA,oBAAAF,OAAA;AAAA,IAAAG,gBAAA,oBAAAH,OAAA;AA2BpB;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,MAAMI,SAAS,CAE5B;EASAC,WAAWA,CACTC,UAA6B,EAC7BC,YAAwB,EACxBC,OAA6B,EAC7B;IAuFF;AACF;AACA;AACA;IAHEC,2BAAA,OAAAN,gBAAA;IAAAM,2BAAA,OAAAP,aAAA;IAAAO,2BAAA,OAAAR,YAAA;IAAAQ,2BAAA,OAAAV,cAAA;IAAAW,0BAAA,OAAAf,UAAA;MAAAgB,QAAA;MAAAC,KAAA,EAjGa,IAAIC,GAAG;
|
|
1
|
+
{"version":3,"file":"RpcClient.mjs","names":["RpcError","RpcInternalError","RpcMethodNotFoundError","InvalidRpcMessageError","MissingCallbackError","ensureError","_callbacks","WeakMap","_messageId","_methods","_handleMessage","WeakSet","_sendRequest","_sendResponse","_processResponse","RpcClient","constructor","connection","onDisconnect","methods","_classPrivateMethodInitSpec","_classPrivateFieldInitSpec","writable","value","Map","_classPrivateFieldSet","connect","_classPrivateMethodGet","_handleMessage2","bind","request","name","params","_sendRequest2","call","_classPrivateFieldGet","Promise","resolve","reject","set","notify","undefined","msg","origin","jsonrpc","JSON","stringify","_processResponse2","result","error","method","methodName","e","id","_sendResponse2","sendMessage","toJSON","_ref","callbacks","get","deserialize","delete"],"sources":["../../../src/aepp-wallet-communication/rpc/RpcClient.ts"],"sourcesContent":["import { RpcError, RpcInternalError, RpcMethodNotFoundError } from '../schema';\nimport BrowserConnection from '../connection/Browser';\nimport { InvalidRpcMessageError, MissingCallbackError } from '../../utils/errors';\nimport { ensureError } from '../../utils/other';\n\ninterface JsonRpcRequest {\n jsonrpc: '2.0';\n id: number;\n method: string;\n params?: any;\n}\n\ninterface JsonRpcResponse {\n jsonrpc: '2.0';\n id: number;\n method: string;\n result?: any;\n error?: {\n code: number;\n message: string;\n data?: any;\n };\n}\n\ntype RpcApiHandler = (p?: any) => any | undefined;\ntype RpcApi<Api> = { [k in keyof Api]: RpcApiHandler };\ntype WithOrigin<Api extends RpcApi<Api>> = {\n [k in keyof Api]: (p: Parameters<Api[k]>[0], origin: string) => ReturnType<Api[k]>\n};\n\n/**\n * Contain functionality for using RPC conection\n * @category aepp wallet communication\n * @param connection - Connection object\n * @param onDisconnect - Disconnect callback\n * @param methods - Object containing handlers for each request by name\n */\nexport default class RpcClient <\n RemoteApi extends RpcApi<RemoteApi>, LocalApi extends RpcApi<LocalApi>,\n> {\n connection: BrowserConnection;\n\n #callbacks = new Map<number, { resolve: (v: any) => void; reject: (e: Error) => void }>();\n\n #messageId = 0;\n\n #methods: WithOrigin<LocalApi>;\n\n constructor(\n connection: BrowserConnection,\n onDisconnect: () => void,\n methods: WithOrigin<LocalApi>,\n ) {\n this.connection = connection;\n this.#methods = methods;\n connection.connect(this.#handleMessage.bind(this), onDisconnect);\n }\n\n async #handleMessage(msg: JsonRpcRequest | JsonRpcResponse, origin: string): Promise<void> {\n if (msg?.jsonrpc !== '2.0') throw new InvalidRpcMessageError(JSON.stringify(msg));\n if ('result' in msg || 'error' in msg) {\n this.#processResponse(msg);\n return;\n }\n\n const request = msg as JsonRpcRequest;\n let result;\n let error: Error | undefined;\n try {\n if (!(request.method in this.#methods)) throw new RpcMethodNotFoundError();\n const methodName = request.method as keyof LocalApi;\n result = await this.#methods[methodName](request.params, origin);\n } catch (e) {\n ensureError(e);\n error = e;\n }\n if (request.id != null) {\n this.#sendResponse(\n request.id,\n request.method as keyof LocalApi,\n result,\n error == null || error instanceof RpcError ? error : new RpcInternalError(),\n );\n }\n if (error != null && !(error instanceof RpcError)) throw error;\n }\n\n #sendRequest(\n id: number | undefined,\n method: keyof RemoteApi | keyof LocalApi,\n params?: any,\n ): void {\n this.connection.sendMessage({\n jsonrpc: '2.0',\n ...id != null ? { id } : {},\n method,\n ...params != null ? { params } : {},\n });\n }\n\n #sendResponse(\n id: number,\n method: keyof RemoteApi | keyof LocalApi, // TODO: remove as far it is not required in JSON RPC\n result?: any,\n error?: RpcError,\n ): void {\n this.connection.sendMessage({\n jsonrpc: '2.0',\n id,\n method,\n ...error != null ? { error: error.toJSON() } : { result },\n });\n }\n\n /**\n * Make a request\n * @param name - Method name\n * @param params - Method params\n * @returns Promise which will be resolved after receiving response message\n */\n async request<Name extends keyof RemoteApi>(\n name: Name,\n params: Parameters<RemoteApi[Name]>[0],\n ): Promise<ReturnType<RemoteApi[Name]>> {\n this.#sendRequest(this.#messageId += 1, name, params);\n return new Promise((resolve, reject) => {\n this.#callbacks.set(this.#messageId, { resolve, reject });\n });\n }\n\n /**\n * Make a notification\n * @param name - Method name\n * @param params - Method params\n */\n notify<Name extends keyof RemoteApi>(name: Name, params: Parameters<RemoteApi[Name]>[0]): void {\n this.#sendRequest(undefined, name, params);\n }\n\n /**\n * Process response message\n * @param msg - Message object\n */\n #processResponse({ id, error, result }: { id: number; error?: any; result?: any }): void {\n const callbacks = this.#callbacks.get(id);\n if (callbacks == null) throw new MissingCallbackError(id);\n if (error != null) callbacks.reject(RpcError.deserialize(error));\n else callbacks.resolve(result);\n this.#callbacks.delete(id);\n }\n}\n"],"mappings":";;;;;;SAASA,QAAQ,EAAEC,gBAAgB,EAAEC,sBAAsB;AAAA,SAElDC,sBAAsB,EAAEC,oBAAoB;AAAA,SAC5CC,WAAW;AAAA,IAAAC,UAAA,oBAAAC,OAAA;AAAA,IAAAC,UAAA,oBAAAD,OAAA;AAAA,IAAAE,QAAA,oBAAAF,OAAA;AAAA,IAAAG,cAAA,oBAAAC,OAAA;AAAA,IAAAC,YAAA,oBAAAD,OAAA;AAAA,IAAAE,aAAA,oBAAAF,OAAA;AAAA,IAAAG,gBAAA,oBAAAH,OAAA;AA2BpB;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,MAAMI,SAAS,CAE5B;EASAC,WAAWA,CACTC,UAA6B,EAC7BC,YAAwB,EACxBC,OAA6B,EAC7B;IAuFF;AACF;AACA;AACA;IAHEC,2BAAA,OAAAN,gBAAA;IAAAM,2BAAA,OAAAP,aAAA;IAAAO,2BAAA,OAAAR,YAAA;IAAAQ,2BAAA,OAAAV,cAAA;IAAAW,0BAAA,OAAAf,UAAA;MAAAgB,QAAA;MAAAC,KAAA,EAjGa,IAAIC,GAAG,CAAoE;IAAC;IAAAH,0BAAA,OAAAb,UAAA;MAAAc,QAAA;MAAAC,KAAA,EAE5E;IAAC;IAAAF,0BAAA,OAAAZ,QAAA;MAAAa,QAAA;MAAAC,KAAA;IAAA;IASZ,IAAI,CAACN,UAAU,GAAGA,UAAU;IAC5BQ,qBAAA,KAAI,EAAAhB,QAAA,EAAYU,OAAO;IACvBF,UAAU,CAACS,OAAO,CAACC,sBAAA,KAAI,EAAAjB,cAAA,EAAAkB,eAAA,EAAgBC,IAAI,CAAC,IAAI,CAAC,EAAEX,YAAY,CAAC;EAClE;EA0DA;AACF;AACA;AACA;AACA;AACA;EACE,MAA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EA,KAAK,EAAEA,KAAK,CAACO,MAAM,CAAC;IAAE,CAAC,GAAG;MAAER;IAAO,CAAC;EAC3D,CAAC,CAAC;AACJ;AAAC,SAAAD,kBAAAU,IAAA,EA+BwF;EAAA,IAAxE;IAAEJ,EAAE;IAAEJ,KAAK;IAAED;EAAkD,CAAC,GAAAS,IAAA;EAC/E,MAAMC,SAAS,GAAGvB,qBAAA,KAAI,EAAA7B,UAAA,EAAYqD,GAAG,CAACN,EAAE,CAAC;EACzC,IAAIK,SAAS,IAAI,IAAI,EAAE,MAAM,IAAItD,oBAAoB,CAACiD,EAAE,CAAC;EACzD,IAAIJ,KAAK,IAAI,IAAI,EAAES,SAAS,CAACpB,MAAM,CAACtC,QAAQ,CAAC4D,WAAW,CAACX,KAAK,CAAC,CAAC,CAAC,KAC5DS,SAAS,CAACrB,OAAO,CAACW,MAAM,CAAC;EAC9Bb,qBAAA,KAAI,EAAA7B,UAAA,EAAYuD,MAAM,CAACR,EAAE,CAAC;AAC5B"}
|
|
@@ -3,6 +3,7 @@ import { Domain, AciValue } from '../../utils/typed-data';
|
|
|
3
3
|
import { METHODS, SUBSCRIPTION_TYPES, WALLET_TYPE } from '../schema';
|
|
4
4
|
import { TransformNodeType } from '../../Node';
|
|
5
5
|
import { SignedTx } from '../../apis/node';
|
|
6
|
+
import { AensName } from '../../tx/builder/constants';
|
|
6
7
|
export interface WalletInfo {
|
|
7
8
|
id: string;
|
|
8
9
|
name: string;
|
|
@@ -87,6 +88,14 @@ export interface WalletApi {
|
|
|
87
88
|
}) => Promise<{
|
|
88
89
|
signature: Encoded.Signature;
|
|
89
90
|
}>;
|
|
91
|
+
[METHODS.signDelegationToContract]: (p: {
|
|
92
|
+
contractAddress: Encoded.ContractAddress;
|
|
93
|
+
name?: AensName;
|
|
94
|
+
oracleQueryId?: Encoded.OracleQueryId;
|
|
95
|
+
onAccount: Encoded.AccountAddress;
|
|
96
|
+
}) => Promise<{
|
|
97
|
+
signature: Encoded.Signature;
|
|
98
|
+
}>;
|
|
90
99
|
}
|
|
91
100
|
export interface AeppApi {
|
|
92
101
|
[METHODS.updateAddress]: (a: Accounts) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.mjs","names":["METHODS","RPC_VERSION"],"sources":["../../../src/aepp-wallet-communication/rpc/types.ts"],"sourcesContent":["import { Encoded } from '../../utils/encoder';\nimport { Domain, AciValue } from '../../utils/typed-data';\nimport { METHODS, SUBSCRIPTION_TYPES, WALLET_TYPE } from '../schema';\nimport { TransformNodeType } from '../../Node';\nimport { SignedTx } from '../../apis/node';\n\nexport interface WalletInfo {\n id: string;\n name: string;\n networkId: string;\n origin: string;\n type: WALLET_TYPE;\n}\n\nexport interface Accounts {\n connected: { [pub: Encoded.AccountAddress]: {} };\n current: { [pub: Encoded.AccountAddress]: {} };\n}\n\nexport interface Node {\n // TODO: name is not used, can be removed\n name: string;\n url: string;\n}\n\nexport interface Network {\n networkId: string;\n node?: Node;\n}\n\ntype Icons = Array<{ src: string; sizes?: string; type?: string; purpose?: string }>;\n\nexport const RPC_VERSION = 1;\n\nexport interface WalletApi {\n [METHODS.connect]: (\n p: { name: string; icons?: Icons; version: typeof RPC_VERSION; connectNode: boolean }\n ) => Promise<WalletInfo & { node?: Node }>;\n\n [METHODS.closeConnection]: (p: any) => void;\n\n [METHODS.subscribeAddress]: (\n p: { type: SUBSCRIPTION_TYPES; value: 'connected' | 'current' }\n ) => Promise<{ subscription: Array<'connected' | 'current'>; address: Accounts }>;\n\n [METHODS.address]: () => Promise<Encoded.AccountAddress[]>;\n\n [METHODS.sign]: ((\n p: {\n tx: Encoded.Transaction;\n onAccount: Encoded.AccountAddress;\n returnSigned: boolean;\n /**\n * @deprecated Wallet provided networkId will be used (current network)\n * required to maintain backward compatibility with wallets using SDK v11.0.1 and below\n * @see {@link https://github.com/aeternity/aepp-sdk-js/commit/153fd89a52c4eab39fcd659b356b36d32129c1ba}\n */\n networkId: string;\n innerTx?: boolean;\n }\n ) => Promise<{\n /**\n * @deprecated this is not a hash at all, will be removed later at the same time\n * as dropping ability to broadcast transaction by wallet\n */\n transactionHash?: Partial<TransformNodeType<SignedTx>> & {\n hash: Encoded.TxHash;\n rawTx: Encoded.Transaction;\n };\n signedTransaction?: Encoded.Transaction;\n }>);\n\n [METHODS.signMessage]: (\n p: { message: string; onAccount: Encoded.AccountAddress }\n ) => Promise<{ signature: string }>;\n\n [METHODS.signTypedData]: (\n p: {\n domain: Domain;\n aci: AciValue;\n data: Encoded.ContractBytearray;\n onAccount: Encoded.AccountAddress;\n },\n ) => Promise<{ signature: Encoded.Signature }>;\n}\n\nexport interface AeppApi {\n [METHODS.updateAddress]: (a: Accounts) => void;\n [METHODS.updateNetwork]: (a: Network) => void;\n [METHODS.readyToConnect]: (w: WalletInfo) => void;\n [METHODS.closeConnection]: (p: any) => void;\n}\n"],"mappings":"SAESA,OAAO;
|
|
1
|
+
{"version":3,"file":"types.mjs","names":["METHODS","RPC_VERSION"],"sources":["../../../src/aepp-wallet-communication/rpc/types.ts"],"sourcesContent":["import { Encoded } from '../../utils/encoder';\nimport { Domain, AciValue } from '../../utils/typed-data';\nimport { METHODS, SUBSCRIPTION_TYPES, WALLET_TYPE } from '../schema';\nimport { TransformNodeType } from '../../Node';\nimport { SignedTx } from '../../apis/node';\nimport { AensName } from '../../tx/builder/constants';\n\nexport interface WalletInfo {\n id: string;\n name: string;\n networkId: string;\n origin: string;\n type: WALLET_TYPE;\n}\n\nexport interface Accounts {\n connected: { [pub: Encoded.AccountAddress]: {} };\n current: { [pub: Encoded.AccountAddress]: {} };\n}\n\nexport interface Node {\n // TODO: name is not used, can be removed\n name: string;\n url: string;\n}\n\nexport interface Network {\n networkId: string;\n node?: Node;\n}\n\ntype Icons = Array<{ src: string; sizes?: string; type?: string; purpose?: string }>;\n\nexport const RPC_VERSION = 1;\n\nexport interface WalletApi {\n [METHODS.connect]: (\n p: { name: string; icons?: Icons; version: typeof RPC_VERSION; connectNode: boolean }\n ) => Promise<WalletInfo & { node?: Node }>;\n\n [METHODS.closeConnection]: (p: any) => void;\n\n [METHODS.subscribeAddress]: (\n p: { type: SUBSCRIPTION_TYPES; value: 'connected' | 'current' }\n ) => Promise<{ subscription: Array<'connected' | 'current'>; address: Accounts }>;\n\n [METHODS.address]: () => Promise<Encoded.AccountAddress[]>;\n\n [METHODS.sign]: ((\n p: {\n tx: Encoded.Transaction;\n onAccount: Encoded.AccountAddress;\n returnSigned: boolean;\n /**\n * @deprecated Wallet provided networkId will be used (current network)\n * required to maintain backward compatibility with wallets using SDK v11.0.1 and below\n * @see {@link https://github.com/aeternity/aepp-sdk-js/commit/153fd89a52c4eab39fcd659b356b36d32129c1ba}\n */\n networkId: string;\n innerTx?: boolean;\n }\n ) => Promise<{\n /**\n * @deprecated this is not a hash at all, will be removed later at the same time\n * as dropping ability to broadcast transaction by wallet\n */\n transactionHash?: Partial<TransformNodeType<SignedTx>> & {\n hash: Encoded.TxHash;\n rawTx: Encoded.Transaction;\n };\n signedTransaction?: Encoded.Transaction;\n }>);\n\n [METHODS.signMessage]: (\n p: { message: string; onAccount: Encoded.AccountAddress }\n ) => Promise<{ signature: string }>;\n\n [METHODS.signTypedData]: (\n p: {\n domain: Domain;\n aci: AciValue;\n data: Encoded.ContractBytearray;\n onAccount: Encoded.AccountAddress;\n },\n ) => Promise<{ signature: Encoded.Signature }>;\n\n [METHODS.signDelegationToContract]: (\n p: {\n contractAddress: Encoded.ContractAddress;\n name?: AensName;\n oracleQueryId?: Encoded.OracleQueryId;\n onAccount: Encoded.AccountAddress;\n },\n ) => Promise<{ signature: Encoded.Signature }>;\n}\n\nexport interface AeppApi {\n [METHODS.updateAddress]: (a: Accounts) => void;\n [METHODS.updateNetwork]: (a: Network) => void;\n [METHODS.readyToConnect]: (w: WalletInfo) => void;\n [METHODS.closeConnection]: (p: any) => void;\n}\n"],"mappings":"SAESA,OAAO;AA+BhB,OAAO,MAAMC,WAAW,GAAG,CAAC"}
|
|
@@ -32,6 +32,7 @@ export declare const enum METHODS {
|
|
|
32
32
|
sign = "transaction.sign",
|
|
33
33
|
signMessage = "message.sign",
|
|
34
34
|
signTypedData = "typedData.sign",
|
|
35
|
+
signDelegationToContract = "delegationToContract.sign",
|
|
35
36
|
subscribeAddress = "address.subscribe",
|
|
36
37
|
updateNetwork = "networkId.update",
|
|
37
38
|
closeConnection = "connection.close"
|
|
@@ -4,39 +4,34 @@ import { BaseError, InternalError } from "../utils/errors.mjs";
|
|
|
4
4
|
/**
|
|
5
5
|
* @category aepp wallet communication
|
|
6
6
|
*/
|
|
7
|
-
export let MESSAGE_DIRECTION
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* @category aepp wallet communication
|
|
11
|
-
*/
|
|
12
|
-
(function (MESSAGE_DIRECTION) {
|
|
7
|
+
export let MESSAGE_DIRECTION = /*#__PURE__*/function (MESSAGE_DIRECTION) {
|
|
13
8
|
MESSAGE_DIRECTION["to_waellet"] = "to_waellet";
|
|
14
9
|
MESSAGE_DIRECTION["to_aepp"] = "to_aepp";
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
return MESSAGE_DIRECTION;
|
|
11
|
+
}({});
|
|
17
12
|
|
|
18
13
|
/**
|
|
19
14
|
* @category aepp wallet communication
|
|
20
15
|
*/
|
|
21
|
-
|
|
16
|
+
export let WALLET_TYPE = /*#__PURE__*/function (WALLET_TYPE) {
|
|
22
17
|
WALLET_TYPE["window"] = "window";
|
|
23
18
|
WALLET_TYPE["extension"] = "extension";
|
|
24
|
-
|
|
25
|
-
|
|
19
|
+
return WALLET_TYPE;
|
|
20
|
+
}({});
|
|
26
21
|
|
|
27
22
|
/**
|
|
28
23
|
* @category aepp wallet communication
|
|
29
24
|
*/
|
|
30
|
-
|
|
25
|
+
export let SUBSCRIPTION_TYPES = /*#__PURE__*/function (SUBSCRIPTION_TYPES) {
|
|
31
26
|
SUBSCRIPTION_TYPES["subscribe"] = "subscribe";
|
|
32
27
|
SUBSCRIPTION_TYPES["unsubscribe"] = "unsubscribe";
|
|
33
|
-
|
|
34
|
-
|
|
28
|
+
return SUBSCRIPTION_TYPES;
|
|
29
|
+
}({});
|
|
35
30
|
|
|
36
31
|
/**
|
|
37
32
|
* @category aepp wallet communication
|
|
38
33
|
*/
|
|
39
|
-
|
|
34
|
+
export let METHODS = /*#__PURE__*/function (METHODS) {
|
|
40
35
|
METHODS["readyToConnect"] = "connection.announcePresence";
|
|
41
36
|
METHODS["updateAddress"] = "address.update";
|
|
42
37
|
METHODS["address"] = "address.get";
|
|
@@ -44,16 +39,22 @@ export let METHODS;
|
|
|
44
39
|
METHODS["sign"] = "transaction.sign";
|
|
45
40
|
METHODS["signMessage"] = "message.sign";
|
|
46
41
|
METHODS["signTypedData"] = "typedData.sign";
|
|
42
|
+
METHODS["signDelegationToContract"] = "delegationToContract.sign";
|
|
47
43
|
METHODS["subscribeAddress"] = "address.subscribe";
|
|
48
44
|
METHODS["updateNetwork"] = "networkId.update";
|
|
49
45
|
METHODS["closeConnection"] = "connection.close";
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
46
|
+
return METHODS;
|
|
47
|
+
}({});
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @category aepp wallet communication
|
|
51
|
+
*/
|
|
52
|
+
export let RPC_STATUS = /*#__PURE__*/function (RPC_STATUS) {
|
|
53
53
|
RPC_STATUS["CONNECTED"] = "CONNECTED";
|
|
54
54
|
RPC_STATUS["DISCONNECTED"] = "DISCONNECTED";
|
|
55
55
|
RPC_STATUS["WAITING_FOR_CONNECTION_REQUEST"] = "WAITING_FOR_CONNECTION_REQUEST";
|
|
56
|
-
|
|
56
|
+
return RPC_STATUS;
|
|
57
|
+
}({});
|
|
57
58
|
const rpcErrors = [];
|
|
58
59
|
|
|
59
60
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.mjs","names":["BaseError","InternalError","MESSAGE_DIRECTION","WALLET_TYPE","SUBSCRIPTION_TYPES","METHODS","RPC_STATUS","rpcErrors","RpcError","toJSON","code","message","data","deserialize","json","RpcErr","find","cl","RpcInvalidTransactionError","constructor","_defineProperty","name","push","RpcRejectedByUserError","RpcUnsupportedProtocolError","RpcConnectionDenyError","RpcNotAuthorizeError","RpcPermissionDenyError","address","RpcInternalError","RpcMethodNotFoundError"],"sources":["../../src/aepp-wallet-communication/schema.ts"],"sourcesContent":["// eslint-disable-next-line max-classes-per-file\nimport { Encoded } from '../utils/encoder';\nimport { BaseError, InternalError } from '../utils/errors';\n\n/**\n * @category aepp wallet communication\n */\nexport const enum MESSAGE_DIRECTION {\n to_waellet = 'to_waellet',\n to_aepp = 'to_aepp',\n}\n\n/**\n * @category aepp wallet communication\n */\nexport const enum WALLET_TYPE {\n window = 'window',\n extension = 'extension',\n}\n\n/**\n * @category aepp wallet communication\n */\nexport const enum SUBSCRIPTION_TYPES {\n subscribe = 'subscribe',\n unsubscribe = 'unsubscribe',\n}\n\n/**\n * @category aepp wallet communication\n */\nexport const enum METHODS {\n readyToConnect = 'connection.announcePresence',\n updateAddress = 'address.update',\n address = 'address.get',\n connect = 'connection.open',\n sign = 'transaction.sign',\n signMessage = 'message.sign',\n signTypedData = 'typedData.sign',\n subscribeAddress = 'address.subscribe',\n updateNetwork = 'networkId.update',\n closeConnection = 'connection.close',\n}\n\n/**\n * @category aepp wallet communication\n */\nexport const enum RPC_STATUS {\n CONNECTED = 'CONNECTED',\n DISCONNECTED = 'DISCONNECTED',\n WAITING_FOR_CONNECTION_REQUEST = 'WAITING_FOR_CONNECTION_REQUEST',\n}\n\ninterface RpcErrorAsJson {\n code: number;\n message: string;\n data?: any;\n}\n\nconst rpcErrors: Array<(new (data?: any) => RpcError) & { code: number }> = [];\n\n/**\n * @category exception\n */\nexport abstract class RpcError extends BaseError {\n static code: number;\n\n code!: number;\n\n data?: any;\n\n toJSON(): RpcErrorAsJson {\n return {\n code: this.code,\n message: this.message,\n data: this.data,\n };\n }\n\n static deserialize(json: RpcErrorAsJson): RpcError {\n const RpcErr = rpcErrors.find((cl) => cl.code === json.code);\n if (RpcErr == null) throw new InternalError(`Can't find RpcError with code: ${json.code}`);\n return new RpcErr(json.data);\n }\n}\n\n/**\n * @category exception\n */\nexport class RpcInvalidTransactionError extends RpcError {\n static override code = 2;\n\n override code = 2;\n\n constructor(data?: any) {\n super('Invalid transaction');\n this.data = data;\n this.name = 'RpcInvalidTransactionError';\n }\n}\nrpcErrors.push(RpcInvalidTransactionError);\n\n/**\n * @category exception\n */\nexport class RpcRejectedByUserError extends RpcError {\n static override code = 4;\n\n override code = 4;\n\n constructor(data?: any) {\n super('Operation rejected by user');\n this.data = data;\n this.name = 'RpcRejectedByUserError';\n }\n}\nrpcErrors.push(RpcRejectedByUserError);\n\n/**\n * @category exception\n */\nexport class RpcUnsupportedProtocolError extends RpcError {\n static override code = 5;\n\n override code = 5;\n\n constructor() {\n super('Unsupported Protocol Version');\n this.name = 'RpcUnsupportedProtocolError';\n }\n}\nrpcErrors.push(RpcUnsupportedProtocolError);\n\n/**\n * @category exception\n */\nexport class RpcConnectionDenyError extends RpcError {\n static override code = 9;\n\n override code = 9;\n\n constructor(data?: any) {\n super('Wallet deny your connection request');\n this.data = data;\n this.name = 'RpcConnectionDenyError';\n }\n}\nrpcErrors.push(RpcConnectionDenyError);\n\n/**\n * @category exception\n */\nexport class RpcNotAuthorizeError extends RpcError {\n static override code = 10;\n\n override code = 10;\n\n constructor() {\n super('You are not connected to the wallet');\n this.name = 'RpcNotAuthorizeError';\n }\n}\nrpcErrors.push(RpcNotAuthorizeError);\n\n/**\n * @category exception\n */\nexport class RpcPermissionDenyError extends RpcError {\n static override code = 11;\n\n override code = 11;\n\n constructor(address: Encoded.AccountAddress) {\n super(`You are not subscribed for account ${address}`);\n this.data = address;\n this.name = 'RpcPermissionDenyError';\n }\n}\nrpcErrors.push(RpcPermissionDenyError);\n\n/**\n * @category exception\n */\nexport class RpcInternalError extends RpcError {\n static override code = 12;\n\n override code = 12;\n\n constructor() {\n super('The peer failed to execute your request due to unknown error');\n this.name = 'RpcInternalError';\n }\n}\nrpcErrors.push(RpcInternalError);\n\n/**\n * @category exception\n */\nexport class RpcMethodNotFoundError extends RpcError {\n static override code = -32601;\n\n override code = -32601;\n\n constructor() {\n super('Method not found');\n this.name = 'RpcMethodNotFoundError';\n }\n}\nrpcErrors.push(RpcMethodNotFoundError);\n"],"mappings":";AAAA;AAAA,SAESA,SAAS,EAAEC,aAAa;AAEjC;AACA;AACA;AACA,WAAkBC,iBAAiB
|
|
1
|
+
{"version":3,"file":"schema.mjs","names":["BaseError","InternalError","MESSAGE_DIRECTION","WALLET_TYPE","SUBSCRIPTION_TYPES","METHODS","RPC_STATUS","rpcErrors","RpcError","toJSON","code","message","data","deserialize","json","RpcErr","find","cl","RpcInvalidTransactionError","constructor","_defineProperty","name","push","RpcRejectedByUserError","RpcUnsupportedProtocolError","RpcConnectionDenyError","RpcNotAuthorizeError","RpcPermissionDenyError","address","RpcInternalError","RpcMethodNotFoundError"],"sources":["../../src/aepp-wallet-communication/schema.ts"],"sourcesContent":["// eslint-disable-next-line max-classes-per-file\nimport { Encoded } from '../utils/encoder';\nimport { BaseError, InternalError } from '../utils/errors';\n\n/**\n * @category aepp wallet communication\n */\nexport const enum MESSAGE_DIRECTION {\n to_waellet = 'to_waellet',\n to_aepp = 'to_aepp',\n}\n\n/**\n * @category aepp wallet communication\n */\nexport const enum WALLET_TYPE {\n window = 'window',\n extension = 'extension',\n}\n\n/**\n * @category aepp wallet communication\n */\nexport const enum SUBSCRIPTION_TYPES {\n subscribe = 'subscribe',\n unsubscribe = 'unsubscribe',\n}\n\n/**\n * @category aepp wallet communication\n */\nexport const enum METHODS {\n readyToConnect = 'connection.announcePresence',\n updateAddress = 'address.update',\n address = 'address.get',\n connect = 'connection.open',\n sign = 'transaction.sign',\n signMessage = 'message.sign',\n signTypedData = 'typedData.sign',\n signDelegationToContract = 'delegationToContract.sign',\n subscribeAddress = 'address.subscribe',\n updateNetwork = 'networkId.update',\n closeConnection = 'connection.close',\n}\n\n/**\n * @category aepp wallet communication\n */\nexport const enum RPC_STATUS {\n CONNECTED = 'CONNECTED',\n DISCONNECTED = 'DISCONNECTED',\n WAITING_FOR_CONNECTION_REQUEST = 'WAITING_FOR_CONNECTION_REQUEST',\n}\n\ninterface RpcErrorAsJson {\n code: number;\n message: string;\n data?: any;\n}\n\nconst rpcErrors: Array<(new (data?: any) => RpcError) & { code: number }> = [];\n\n/**\n * @category exception\n */\nexport abstract class RpcError extends BaseError {\n static code: number;\n\n code!: number;\n\n data?: any;\n\n toJSON(): RpcErrorAsJson {\n return {\n code: this.code,\n message: this.message,\n data: this.data,\n };\n }\n\n static deserialize(json: RpcErrorAsJson): RpcError {\n const RpcErr = rpcErrors.find((cl) => cl.code === json.code);\n if (RpcErr == null) throw new InternalError(`Can't find RpcError with code: ${json.code}`);\n return new RpcErr(json.data);\n }\n}\n\n/**\n * @category exception\n */\nexport class RpcInvalidTransactionError extends RpcError {\n static override code = 2;\n\n override code = 2;\n\n constructor(data?: any) {\n super('Invalid transaction');\n this.data = data;\n this.name = 'RpcInvalidTransactionError';\n }\n}\nrpcErrors.push(RpcInvalidTransactionError);\n\n/**\n * @category exception\n */\nexport class RpcRejectedByUserError extends RpcError {\n static override code = 4;\n\n override code = 4;\n\n constructor(data?: any) {\n super('Operation rejected by user');\n this.data = data;\n this.name = 'RpcRejectedByUserError';\n }\n}\nrpcErrors.push(RpcRejectedByUserError);\n\n/**\n * @category exception\n */\nexport class RpcUnsupportedProtocolError extends RpcError {\n static override code = 5;\n\n override code = 5;\n\n constructor() {\n super('Unsupported Protocol Version');\n this.name = 'RpcUnsupportedProtocolError';\n }\n}\nrpcErrors.push(RpcUnsupportedProtocolError);\n\n/**\n * @category exception\n */\nexport class RpcConnectionDenyError extends RpcError {\n static override code = 9;\n\n override code = 9;\n\n constructor(data?: any) {\n super('Wallet deny your connection request');\n this.data = data;\n this.name = 'RpcConnectionDenyError';\n }\n}\nrpcErrors.push(RpcConnectionDenyError);\n\n/**\n * @category exception\n */\nexport class RpcNotAuthorizeError extends RpcError {\n static override code = 10;\n\n override code = 10;\n\n constructor() {\n super('You are not connected to the wallet');\n this.name = 'RpcNotAuthorizeError';\n }\n}\nrpcErrors.push(RpcNotAuthorizeError);\n\n/**\n * @category exception\n */\nexport class RpcPermissionDenyError extends RpcError {\n static override code = 11;\n\n override code = 11;\n\n constructor(address: Encoded.AccountAddress) {\n super(`You are not subscribed for account ${address}`);\n this.data = address;\n this.name = 'RpcPermissionDenyError';\n }\n}\nrpcErrors.push(RpcPermissionDenyError);\n\n/**\n * @category exception\n */\nexport class RpcInternalError extends RpcError {\n static override code = 12;\n\n override code = 12;\n\n constructor() {\n super('The peer failed to execute your request due to unknown error');\n this.name = 'RpcInternalError';\n }\n}\nrpcErrors.push(RpcInternalError);\n\n/**\n * @category exception\n */\nexport class RpcMethodNotFoundError extends RpcError {\n static override code = -32601;\n\n override code = -32601;\n\n constructor() {\n super('Method not found');\n this.name = 'RpcMethodNotFoundError';\n }\n}\nrpcErrors.push(RpcMethodNotFoundError);\n"],"mappings":";AAAA;AAAA,SAESA,SAAS,EAAEC,aAAa;AAEjC;AACA;AACA;AACA,WAAkBC,iBAAiB,0BAAjBA,iBAAiB;EAAjBA,iBAAiB;EAAjBA,iBAAiB;EAAA,OAAjBA,iBAAiB;AAAA;;AAKnC;AACA;AACA;AACA,WAAkBC,WAAW,0BAAXA,WAAW;EAAXA,WAAW;EAAXA,WAAW;EAAA,OAAXA,WAAW;AAAA;;AAK7B;AACA;AACA;AACA,WAAkBC,kBAAkB,0BAAlBA,kBAAkB;EAAlBA,kBAAkB;EAAlBA,kBAAkB;EAAA,OAAlBA,kBAAkB;AAAA;;AAKpC;AACA;AACA;AACA,WAAkBC,OAAO,0BAAPA,OAAO;EAAPA,OAAO;EAAPA,OAAO;EAAPA,OAAO;EAAPA,OAAO;EAAPA,OAAO;EAAPA,OAAO;EAAPA,OAAO;EAAPA,OAAO;EAAPA,OAAO;EAAPA,OAAO;EAA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AE;IAIhB,IAAI,CAACR,IAAI,GAAGgB,OAAO;IACnB,IAAI,CAACP,IAAI,GAAG,wBAAwB;EACtC;AACF;AAACD,eAAA,CAVYO,sBAAsB,UACV,EAAE;AAU3BpB,SAAS,CAACe,IAAI,CAACK,sBAAsB,CAAC;;AAEtC;AACA;AACA;AACA,OAAO,MAAME,gBAAgB,SAASrB,QAAQ,CAAC;EAK7CW,WAAWA,CAAA,EAAG;IACZ,KAAK,CAAC,8DAA8D,CAAC;IAACC,eAAA,eAHxD,EAAE;IAIhB,IAAI,CAACC,IAAI,GAAG,kBAAkB;EAChC;AACF;AAACD,eAAA,CATYS,gBAAgB,UACJ,EAAE;AAS3BtB,SAAS,CAACe,IAAI,CAACO,gBAAgB,CAAC;;AAEhC;AACA;AACA;AACA,OAAO,MAAMC,sBAAsB,SAAStB,QAAQ,CAAC;EAKnDW,WAAWA,CAAA,EAAG;IACZ,KAAK,CAAC,kBAAkB,CAAC;IAACC,eAAA,eAHZ,CAAC,KAAK;IAIpB,IAAI,CAACC,IAAI,GAAG,wBAAwB;EACtC;AACF;AAACD,eAAA,CATYU,sBAAsB,UACV,CAAC,KAAK;AAS/BvB,SAAS,CAACe,IAAI,CAACQ,sBAAsB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wallet-detector.mjs","names":["BrowserWindowMessageConnection","MESSAGE_DIRECTION","METHODS","UnsupportedPlatformError","connection","onDetected","window","wallets","connect","_ref","origin","source","method","params","readyToConnect","id","wallet","info","getConnection","isExtension","type","sendDirection","to_waellet","undefined","receiveDirection","to_aepp","target","newWallet","disconnect"],"sources":["../../src/aepp-wallet-communication/wallet-detector.ts"],"sourcesContent":["import BrowserConnection from './connection/Browser';\nimport BrowserWindowMessageConnection from './connection/BrowserWindowMessage';\nimport { MESSAGE_DIRECTION, METHODS } from './schema';\nimport { UnsupportedPlatformError } from '../utils/errors';\n\ninterface Wallet {\n info: {\n id: string;\n type: string;\n origin: string;\n };\n getConnection: () => BrowserWindowMessageConnection;\n}\ninterface Wallets { [key: string]: Wallet }\n\n/**\n * A function to detect available wallets\n * @category aepp wallet communication\n * @param connection - connection to use to detect wallets\n * @param onDetected - call-back function which trigger on new wallet\n * @returns a function to stop scanning\n */\nexport default (\n connection: BrowserConnection,\n onDetected: ({ wallets, newWallet }: { wallets: Wallets; newWallet: Wallet }) => void,\n): () => void => {\n if (window == null) throw new UnsupportedPlatformError('Window object not found, you can run wallet detector only in browser');\n const wallets: Wallets = {};\n\n connection.connect((\n { method, params }: { method: string; params: Wallet['info'] },\n origin: string,\n source: Window,\n ) => {\n if (method !== METHODS.readyToConnect || wallets[params.id] != null) return;\n\n const wallet = {\n info: params,\n getConnection() {\n const isExtension = params.type === 'extension';\n return new BrowserWindowMessageConnection({\n sendDirection: isExtension ? MESSAGE_DIRECTION.to_waellet : undefined,\n receiveDirection: isExtension ? MESSAGE_DIRECTION.to_aepp : undefined,\n target: source,\n origin: isExtension ? window.origin : params.origin,\n });\n },\n };\n wallets[wallet.info.id] = wallet;\n onDetected({ wallets, newWallet: wallet });\n }, () => {});\n\n return () => connection.disconnect();\n};\n"],"mappings":"OACOA,8BAA8B;AAAA,SAC5BC,iBAAiB,EAAEC,OAAO;AAAA,SAC1BC,wBAAwB;AAYjC;AACA;AACA;AACA;AACA;AACA;AACA;AACA,gBAAe,CACbC,UAA6B,EAC7BC,UAAqF,KACtE;EACf,IAAIC,MAAM,IAAI,IAAI,EAAE,MAAM,IAAIH,wBAAwB,CAAC,sEAAsE,CAAC;EAC9H,MAAMI,OAAgB,GAAG,CAAC,CAAC;EAE3BH,UAAU,CAACI,OAAO,CAAC,CAAAC,IAAA,EAEjBC,MAAc,EACdC,MAAc,KACX;IAAA,IAHH;MAAEC,MAAM;MAAEC;IAAmD,CAAC,GAAAJ,IAAA;IAI9D,IAAIG,MAAM,KAAKV,OAAO,CAACY,cAAc,IAAIP,OAAO,CAACM,MAAM,CAACE,EAAE,CAAC,IAAI,IAAI,EAAE;IAErE,MAAMC,MAAM,GAAG;MACbC,IAAI,EAAEJ,MAAM;MACZK,aAAaA,CAAA,EAAG;QACd,MAAMC,WAAW,GAAGN,MAAM,CAACO,IAAI,KAAK,WAAW;QAC/C,OAAO,IAAIpB,8BAA8B,CAAC;UACxCqB,aAAa,EAAEF,WAAW,GAAGlB,iBAAiB,CAACqB,UAAU,GAAGC,SAAS;UACrEC,gBAAgB,EAAEL,WAAW,GAAGlB,iBAAiB,CAACwB,OAAO,GAAGF,SAAS;UACrEG,MAAM,EAAEf,MAAM;UACdD,MAAM,EAAES,WAAW,GAAGb,MAAM,CAACI,MAAM,GAAGG,MAAM,CAACH;QAC/C,CAAC,CAAC;MACJ;IACF,CAAC;IACDH,OAAO,CAACS,MAAM,CAACC,IAAI,CAACF,EAAE,CAAC,GAAGC,MAAM;IAChCX,UAAU,CAAC;MAAEE,OAAO;MAAEoB,SAAS,EAAEX;IAAO,CAAC,CAAC;EAC5C,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;EAEZ,OAAO,MAAMZ,UAAU,CAACwB,UAAU,
|
|
1
|
+
{"version":3,"file":"wallet-detector.mjs","names":["BrowserWindowMessageConnection","MESSAGE_DIRECTION","METHODS","UnsupportedPlatformError","connection","onDetected","window","wallets","connect","_ref","origin","source","method","params","readyToConnect","id","wallet","info","getConnection","isExtension","type","sendDirection","to_waellet","undefined","receiveDirection","to_aepp","target","newWallet","disconnect"],"sources":["../../src/aepp-wallet-communication/wallet-detector.ts"],"sourcesContent":["import BrowserConnection from './connection/Browser';\nimport BrowserWindowMessageConnection from './connection/BrowserWindowMessage';\nimport { MESSAGE_DIRECTION, METHODS } from './schema';\nimport { UnsupportedPlatformError } from '../utils/errors';\n\ninterface Wallet {\n info: {\n id: string;\n type: string;\n origin: string;\n };\n getConnection: () => BrowserWindowMessageConnection;\n}\ninterface Wallets { [key: string]: Wallet }\n\n/**\n * A function to detect available wallets\n * @category aepp wallet communication\n * @param connection - connection to use to detect wallets\n * @param onDetected - call-back function which trigger on new wallet\n * @returns a function to stop scanning\n */\nexport default (\n connection: BrowserConnection,\n onDetected: ({ wallets, newWallet }: { wallets: Wallets; newWallet: Wallet }) => void,\n): () => void => {\n if (window == null) throw new UnsupportedPlatformError('Window object not found, you can run wallet detector only in browser');\n const wallets: Wallets = {};\n\n connection.connect((\n { method, params }: { method: string; params: Wallet['info'] },\n origin: string,\n source: Window,\n ) => {\n if (method !== METHODS.readyToConnect || wallets[params.id] != null) return;\n\n const wallet = {\n info: params,\n getConnection() {\n const isExtension = params.type === 'extension';\n return new BrowserWindowMessageConnection({\n sendDirection: isExtension ? MESSAGE_DIRECTION.to_waellet : undefined,\n receiveDirection: isExtension ? MESSAGE_DIRECTION.to_aepp : undefined,\n target: source,\n origin: isExtension ? window.origin : params.origin,\n });\n },\n };\n wallets[wallet.info.id] = wallet;\n onDetected({ wallets, newWallet: wallet });\n }, () => {});\n\n return () => connection.disconnect();\n};\n"],"mappings":"OACOA,8BAA8B;AAAA,SAC5BC,iBAAiB,EAAEC,OAAO;AAAA,SAC1BC,wBAAwB;AAYjC;AACA;AACA;AACA;AACA;AACA;AACA;AACA,gBAAe,CACbC,UAA6B,EAC7BC,UAAqF,KACtE;EACf,IAAIC,MAAM,IAAI,IAAI,EAAE,MAAM,IAAIH,wBAAwB,CAAC,sEAAsE,CAAC;EAC9H,MAAMI,OAAgB,GAAG,CAAC,CAAC;EAE3BH,UAAU,CAACI,OAAO,CAAC,CAAAC,IAAA,EAEjBC,MAAc,EACdC,MAAc,KACX;IAAA,IAHH;MAAEC,MAAM;MAAEC;IAAmD,CAAC,GAAAJ,IAAA;IAI9D,IAAIG,MAAM,KAAKV,OAAO,CAACY,cAAc,IAAIP,OAAO,CAACM,MAAM,CAACE,EAAE,CAAC,IAAI,IAAI,EAAE;IAErE,MAAMC,MAAM,GAAG;MACbC,IAAI,EAAEJ,MAAM;MACZK,aAAaA,CAAA,EAAG;QACd,MAAMC,WAAW,GAAGN,MAAM,CAACO,IAAI,KAAK,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