@relayprotocol/relay-bitcoin-wallet-adapter 10.0.0

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.
@@ -0,0 +1 @@
1
+ {"type": "module","sideEffects":false}
@@ -0,0 +1,52 @@
1
+ import { LogLevel, axios, getClient } from '@relayprotocol/relay-sdk';
2
+ import * as bitcoin from 'bitcoinjs-lib';
3
+ export const adaptBitcoinWallet = (walletAddress, signPsbt) => {
4
+ return {
5
+ vmType: 'bvm',
6
+ getChainId: async () => {
7
+ return 8253038;
8
+ },
9
+ address: async () => {
10
+ return walletAddress;
11
+ },
12
+ handleSignMessageStep: async () => {
13
+ throw new Error('Message signing not implemented for Bitcoin');
14
+ },
15
+ handleSendTransactionStep: async (_chainId, stepItem) => {
16
+ const client = getClient();
17
+ const psbtHex = stepItem.data.psbt;
18
+ const psbt = bitcoin.Psbt.fromHex(psbtHex, {
19
+ network: bitcoin.networks.bitcoin
20
+ });
21
+ const signature = psbt.txInputs.map((_input, index) => {
22
+ return {
23
+ address: walletAddress,
24
+ signingIndexes: [index]
25
+ };
26
+ });
27
+ const dynamicParams = {
28
+ allowedSighash: [1], // Only allow SIGHASH_ALL
29
+ unsignedPsbtBase64: psbt.toBase64(), // The unsigned PSBT in Base64 format
30
+ signature
31
+ };
32
+ const signedPsbt = bitcoin.Psbt.fromBase64(await signPsbt(walletAddress, psbt, dynamicParams));
33
+ signedPsbt.finalizeAllInputs();
34
+ const rawTransaction = signedPsbt.extractTransaction().toHex();
35
+ client.log(['BTC Transaction', rawTransaction], LogLevel.Verbose);
36
+ const mempoolResponse = await axios
37
+ .post('https://mempool.space/api/tx', rawTransaction)
38
+ .then((r) => r.data);
39
+ client.log(['Transaction Broadcasted', mempoolResponse], LogLevel.Verbose);
40
+ return mempoolResponse;
41
+ },
42
+ //Bitcoin txs can take 10m or more to finalize, in the case of chains that have a long block time (2m+), the SDK will skip waiting for confirmation
43
+ handleConfirmTransactionStep: async () => {
44
+ throw 'Not implemented';
45
+ },
46
+ //@ts-ignore
47
+ switchChain: (chainId) => {
48
+ throw 'Not yet implemented';
49
+ }
50
+ };
51
+ };
52
+ //# sourceMappingURL=adapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adapter.js","sourceRoot":"","sources":["../../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,KAAK,EACL,SAAS,EAEV,MAAM,0BAA0B,CAAA;AACjC,OAAO,KAAK,OAAO,MAAM,eAAe,CAAA;AAWxC,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAChC,aAAqB,EACrB,QAIoB,EACL,EAAE;IACjB,OAAO;QACL,MAAM,EAAE,KAAK;QACb,UAAU,EAAE,KAAK,IAAI,EAAE;YACrB,OAAO,OAAO,CAAA;QAChB,CAAC;QACD,OAAO,EAAE,KAAK,IAAI,EAAE;YAClB,OAAO,aAAa,CAAA;QACtB,CAAC;QACD,qBAAqB,EAAE,KAAK,IAAI,EAAE;YAChC,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAA;QAChE,CAAC;QACD,yBAAyB,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,EAAE;YACtD,MAAM,MAAM,GAAG,SAAS,EAAE,CAAA;YAE1B,MAAM,OAAO,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAc,CAAA;YAE5C,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE;gBACzC,OAAO,EAAE,OAAO,CAAC,QAAQ,CAAC,OAAO;aAClC,CAAC,CAAA;YAEF,MAAM,SAAS,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE;gBACpD,OAAO;oBACL,OAAO,EAAE,aAAa;oBACtB,cAAc,EAAE,CAAC,KAAK,CAAC;iBACxB,CAAA;YACH,CAAC,CAAC,CAAA;YAEF,MAAM,aAAa,GAA0B;gBAC3C,cAAc,EAAE,CAAC,CAAC,CAAC,EAAE,yBAAyB;gBAC9C,kBAAkB,EAAE,IAAI,CAAC,QAAQ,EAAE,EAAE,qCAAqC;gBAC1E,SAAS;aACV,CAAA;YAED,MAAM,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,UAAU,CACxC,MAAM,QAAQ,CAAC,aAAa,EAAE,IAAI,EAAE,aAAa,CAAC,CACnD,CAAA;YACD,UAAU,CAAC,iBAAiB,EAAE,CAAA;YAE9B,MAAM,cAAc,GAAG,UAAU,CAAC,kBAAkB,EAAE,CAAC,KAAK,EAAE,CAAA;YAC9D,MAAM,CAAC,GAAG,CAAC,CAAC,iBAAiB,EAAE,cAAc,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAA;YACjE,MAAM,eAAe,GAAG,MAAM,KAAK;iBAChC,IAAI,CAAC,8BAA8B,EAAE,cAAc,CAAC;iBACpD,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAA;YACtB,MAAM,CAAC,GAAG,CAAC,CAAC,yBAAyB,EAAE,eAAe,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAA;YAC1E,OAAO,eAAe,CAAA;QACxB,CAAC;QACD,mJAAmJ;QACnJ,4BAA4B,EAAE,KAAK,IAAI,EAAE;YACvC,MAAM,iBAAiB,CAAA;QACzB,CAAC;QACD,YAAY;QACZ,WAAW,EAAE,CAAC,OAAe,EAAE,EAAE;YAC/B,MAAM,qBAAqB,CAAA;QAC7B,CAAC;KACF,CAAA;AACH,CAAC,CAAA"}
@@ -0,0 +1,2 @@
1
+ export * from './adapter.js';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA"}