@nucypher/shared 0.6.0-alpha.1 → 0.6.0-alpha.3
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/cjs/taco-interfaces.d.ts +45 -0
- package/dist/cjs/taco-interfaces.js +3 -0
- package/dist/cjs/taco-interfaces.js.map +1 -0
- package/dist/cjs/viem/ethers-viem-utils.d.ts +45 -0
- package/dist/cjs/viem/ethers-viem-utils.js +108 -0
- package/dist/cjs/viem/ethers-viem-utils.js.map +1 -0
- package/dist/cjs/viem/type-guards.d.ts +10 -0
- package/dist/cjs/viem/type-guards.js +28 -0
- package/dist/cjs/viem/type-guards.js.map +1 -0
- package/dist/cjs/viem/types.d.ts +31 -0
- package/dist/cjs/viem/types.js +21 -0
- package/dist/cjs/viem/types.js.map +1 -0
- package/dist/es/taco-interfaces.d.ts +45 -0
- package/dist/es/taco-interfaces.js +2 -0
- package/dist/es/taco-interfaces.js.map +1 -0
- package/dist/es/viem/ethers-viem-utils.d.ts +45 -0
- package/dist/es/viem/ethers-viem-utils.js +101 -0
- package/dist/es/viem/ethers-viem-utils.js.map +1 -0
- package/dist/es/viem/type-guards.d.ts +10 -0
- package/dist/es/viem/type-guards.js +24 -0
- package/dist/es/viem/type-guards.js.map +1 -0
- package/dist/es/viem/types.d.ts +31 -0
- package/dist/es/viem/types.js +20 -0
- package/dist/es/viem/types.js.map +1 -0
- package/dist/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/tsconfig.es.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/dist/cjs/contracts/agents/signingCoordinator.d.ts +0 -14
- package/dist/cjs/contracts/agents/signingCoordinator.js +0 -32
- package/dist/cjs/contracts/agents/signingCoordinator.js.map +0 -1
- package/dist/es/contracts/agents/signingCoordinator.d.ts +0 -14
- package/dist/es/contracts/agents/signingCoordinator.js +0 -28
- package/dist/es/contracts/agents/signingCoordinator.js.map +0 -1
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { ethers } from 'ethers';
|
|
2
|
+
/**
|
|
3
|
+
* Basic TACo Provider interface
|
|
4
|
+
*
|
|
5
|
+
* This interface defines the minimal provider functionality needed for TACo operations.
|
|
6
|
+
* It contains only the methods that TACo actually uses.
|
|
7
|
+
* This interface is implemented by ViemTacoProvider. And any future provider implementation
|
|
8
|
+
* would need to implement this interface.
|
|
9
|
+
*/
|
|
10
|
+
export interface TacoProvider {
|
|
11
|
+
/**
|
|
12
|
+
* Ethers.js compatibility property for contract validation
|
|
13
|
+
*/
|
|
14
|
+
readonly _isProvider: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Get network information
|
|
17
|
+
*/
|
|
18
|
+
getNetwork(): Promise<ethers.providers.Network>;
|
|
19
|
+
/**
|
|
20
|
+
* Make a contract call
|
|
21
|
+
*/
|
|
22
|
+
call(transaction: ethers.providers.TransactionRequest): Promise<string>;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Basic TACo Signer interface
|
|
26
|
+
*
|
|
27
|
+
* This interface defines the minimal signer functionality needed for TACo operations.
|
|
28
|
+
* It contains only the methods that TACo actually uses.
|
|
29
|
+
* This interface is implemented by ViemTacoSigner. And any future signer implementation
|
|
30
|
+
* would need to implement this interface.
|
|
31
|
+
*/
|
|
32
|
+
export interface TacoSigner {
|
|
33
|
+
/**
|
|
34
|
+
* The provider this signer is connected to (optional for signing-only operations)
|
|
35
|
+
*/
|
|
36
|
+
readonly provider?: TacoProvider | undefined;
|
|
37
|
+
/**
|
|
38
|
+
* Get the address of this signer
|
|
39
|
+
*/
|
|
40
|
+
getAddress(): Promise<string>;
|
|
41
|
+
/**
|
|
42
|
+
* Sign a message
|
|
43
|
+
*/
|
|
44
|
+
signMessage(message: string | Uint8Array): Promise<string>;
|
|
45
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"taco-interfaces.js","sourceRoot":"","sources":["../../src/taco-interfaces.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { ethers } from 'ethers';
|
|
2
|
+
import { type TacoProvider, type TacoSigner } from '../taco-interfaces';
|
|
3
|
+
import { ProviderLike, SignerLike } from '../types';
|
|
4
|
+
import { type Account, type PublicClient } from './types';
|
|
5
|
+
/**
|
|
6
|
+
* Viem TACo Provider
|
|
7
|
+
*
|
|
8
|
+
* This class implements the TacoProvider interface directly using viem clients.
|
|
9
|
+
*/
|
|
10
|
+
export declare class ViemTacoProvider implements TacoProvider {
|
|
11
|
+
protected viemPublicClient: PublicClient;
|
|
12
|
+
readonly _isProvider = true;
|
|
13
|
+
readonly _network: Promise<ethers.providers.Network>;
|
|
14
|
+
constructor(viemPublicClient: PublicClient);
|
|
15
|
+
getNetwork(): Promise<ethers.providers.Network>;
|
|
16
|
+
call(transaction: ethers.providers.TransactionRequest): Promise<string>;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Viem TACo Signer
|
|
20
|
+
*
|
|
21
|
+
* This class implements the TacoSigner interface directly using viem accounts.
|
|
22
|
+
*/
|
|
23
|
+
export declare class ViemTacoSigner implements TacoSigner {
|
|
24
|
+
protected viemAccount: Account;
|
|
25
|
+
provider?: ethers.providers.Provider | undefined;
|
|
26
|
+
constructor(viemAccount: Account, providerLike?: ProviderLike | undefined);
|
|
27
|
+
getAddress(): Promise<string>;
|
|
28
|
+
signMessage(message: string | Uint8Array): Promise<string>;
|
|
29
|
+
connect(provider: ethers.providers.Provider): ethers.Signer;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Create a TACo provider from viem PublicClient
|
|
33
|
+
*
|
|
34
|
+
* This function creates a TacoProvider directly from a viem client.
|
|
35
|
+
*/
|
|
36
|
+
export declare function toEthersProvider(providerLike: ProviderLike): ethers.providers.Provider;
|
|
37
|
+
/**
|
|
38
|
+
* Create a TACo signer from viem Account
|
|
39
|
+
*
|
|
40
|
+
* This function creates a TacoSigner directly from a viem account.
|
|
41
|
+
*
|
|
42
|
+
* @param viemAccount - Viem account for signing operations
|
|
43
|
+
* @param provider - Optional TACo provider. If not provided, some operations will require a provider
|
|
44
|
+
*/
|
|
45
|
+
export declare function toEthersSigner(signerLike: SignerLike, providerLike?: ProviderLike): ethers.Signer;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ViemTacoSigner = exports.ViemTacoProvider = void 0;
|
|
4
|
+
exports.toEthersProvider = toEthersProvider;
|
|
5
|
+
exports.toEthersSigner = toEthersSigner;
|
|
6
|
+
const ethers_1 = require("ethers");
|
|
7
|
+
const type_guards_1 = require("./type-guards");
|
|
8
|
+
/**
|
|
9
|
+
* Viem TACo Provider
|
|
10
|
+
*
|
|
11
|
+
* This class implements the TacoProvider interface directly using viem clients.
|
|
12
|
+
*/
|
|
13
|
+
class ViemTacoProvider {
|
|
14
|
+
viemPublicClient;
|
|
15
|
+
// Ethers.js compatibility property for contract validation
|
|
16
|
+
_isProvider = true;
|
|
17
|
+
_network;
|
|
18
|
+
constructor(viemPublicClient) {
|
|
19
|
+
this.viemPublicClient = viemPublicClient;
|
|
20
|
+
// Initialize network for ethers compatibility
|
|
21
|
+
this._network = this.getNetwork();
|
|
22
|
+
}
|
|
23
|
+
async getNetwork() {
|
|
24
|
+
const chainId = await this.viemPublicClient.getChainId();
|
|
25
|
+
const name = this.viemPublicClient.chain?.name || `chain-${chainId}`;
|
|
26
|
+
return {
|
|
27
|
+
name,
|
|
28
|
+
chainId,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
async call(transaction) {
|
|
32
|
+
const result = await this.viemPublicClient.call({
|
|
33
|
+
to: transaction.to,
|
|
34
|
+
data: transaction.data,
|
|
35
|
+
value: transaction.value
|
|
36
|
+
? BigInt(transaction.value.toString())
|
|
37
|
+
: undefined,
|
|
38
|
+
});
|
|
39
|
+
if (typeof result === 'object' && result && 'data' in result) {
|
|
40
|
+
return result.data;
|
|
41
|
+
}
|
|
42
|
+
return result;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.ViemTacoProvider = ViemTacoProvider;
|
|
46
|
+
/**
|
|
47
|
+
* Viem TACo Signer
|
|
48
|
+
*
|
|
49
|
+
* This class implements the TacoSigner interface directly using viem accounts.
|
|
50
|
+
*/
|
|
51
|
+
class ViemTacoSigner {
|
|
52
|
+
viemAccount;
|
|
53
|
+
provider;
|
|
54
|
+
constructor(viemAccount, providerLike) {
|
|
55
|
+
this.viemAccount = viemAccount;
|
|
56
|
+
if (providerLike) {
|
|
57
|
+
this.provider = toEthersProvider(providerLike);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
async getAddress() {
|
|
61
|
+
return this.viemAccount.address;
|
|
62
|
+
}
|
|
63
|
+
async signMessage(message) {
|
|
64
|
+
if (!this.viemAccount.signMessage) {
|
|
65
|
+
throw new Error('Account does not support message signing');
|
|
66
|
+
}
|
|
67
|
+
const messageToSign = typeof message === 'string' ? message : ethers_1.ethers.utils.hexlify(message);
|
|
68
|
+
return await this.viemAccount.signMessage({ message: messageToSign });
|
|
69
|
+
}
|
|
70
|
+
connect(provider) {
|
|
71
|
+
this.provider = provider;
|
|
72
|
+
return this;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
exports.ViemTacoSigner = ViemTacoSigner;
|
|
76
|
+
/**
|
|
77
|
+
* Create a TACo provider from viem PublicClient
|
|
78
|
+
*
|
|
79
|
+
* This function creates a TacoProvider directly from a viem client.
|
|
80
|
+
*/
|
|
81
|
+
function toEthersProvider(providerLike) {
|
|
82
|
+
if ((0, type_guards_1.isViemClient)(providerLike)) {
|
|
83
|
+
return new ViemTacoProvider(providerLike);
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
return providerLike;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Create a TACo signer from viem Account
|
|
91
|
+
*
|
|
92
|
+
* This function creates a TacoSigner directly from a viem account.
|
|
93
|
+
*
|
|
94
|
+
* @param viemAccount - Viem account for signing operations
|
|
95
|
+
* @param provider - Optional TACo provider. If not provided, some operations will require a provider
|
|
96
|
+
*/
|
|
97
|
+
function toEthersSigner(signerLike, providerLike) {
|
|
98
|
+
const providerAdapter = providerLike
|
|
99
|
+
? toEthersProvider(providerLike)
|
|
100
|
+
: undefined;
|
|
101
|
+
if ((0, type_guards_1.isViemAccount)(signerLike)) {
|
|
102
|
+
return new ViemTacoSigner(signerLike, providerAdapter);
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
return signerLike;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=ethers-viem-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ethers-viem-utils.js","sourceRoot":"","sources":["../../../src/viem/ethers-viem-utils.ts"],"names":[],"mappings":";;;AA4FA,4CAUC;AAUD,wCAeC;AA/HD,mCAAgC;AAKhC,+CAA4D;AAG5D;;;;GAIG;AACH,MAAa,gBAAgB;IACjB,gBAAgB,CAAe;IAEzC,2DAA2D;IAClD,WAAW,GAAG,IAAI,CAAC;IACnB,QAAQ,CAAoC;IAErD,YAAY,gBAA8B;QACxC,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAC;QACzC,8CAA8C;QAC9C,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;IACpC,CAAC;IAED,KAAK,CAAC,UAAU;QACd,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,gBAAgB,CAAC,UAAU,EAAE,CAAC;QACzD,MAAM,IAAI,GAAG,IAAI,CAAC,gBAAgB,CAAC,KAAK,EAAE,IAAI,IAAI,SAAS,OAAO,EAAE,CAAC;QACrE,OAAO;YACL,IAAI;YACJ,OAAO;SACR,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,IAAI,CACR,WAAgD;QAEhD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC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C,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,OAAO,IAAgC,CAAC;IAC1C,CAAC;CACF;AA5BD,wCA4BC;AAED;;;;GAIG;AACH,SAAgB,gBAAgB,CAC9B,YAA0B;IAE1B,IAAI,IAAA,0BAAY,EAAC,YAAY,CAAC,EAAE,CAAC;QAC/B,OAAO,IAAI,gBAAgB,CACzB,YAAY,CAC2B,CAAC;IAC5C,CAAC;SAAM,CAAC;QACN,OAAO,YAAY,CAAC;IACtB,CAAC;AACH,CAAC;AAED;;;;;;;GAOG;AACH,SAAgB,cAAc,CAC5B,UAAsB,EACtB,YAA2B;IAE3B,MAAM,eAAe,GAAG,YAAY;QAClC,CAAC,CAAC,gBAAgB,CAAC,YAAY,CAAC;QAChC,CAAC,CAAC,SAAS,CAAC;IACd,IAAI,IAAA,2BAAa,EAAC,UAAU,CAAC,EAAE,CAAC;QAC9B,OAAO,IAAI,cAAc,CACvB,UAAU,EACV,eAAe,CACY,CAAC;IAChC,CAAC;SAAM,CAAC;QACN,OAAO,UAAsC,CAAC;IAChD,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ProviderLike, SignerLike } from '../types';
|
|
2
|
+
import { Account, PublicClient } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Type guard to determine if the client is a viem PublicClient
|
|
5
|
+
*/
|
|
6
|
+
export declare function isViemClient(providerLike: ProviderLike): providerLike is PublicClient;
|
|
7
|
+
/**
|
|
8
|
+
* Type guard to determine if the signer is a viem Account
|
|
9
|
+
*/
|
|
10
|
+
export declare function isViemAccount(signer: SignerLike): signer is Account;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isViemClient = isViemClient;
|
|
4
|
+
exports.isViemAccount = isViemAccount;
|
|
5
|
+
const ethers_1 = require("ethers");
|
|
6
|
+
/**
|
|
7
|
+
* Type guard to determine if the client is a viem PublicClient
|
|
8
|
+
*/
|
|
9
|
+
function isViemClient(providerLike) {
|
|
10
|
+
const hasViemProperties = 'chain' in providerLike;
|
|
11
|
+
const hasViemMethods = typeof providerLike
|
|
12
|
+
.getChainId === 'function';
|
|
13
|
+
const isNotEthersProvider = !(providerLike instanceof ethers_1.ethers.providers.BaseProvider);
|
|
14
|
+
return isNotEthersProvider && (hasViemProperties || hasViemMethods);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Type guard to determine if the signer is a viem Account
|
|
18
|
+
*/
|
|
19
|
+
function isViemAccount(signer) {
|
|
20
|
+
// Check for viem Account properties
|
|
21
|
+
const hasViemAccountProperties = 'address' in signer &&
|
|
22
|
+
typeof signer.address === 'string' &&
|
|
23
|
+
!('provider' in signer); // ethers.Signer has provider property
|
|
24
|
+
// Check if it's not an ethers.Signer
|
|
25
|
+
const isNotEthersSigner = !(signer instanceof ethers_1.ethers.Signer);
|
|
26
|
+
return isNotEthersSigner && hasViemAccountProperties;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=type-guards.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-guards.js","sourceRoot":"","sources":["../../../src/viem/type-guards.ts"],"names":[],"mappings":";;AASA,oCAYC;AAKD,sCAWC;AArCD,mCAAgC;AAMhC;;GAEG;AACH,SAAgB,YAAY,CAC1B,YAA0B;IAE1B,MAAM,iBAAiB,GAAG,OAAO,IAAI,YAAY,CAAC;IAClD,MAAM,cAAc,GAClB,OAAQ,YAAsD;SAC3D,UAAU,KAAK,UAAU,CAAC;IAC/B,MAAM,mBAAmB,GAAG,CAAC,CAC3B,YAAY,YAAY,eAAM,CAAC,SAAS,CAAC,YAAY,CACtD,CAAC;IAEF,OAAO,mBAAmB,IAAI,CAAC,iBAAiB,IAAI,cAAc,CAAC,CAAC;AACtE,CAAC;AAED;;GAEG;AACH,SAAgB,aAAa,CAAC,MAAkB;IAC9C,oCAAoC;IACpC,MAAM,wBAAwB,GAC5B,SAAS,IAAI,MAAM;QACnB,OAAQ,MAA8B,CAAC,OAAO,KAAK,QAAQ;QAC3D,CAAC,CAAC,UAAU,IAAI,MAAM,CAAC,CAAC,CAAC,sCAAsC;IAEjE,qCAAqC;IACrC,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,YAAY,eAAM,CAAC,MAAM,CAAC,CAAC;IAE7D,OAAO,iBAAiB,IAAI,wBAAwB,CAAC;AACvD,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared viem utilities for TACo packages
|
|
3
|
+
*
|
|
4
|
+
* Features:
|
|
5
|
+
* - Optional viem dependency handling with helpful error messages
|
|
6
|
+
* - Dynamic import pattern that's webpack-compatible
|
|
7
|
+
* - Centralized type definitions for viem objects
|
|
8
|
+
* - Runtime availability checking with caching
|
|
9
|
+
* - Common wrapper implementations for providers and signers
|
|
10
|
+
*
|
|
11
|
+
* Usage:
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { type PublicClient } from '@nucypher/shared';
|
|
14
|
+
*
|
|
15
|
+
* // Use viem clients directly with TACo adapters
|
|
16
|
+
* const tacoProvider = await toEthersProvider(viemPublicClient);
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
type _ViemPublicClient = import('viem').PublicClient;
|
|
20
|
+
type _ViemAccount = import('viem').Account;
|
|
21
|
+
/**
|
|
22
|
+
* Viem PublicClient type for read operations
|
|
23
|
+
* @see https://viem.sh/docs/clients/public
|
|
24
|
+
*/
|
|
25
|
+
export type PublicClient = [unknown] extends [_ViemPublicClient] ? any : _ViemPublicClient;
|
|
26
|
+
/**
|
|
27
|
+
* Viem Account type for signing operations
|
|
28
|
+
* @see https://viem.sh/docs/accounts/privateKey
|
|
29
|
+
*/
|
|
30
|
+
export type Account = [unknown] extends [_ViemAccount] ? any : _ViemAccount;
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Shared viem utilities for TACo packages
|
|
4
|
+
*
|
|
5
|
+
* Features:
|
|
6
|
+
* - Optional viem dependency handling with helpful error messages
|
|
7
|
+
* - Dynamic import pattern that's webpack-compatible
|
|
8
|
+
* - Centralized type definitions for viem objects
|
|
9
|
+
* - Runtime availability checking with caching
|
|
10
|
+
* - Common wrapper implementations for providers and signers
|
|
11
|
+
*
|
|
12
|
+
* Usage:
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { type PublicClient } from '@nucypher/shared';
|
|
15
|
+
*
|
|
16
|
+
* // Use viem clients directly with TACo adapters
|
|
17
|
+
* const tacoProvider = await toEthersProvider(viemPublicClient);
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/viem/types.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { ethers } from 'ethers';
|
|
2
|
+
/**
|
|
3
|
+
* Basic TACo Provider interface
|
|
4
|
+
*
|
|
5
|
+
* This interface defines the minimal provider functionality needed for TACo operations.
|
|
6
|
+
* It contains only the methods that TACo actually uses.
|
|
7
|
+
* This interface is implemented by ViemTacoProvider. And any future provider implementation
|
|
8
|
+
* would need to implement this interface.
|
|
9
|
+
*/
|
|
10
|
+
export interface TacoProvider {
|
|
11
|
+
/**
|
|
12
|
+
* Ethers.js compatibility property for contract validation
|
|
13
|
+
*/
|
|
14
|
+
readonly _isProvider: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Get network information
|
|
17
|
+
*/
|
|
18
|
+
getNetwork(): Promise<ethers.providers.Network>;
|
|
19
|
+
/**
|
|
20
|
+
* Make a contract call
|
|
21
|
+
*/
|
|
22
|
+
call(transaction: ethers.providers.TransactionRequest): Promise<string>;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Basic TACo Signer interface
|
|
26
|
+
*
|
|
27
|
+
* This interface defines the minimal signer functionality needed for TACo operations.
|
|
28
|
+
* It contains only the methods that TACo actually uses.
|
|
29
|
+
* This interface is implemented by ViemTacoSigner. And any future signer implementation
|
|
30
|
+
* would need to implement this interface.
|
|
31
|
+
*/
|
|
32
|
+
export interface TacoSigner {
|
|
33
|
+
/**
|
|
34
|
+
* The provider this signer is connected to (optional for signing-only operations)
|
|
35
|
+
*/
|
|
36
|
+
readonly provider?: TacoProvider | undefined;
|
|
37
|
+
/**
|
|
38
|
+
* Get the address of this signer
|
|
39
|
+
*/
|
|
40
|
+
getAddress(): Promise<string>;
|
|
41
|
+
/**
|
|
42
|
+
* Sign a message
|
|
43
|
+
*/
|
|
44
|
+
signMessage(message: string | Uint8Array): Promise<string>;
|
|
45
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"taco-interfaces.js","sourceRoot":"","sources":["../../src/taco-interfaces.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { ethers } from 'ethers';
|
|
2
|
+
import { type TacoProvider, type TacoSigner } from '../taco-interfaces';
|
|
3
|
+
import { ProviderLike, SignerLike } from '../types';
|
|
4
|
+
import { type Account, type PublicClient } from './types';
|
|
5
|
+
/**
|
|
6
|
+
* Viem TACo Provider
|
|
7
|
+
*
|
|
8
|
+
* This class implements the TacoProvider interface directly using viem clients.
|
|
9
|
+
*/
|
|
10
|
+
export declare class ViemTacoProvider implements TacoProvider {
|
|
11
|
+
protected viemPublicClient: PublicClient;
|
|
12
|
+
readonly _isProvider = true;
|
|
13
|
+
readonly _network: Promise<ethers.providers.Network>;
|
|
14
|
+
constructor(viemPublicClient: PublicClient);
|
|
15
|
+
getNetwork(): Promise<ethers.providers.Network>;
|
|
16
|
+
call(transaction: ethers.providers.TransactionRequest): Promise<string>;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Viem TACo Signer
|
|
20
|
+
*
|
|
21
|
+
* This class implements the TacoSigner interface directly using viem accounts.
|
|
22
|
+
*/
|
|
23
|
+
export declare class ViemTacoSigner implements TacoSigner {
|
|
24
|
+
protected viemAccount: Account;
|
|
25
|
+
provider?: ethers.providers.Provider | undefined;
|
|
26
|
+
constructor(viemAccount: Account, providerLike?: ProviderLike | undefined);
|
|
27
|
+
getAddress(): Promise<string>;
|
|
28
|
+
signMessage(message: string | Uint8Array): Promise<string>;
|
|
29
|
+
connect(provider: ethers.providers.Provider): ethers.Signer;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Create a TACo provider from viem PublicClient
|
|
33
|
+
*
|
|
34
|
+
* This function creates a TacoProvider directly from a viem client.
|
|
35
|
+
*/
|
|
36
|
+
export declare function toEthersProvider(providerLike: ProviderLike): ethers.providers.Provider;
|
|
37
|
+
/**
|
|
38
|
+
* Create a TACo signer from viem Account
|
|
39
|
+
*
|
|
40
|
+
* This function creates a TacoSigner directly from a viem account.
|
|
41
|
+
*
|
|
42
|
+
* @param viemAccount - Viem account for signing operations
|
|
43
|
+
* @param provider - Optional TACo provider. If not provided, some operations will require a provider
|
|
44
|
+
*/
|
|
45
|
+
export declare function toEthersSigner(signerLike: SignerLike, providerLike?: ProviderLike): ethers.Signer;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { ethers } from 'ethers';
|
|
2
|
+
import { isViemAccount, isViemClient } from './type-guards';
|
|
3
|
+
/**
|
|
4
|
+
* Viem TACo Provider
|
|
5
|
+
*
|
|
6
|
+
* This class implements the TacoProvider interface directly using viem clients.
|
|
7
|
+
*/
|
|
8
|
+
export class ViemTacoProvider {
|
|
9
|
+
viemPublicClient;
|
|
10
|
+
// Ethers.js compatibility property for contract validation
|
|
11
|
+
_isProvider = true;
|
|
12
|
+
_network;
|
|
13
|
+
constructor(viemPublicClient) {
|
|
14
|
+
this.viemPublicClient = viemPublicClient;
|
|
15
|
+
// Initialize network for ethers compatibility
|
|
16
|
+
this._network = this.getNetwork();
|
|
17
|
+
}
|
|
18
|
+
async getNetwork() {
|
|
19
|
+
const chainId = await this.viemPublicClient.getChainId();
|
|
20
|
+
const name = this.viemPublicClient.chain?.name || `chain-${chainId}`;
|
|
21
|
+
return {
|
|
22
|
+
name,
|
|
23
|
+
chainId,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
async call(transaction) {
|
|
27
|
+
const result = await this.viemPublicClient.call({
|
|
28
|
+
to: transaction.to,
|
|
29
|
+
data: transaction.data,
|
|
30
|
+
value: transaction.value
|
|
31
|
+
? BigInt(transaction.value.toString())
|
|
32
|
+
: undefined,
|
|
33
|
+
});
|
|
34
|
+
if (typeof result === 'object' && result && 'data' in result) {
|
|
35
|
+
return result.data;
|
|
36
|
+
}
|
|
37
|
+
return result;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Viem TACo Signer
|
|
42
|
+
*
|
|
43
|
+
* This class implements the TacoSigner interface directly using viem accounts.
|
|
44
|
+
*/
|
|
45
|
+
export class ViemTacoSigner {
|
|
46
|
+
viemAccount;
|
|
47
|
+
provider;
|
|
48
|
+
constructor(viemAccount, providerLike) {
|
|
49
|
+
this.viemAccount = viemAccount;
|
|
50
|
+
if (providerLike) {
|
|
51
|
+
this.provider = toEthersProvider(providerLike);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
async getAddress() {
|
|
55
|
+
return this.viemAccount.address;
|
|
56
|
+
}
|
|
57
|
+
async signMessage(message) {
|
|
58
|
+
if (!this.viemAccount.signMessage) {
|
|
59
|
+
throw new Error('Account does not support message signing');
|
|
60
|
+
}
|
|
61
|
+
const messageToSign = typeof message === 'string' ? message : ethers.utils.hexlify(message);
|
|
62
|
+
return await this.viemAccount.signMessage({ message: messageToSign });
|
|
63
|
+
}
|
|
64
|
+
connect(provider) {
|
|
65
|
+
this.provider = provider;
|
|
66
|
+
return this;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Create a TACo provider from viem PublicClient
|
|
71
|
+
*
|
|
72
|
+
* This function creates a TacoProvider directly from a viem client.
|
|
73
|
+
*/
|
|
74
|
+
export function toEthersProvider(providerLike) {
|
|
75
|
+
if (isViemClient(providerLike)) {
|
|
76
|
+
return new ViemTacoProvider(providerLike);
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
return providerLike;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Create a TACo signer from viem Account
|
|
84
|
+
*
|
|
85
|
+
* This function creates a TacoSigner directly from a viem account.
|
|
86
|
+
*
|
|
87
|
+
* @param viemAccount - Viem account for signing operations
|
|
88
|
+
* @param provider - Optional TACo provider. If not provided, some operations will require a provider
|
|
89
|
+
*/
|
|
90
|
+
export function toEthersSigner(signerLike, providerLike) {
|
|
91
|
+
const providerAdapter = providerLike
|
|
92
|
+
? toEthersProvider(providerLike)
|
|
93
|
+
: undefined;
|
|
94
|
+
if (isViemAccount(signerLike)) {
|
|
95
|
+
return new ViemTacoSigner(signerLike, providerAdapter);
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
return signerLike;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=ethers-viem-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ethers-viem-utils.js","sourceRoot":"","sources":["../../../src/viem/ethers-viem-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAKhC,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAG5D;;;;GAIG;AACH,MAAM,OAAO,gBAAgB;IACjB,gBAAgB,CAAe;IAEzC,2DAA2D;IAClD,WAAW,GAAG,IAAI,CAAC;IACnB,QAAQ,CAAoC;IAErD,Y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
|
3
|
+
/**
|
|
4
|
+
* Type guard to determine if the client is a viem PublicClient
|
|
5
|
+
*/
|
|
6
|
+
export declare function isViemClient(providerLike: ProviderLike): providerLike is PublicClient;
|
|
7
|
+
/**
|
|
8
|
+
* Type guard to determine if the signer is a viem Account
|
|
9
|
+
*/
|
|
10
|
+
export declare function isViemAccount(signer: SignerLike): signer is Account;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ethers } from 'ethers';
|
|
2
|
+
/**
|
|
3
|
+
* Type guard to determine if the client is a viem PublicClient
|
|
4
|
+
*/
|
|
5
|
+
export function isViemClient(providerLike) {
|
|
6
|
+
const hasViemProperties = 'chain' in providerLike;
|
|
7
|
+
const hasViemMethods = typeof providerLike
|
|
8
|
+
.getChainId === 'function';
|
|
9
|
+
const isNotEthersProvider = !(providerLike instanceof ethers.providers.BaseProvider);
|
|
10
|
+
return isNotEthersProvider && (hasViemProperties || hasViemMethods);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Type guard to determine if the signer is a viem Account
|
|
14
|
+
*/
|
|
15
|
+
export function isViemAccount(signer) {
|
|
16
|
+
// Check for viem Account properties
|
|
17
|
+
const hasViemAccountProperties = 'address' in signer &&
|
|
18
|
+
typeof signer.address === 'string' &&
|
|
19
|
+
!('provider' in signer); // ethers.Signer has provider property
|
|
20
|
+
// Check if it's not an ethers.Signer
|
|
21
|
+
const isNotEthersSigner = !(signer instanceof ethers.Signer);
|
|
22
|
+
return isNotEthersSigner && hasViemAccountProperties;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=type-guards.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-guards.js","sourceRoot":"","sources":["../../../src/viem/type-guards.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAMhC;;GAEG;AACH,MAAM,UAAU,YAAY,CAC1B,YAA0B;IAE1B,MAAM,iBAAiB,GAAG,OAAO,IAAI,YAAY,CAAC;IAClD,MAAM,cAAc,GAClB,OAAQ,YAAsD;SAC3D,UAAU,KAAK,UAAU,CAAC;IAC/B,MAAM,mBAAmB,GAAG,CAAC,CAC3B,YAAY,YAAY,MAAM,CAAC,SAAS,CAAC,YAAY,CACtD,CAAC;IAEF,OAAO,mBAAmB,IAAI,CAAC,iBAAiB,IAAI,cAAc,CAAC,CAAC;AACtE,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,MAAkB;IAC9C,oCAAoC;IACpC,MAAM,wBAAwB,GAC5B,SAAS,IAAI,MAAM;QACnB,OAAQ,MAA8B,CAAC,OAAO,KAAK,QAAQ;QAC3D,CAAC,CAAC,UAAU,IAAI,MAAM,CAAC,CAAC,CAAC,sCAAsC;IAEjE,qCAAqC;IACrC,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,YAAY,MAAM,CAAC,MAAM,CAAC,CAAC;IAE7D,OAAO,iBAAiB,IAAI,wBAAwB,CAAC;AACvD,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared viem utilities for TACo packages
|
|
3
|
+
*
|
|
4
|
+
* Features:
|
|
5
|
+
* - Optional viem dependency handling with helpful error messages
|
|
6
|
+
* - Dynamic import pattern that's webpack-compatible
|
|
7
|
+
* - Centralized type definitions for viem objects
|
|
8
|
+
* - Runtime availability checking with caching
|
|
9
|
+
* - Common wrapper implementations for providers and signers
|
|
10
|
+
*
|
|
11
|
+
* Usage:
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { type PublicClient } from '@nucypher/shared';
|
|
14
|
+
*
|
|
15
|
+
* // Use viem clients directly with TACo adapters
|
|
16
|
+
* const tacoProvider = await toEthersProvider(viemPublicClient);
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
type _ViemPublicClient = import('viem').PublicClient;
|
|
20
|
+
type _ViemAccount = import('viem').Account;
|
|
21
|
+
/**
|
|
22
|
+
* Viem PublicClient type for read operations
|
|
23
|
+
* @see https://viem.sh/docs/clients/public
|
|
24
|
+
*/
|
|
25
|
+
export type PublicClient = [unknown] extends [_ViemPublicClient] ? any : _ViemPublicClient;
|
|
26
|
+
/**
|
|
27
|
+
* Viem Account type for signing operations
|
|
28
|
+
* @see https://viem.sh/docs/accounts/privateKey
|
|
29
|
+
*/
|
|
30
|
+
export type Account = [unknown] extends [_ViemAccount] ? any : _ViemAccount;
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared viem utilities for TACo packages
|
|
3
|
+
*
|
|
4
|
+
* Features:
|
|
5
|
+
* - Optional viem dependency handling with helpful error messages
|
|
6
|
+
* - Dynamic import pattern that's webpack-compatible
|
|
7
|
+
* - Centralized type definitions for viem objects
|
|
8
|
+
* - Runtime availability checking with caching
|
|
9
|
+
* - Common wrapper implementations for providers and signers
|
|
10
|
+
*
|
|
11
|
+
* Usage:
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { type PublicClient } from '@nucypher/shared';
|
|
14
|
+
*
|
|
15
|
+
* // Use viem clients directly with TACo adapters
|
|
16
|
+
* const tacoProvider = await toEthersProvider(viemPublicClient);
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export {};
|
|
20
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/viem/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG"}
|