{"version":3,"sources":["../../src/connector/index.ts"],"sourcesContent":["import {\n  setIfDoesNotExist,\n  set,\n  objKeyByConnectorPlatform,\n} from '@nufi/dapp-client-core'\nimport type {\n  ConnectorObject,\n  InjectedConnectorFactory,\n  ConnectorPlatform,\n  MessagingClient,\n} from '@nufi/dapp-client-core'\n\nimport {emulatedWalletIcons} from './emulatedWalletIcons'\n\nexport * from './utils'\n\nconst connectorKind = 'cardano'\n\n/* The static configuration is determined at compile time, and must not change\n * afterwards.  */\nexport type CardanoDappConnectorConfig = {\n  appId: string\n  connectorPlatform: ConnectorPlatform\n  name: string\n  icons: {\n    default: string\n  }\n  connectors: {\n    cardano: Record<PropertyKey, never>\n  }\n}\n\nexport const API_VERSION = '1.1.0'\n\nexport const createInjectedConnectorFactory =\n  (options?: {\n    beforeEnable?: (client: MessagingClient) => Promise<void>\n  }): InjectedConnectorFactory<CardanoDappConnectorConfig> =>\n  (client, config) => {\n    const createProxyMethods = (methods: string[]) =>\n      Object.fromEntries(\n        methods.map((method) => [method, client.proxy[method]]),\n      )\n\n    // CIP-0030\n    const cip30ApiObject = {\n      ...createProxyMethods([\n        'getExtensions',\n        'getNetworkId',\n        'getUtxos',\n        'getBalance',\n        'getUsedAddresses',\n        'getUnusedAddresses',\n        'getChangeAddress',\n        'getRewardAddresses',\n        'signTx',\n        'signData',\n        'submitTx',\n        'getCollateral',\n      ]),\n      experimental: {\n        getCollateral: client.proxy.getCollateral,\n      },\n    }\n    // CIP-0095\n    const cip95ApiObject = {\n      ...createProxyMethods([\n        'signData',\n        'getPubDRepKey',\n        'getRegisteredPubStakeKeys',\n        'getUnregisteredPubStakeKeys',\n      ]),\n    }\n\n    const connectorObject = {\n      enable: async () => {\n        await options?.beforeEnable?.(client)\n\n        await client.proxy.enable() // This will throw on failure\n        return {\n          ...cip30ApiObject,\n          cip95: cip95ApiObject,\n        }\n      },\n      isEnabled: async () => await client.proxy.isEnabled(),\n      apiVersion: API_VERSION,\n      name: config.name,\n      icon: config.icons.default,\n      supportedExtensions: [{cip: 95}],\n    } as unknown as ConnectorObject\n\n    return {\n      connectorKind,\n      inject: (window) => {\n        // We are not using `setIfDoesNotExist` here as in case of Widget\n        // we are expecting reassignments (due to messaging port recreation).\n        set(\n          window,\n          [connectorKind, objKeyByConnectorPlatform[config.connectorPlatform]],\n          connectorObject,\n        )\n      },\n      injectOverrides: (window, walletOverrides) => {\n        if (walletOverrides?.eternl) {\n          const eternlConnector = {\n            ...connectorObject,\n            name: 'eternl',\n            icon: emulatedWalletIcons.eternl,\n            experimental: {\n              // without this, e.g. jpg.store fails to recognize eternl wallet\n              appVersion: {major: 2, minor: 0, patch: 9, build: 14},\n            },\n          }\n          setIfDoesNotExist(window, [connectorKind, 'eternl'], eternlConnector)\n        }\n      },\n      async eventHandler() {},\n    }\n  }\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,8BAIO;AAQP,iCAAkC;AAElC,8BAAc,wBAdd;AAgBA,IAAM,gBAAgB;AAgBf,IAAM,cAAc;AAEpB,IAAM,iCACX,CAAC,YAGD,CAAC,QAAQ,WAAW;AAClB,QAAM,qBAAqB,CAAC,YAC1B,OAAO;AAAA,IACL,QAAQ,IAAI,CAAC,WAAW,CAAC,QAAQ,OAAO,MAAM,MAAM,CAAC,CAAC;AAAA,EACxD;AAGF,QAAM,iBAAiB;AAAA,IACrB,GAAG,mBAAmB;AAAA,MACpB;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF,CAAC;AAAA,IACD,cAAc;AAAA,MACZ,eAAe,OAAO,MAAM;AAAA,IAC9B;AAAA,EACF;AAEA,QAAM,iBAAiB;AAAA,IACrB,GAAG,mBAAmB;AAAA,MACpB;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF,CAAC;AAAA,EACH;AAEA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