{"version":3,"file":"signer.cjs","names":["account: Account | Address"],"sources":["../../src/signing/signer.ts"],"sourcesContent":["import type { Account, Address, WalletClient } from \"viem\";\n\ntype TypedDataDomain = Record<string, unknown>;\ntype TypedDataTypes = Record<string, Array<{ name: string; type: string }>>;\ntype TypedDataValue = Record<string, unknown>;\n\ninterface EthersSigner {\n\t_signTypedData(\n\t\tdomain: TypedDataDomain,\n\t\ttypes: TypedDataTypes,\n\t\tvalue: TypedDataValue,\n\t): Promise<string>;\n\tgetAddress(): Promise<string>;\n}\n\nexport type ClobSigner = EthersSigner | WalletClient;\n\nconst isEthersTypedDataSigner = (signer: ClobSigner): signer is EthersSigner =>\n\t// eslint-disable-next-line no-underscore-dangle\n\ttypeof (signer as EthersSigner)._signTypedData === \"function\";\n\nconst isWalletClientSigner = (signer: ClobSigner): signer is WalletClient =>\n\ttypeof (signer as WalletClient).signTypedData === \"function\";\n\nexport const getWalletClientAddress = async (walletClient: WalletClient): Promise<Address> => {\n\tconst accountAddress = walletClient.account?.address;\n\tif (typeof accountAddress === \"string\" && accountAddress.length > 0) {\n\t\treturn accountAddress as Address;\n\t}\n\n\tif (typeof walletClient.requestAddresses === \"function\") {\n\t\tconst [address] = await walletClient.requestAddresses();\n\t\tif (typeof address === \"string\" && address.length > 0) {\n\t\t\treturn address as Address;\n\t\t}\n\t}\n\n\tif (typeof walletClient.getAddresses === \"function\") {\n\t\tconst [address] = await walletClient.getAddresses();\n\t\tif (typeof address === \"string\" && address.length > 0) {\n\t\t\treturn address as Address;\n\t\t}\n\t}\n\n\tthrow new Error(\"wallet client is missing account address\");\n};\n\nexport const getSignerAddress = async (signer: ClobSigner): Promise<string> => {\n\tif (isEthersTypedDataSigner(signer)) {\n\t\treturn signer.getAddress();\n\t}\n\n\tif (isWalletClientSigner(signer)) {\n\t\treturn getWalletClientAddress(signer);\n\t}\n\n\tthrow new Error(\"unsupported signer type\");\n};\n\nexport const signTypedDataWithSigner = async ({\n\tsigner,\n\tdomain,\n\ttypes,\n\tvalue,\n\tprimaryType,\n}: {\n\tsigner: ClobSigner;\n\tdomain: TypedDataDomain;\n\ttypes: TypedDataTypes;\n\tvalue: TypedDataValue;\n\tprimaryType?: string;\n}): Promise<string> => {\n\tif (isEthersTypedDataSigner(signer)) {\n\t\t// eslint-disable-next-line no-underscore-dangle\n\t\treturn signer._signTypedData(domain, types, value);\n\t}\n\n\tif (isWalletClientSigner(signer)) {\n\t\tconst account: Account | Address = signer.account ?? (await getWalletClientAddress(signer));\n\t\treturn signer.signTypedData({\n\t\t\taccount,\n\t\t\tdomain,\n\t\t\ttypes,\n\t\t\tprimaryType,\n\t\t\tmessage: value,\n\t\t} as Parameters<WalletClient[\"signTypedData\"]>[0]);\n\t}\n\n\tthrow new Error(\"unsupported signer type\");\n};\n"],"mappings":";;AAiBA,MAAM,2BAA2B,WAEhC,OAAQ,OAAwB,mBAAmB;AAEpD,MAAM,wBAAwB,WAC7B,OAAQ,OAAwB,kBAAkB;AAEnD,MAAa,yBAAyB,OAAO,iBAAiD;CAC7F,MAAM,iBAAiB,aAAa,SAAS;AAC7C,KAAI,OAAO,mBAAmB,YAAY,eAAe,SAAS,EACjE,QAAO;AAGR,KAAI,OAAO,aAAa,qBAAqB,YAAY;EACxD,MAAM,CAAC,WAAW,MAAM,aAAa,kBAAkB;AACvD,MAAI,OAAO,YAAY,YAAY,QAAQ,SAAS,EACnD,QAAO;;AAIT,KAAI,OAAO,aAAa,iBAAiB,YAAY;EACpD,MAAM,CAAC,WAAW,MAAM,aAAa,cAAc;AACnD,MAAI,OAAO,YAAY,YAAY,QAAQ,SAAS,EACnD,QAAO;;AAIT,OAAM,IAAI,MAAM,2CAA2C;;AAG5D,MAAa,mBAAmB,OAAO,WAAwC;AAC9E,KAAI,wBAAwB,OAAO,CAClC,QAAO,OAAO,YAAY;AAG3B,KAAI,qBAAqB,OAAO,CAC/B,QAAO,uBAAuB,OAAO;AAGtC,OAAM,IAAI,MAAM,0BAA0B;;AAG3C,MAAa,0BAA0B,OAAO,EAC7C,QACA,QACA,OACA,OACA,kBAOsB;AACtB,KAAI,wBAAwB,OAAO,CAElC,QAAO,OAAO,eAAe,QAAQ,OAAO,MAAM;AAGnD,KAAI,qBAAqB,OAAO,EAAE;EACjC,MAAMA,UAA6B,OAAO,WAAY,MAAM,uBAAuB,OAAO;AAC1F,SAAO,OAAO,cAAc;GAC3B;GACA;GACA;GACA;GACA,SAAS;GACT,CAAiD;;AAGnD,OAAM,IAAI,MAAM,0BAA0B"}