@aztec/wallet-sdk 0.0.1-commit.f504929 → 0.0.1-commit.f650c0a5c
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/dest/base-wallet/base_wallet.d.ts +33 -37
- package/dest/base-wallet/base_wallet.d.ts.map +1 -1
- package/dest/base-wallet/base_wallet.js +99 -70
- package/dest/base-wallet/index.d.ts +2 -2
- package/dest/base-wallet/index.d.ts.map +1 -1
- package/dest/crypto.d.ts +39 -1
- package/dest/crypto.d.ts.map +1 -1
- package/dest/crypto.js +88 -0
- package/dest/extension/provider/extension_wallet.d.ts +2 -5
- package/dest/extension/provider/extension_wallet.d.ts.map +1 -1
- package/dest/extension/provider/index.d.ts +2 -2
- package/dest/extension/provider/index.d.ts.map +1 -1
- package/dest/iframe/handlers/iframe_connection_handler.d.ts +118 -0
- package/dest/iframe/handlers/iframe_connection_handler.d.ts.map +1 -0
- package/dest/iframe/handlers/iframe_connection_handler.js +228 -0
- package/dest/iframe/handlers/index.d.ts +2 -0
- package/dest/iframe/handlers/index.d.ts.map +1 -0
- package/dest/iframe/handlers/index.js +1 -0
- package/dest/iframe/provider/iframe_discovery.d.ts +25 -0
- package/dest/iframe/provider/iframe_discovery.d.ts.map +1 -0
- package/dest/iframe/provider/iframe_discovery.js +167 -0
- package/dest/iframe/provider/iframe_provider.d.ts +65 -0
- package/dest/iframe/provider/iframe_provider.d.ts.map +1 -0
- package/dest/iframe/provider/iframe_provider.js +257 -0
- package/dest/iframe/provider/iframe_wallet.d.ts +68 -0
- package/dest/iframe/provider/iframe_wallet.d.ts.map +1 -0
- package/dest/iframe/provider/iframe_wallet.js +200 -0
- package/dest/iframe/provider/index.d.ts +4 -0
- package/dest/iframe/provider/index.d.ts.map +1 -0
- package/dest/iframe/provider/index.js +3 -0
- package/dest/manager/types.d.ts +3 -2
- package/dest/manager/types.d.ts.map +1 -1
- package/dest/manager/wallet_manager.d.ts +1 -1
- package/dest/manager/wallet_manager.d.ts.map +1 -1
- package/dest/manager/wallet_manager.js +46 -16
- package/dest/types.d.ts +14 -2
- package/dest/types.d.ts.map +1 -1
- package/dest/types.js +4 -0
- package/package.json +12 -8
- package/src/base-wallet/base_wallet.ts +165 -124
- package/src/base-wallet/index.ts +6 -1
- package/src/crypto.ts +104 -0
- package/src/extension/provider/extension_wallet.ts +1 -6
- package/src/extension/provider/index.ts +1 -1
- package/src/iframe/handlers/iframe_connection_handler.ts +328 -0
- package/src/iframe/handlers/index.ts +7 -0
- package/src/iframe/provider/iframe_discovery.ts +185 -0
- package/src/iframe/provider/iframe_provider.ts +331 -0
- package/src/iframe/provider/iframe_wallet.ts +229 -0
- package/src/iframe/provider/index.ts +3 -0
- package/src/manager/types.ts +2 -1
- package/src/manager/wallet_manager.ts +48 -14
- package/src/types.ts +13 -0
|
@@ -67,4 +67,4 @@ export declare class WalletManager {
|
|
|
67
67
|
*/
|
|
68
68
|
private isExtensionAllowed;
|
|
69
69
|
}
|
|
70
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
70
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoid2FsbGV0X21hbmFnZXIuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9tYW5hZ2VyL3dhbGxldF9tYW5hZ2VyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQU1BLE9BQU8sS0FBSyxFQUNWLHNCQUFzQixFQUN0QixnQkFBZ0IsRUFJaEIsbUJBQW1CLEVBRXBCLE1BQU0sWUFBWSxDQUFDO0FBRXBCOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7R0E4Qkc7QUFDSCxxQkFBYSxhQUFhO0lBQ3hCLE9BQU8sQ0FBQyxNQUFNLENBR1o7SUFFRixPQUFPLGVBQWlCO0lBRXhCOzs7T0FHRztJQUNILE1BQU0sQ0FBQyxTQUFTLENBQUMsTUFBTSxFQUFFLG1CQUFtQixHQUFHLGFBQWEsQ0FPM0Q7SUFFRDs7Ozs7Ozs7Ozs7O09BWUc7SUFDSCxtQkFBbUIsQ0FBQyxPQUFPLEVBQUUsc0JBQXNCLEdBQUcsZ0JBQWdCLENBOEdyRTtJQUVEOzs7Ozs7T0FNRztJQUNILE9BQU8sQ0FBQyxrQ0FBa0M7SUEwRTFDOzs7O09BSUc7SUFDSCxPQUFPLENBQUMsa0JBQWtCO0NBVzNCIn0=
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wallet_manager.d.ts","sourceRoot":"","sources":["../../src/manager/wallet_manager.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"wallet_manager.d.ts","sourceRoot":"","sources":["../../src/manager/wallet_manager.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,sBAAsB,EACtB,gBAAgB,EAIhB,mBAAmB,EAEpB,MAAM,YAAY,CAAC;AAEpB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,MAAM,CAGZ;IAEF,OAAO,eAAiB;IAExB;;;OAGG;IACH,MAAM,CAAC,SAAS,CAAC,MAAM,EAAE,mBAAmB,GAAG,aAAa,CAO3D;IAED;;;;;;;;;;;;OAYG;IACH,mBAAmB,CAAC,OAAO,EAAE,sBAAsB,GAAG,gBAAgB,CA8GrE;IAED;;;;;;OAMG;IACH,OAAO,CAAC,kCAAkC;IA0E1C;;;;OAIG;IACH,OAAO,CAAC,kBAAkB;CAW3B"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { promiseWithResolvers } from '@aztec/foundation/promise';
|
|
2
2
|
import { ExtensionProvider, ExtensionWallet } from '../extension/provider/index.js';
|
|
3
|
+
import { discoverWebWallets } from '../iframe/provider/iframe_discovery.js';
|
|
3
4
|
import { WalletMessageType } from '../types.js';
|
|
4
5
|
/**
|
|
5
6
|
* Manager for wallet discovery, configuration, and connection.
|
|
@@ -75,6 +76,20 @@ import { WalletMessageType } from '../types.js';
|
|
|
75
76
|
let pendingResolve = null;
|
|
76
77
|
let completed = false;
|
|
77
78
|
const { promise: donePromise, resolve: resolveDone } = promiseWithResolvers();
|
|
79
|
+
const pendingSources = new Set();
|
|
80
|
+
const emit = (provider)=>{
|
|
81
|
+
options.onWalletDiscovered?.(provider);
|
|
82
|
+
if (pendingResolve) {
|
|
83
|
+
const resolve = pendingResolve;
|
|
84
|
+
pendingResolve = null;
|
|
85
|
+
resolve({
|
|
86
|
+
value: provider,
|
|
87
|
+
done: false
|
|
88
|
+
});
|
|
89
|
+
} else {
|
|
90
|
+
pendingProviders.push(provider);
|
|
91
|
+
}
|
|
92
|
+
};
|
|
78
93
|
const markComplete = ()=>{
|
|
79
94
|
completed = true;
|
|
80
95
|
resolveDone();
|
|
@@ -87,7 +102,14 @@ import { WalletMessageType } from '../types.js';
|
|
|
87
102
|
});
|
|
88
103
|
}
|
|
89
104
|
};
|
|
105
|
+
const sourceComplete = (source)=>{
|
|
106
|
+
pendingSources.delete(source);
|
|
107
|
+
if (pendingSources.size === 0) {
|
|
108
|
+
markComplete();
|
|
109
|
+
}
|
|
110
|
+
};
|
|
90
111
|
if (this.config.extensions?.enabled) {
|
|
112
|
+
pendingSources.add('extensions');
|
|
91
113
|
const extensionConfig = this.config.extensions;
|
|
92
114
|
void ExtensionProvider.discoverWallets(chainInfo, {
|
|
93
115
|
appId,
|
|
@@ -95,25 +117,33 @@ import { WalletMessageType } from '../types.js';
|
|
|
95
117
|
signal: abortController.signal,
|
|
96
118
|
onWalletDiscovered: (discoveredWallet)=>{
|
|
97
119
|
const provider = this.createProviderFromDiscoveredWallet(discoveredWallet, chainInfo, extensionConfig);
|
|
98
|
-
if (
|
|
99
|
-
|
|
120
|
+
if (provider) {
|
|
121
|
+
emit(provider);
|
|
100
122
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
123
|
+
}
|
|
124
|
+
}).then(()=>sourceComplete('extensions'));
|
|
125
|
+
}
|
|
126
|
+
if (this.config.webWallets?.urls && this.config.webWallets.urls.length > 0) {
|
|
127
|
+
pendingSources.add('webWallets');
|
|
128
|
+
const webSession = discoverWebWallets(this.config.webWallets.urls, chainInfo);
|
|
129
|
+
// Forward discovered web wallets into the shared iterator
|
|
130
|
+
void (async ()=>{
|
|
131
|
+
try {
|
|
132
|
+
for await (const provider of webSession.wallets){
|
|
133
|
+
if (abortController.signal.aborted) {
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
emit(provider);
|
|
113
137
|
}
|
|
138
|
+
} finally{
|
|
139
|
+
sourceComplete('webWallets');
|
|
114
140
|
}
|
|
115
|
-
})
|
|
116
|
-
|
|
141
|
+
})();
|
|
142
|
+
abortController.signal.addEventListener('abort', ()=>webSession.cancel(), {
|
|
143
|
+
once: true
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
if (pendingSources.size === 0) {
|
|
117
147
|
markComplete();
|
|
118
148
|
}
|
|
119
149
|
const wallets = {
|
package/dest/types.d.ts
CHANGED
|
@@ -14,7 +14,15 @@ export declare enum WalletMessageType {
|
|
|
14
14
|
/** Key exchange request sent over MessageChannel */
|
|
15
15
|
KEY_EXCHANGE_REQUEST = "aztec-wallet-key-exchange-request",
|
|
16
16
|
/** Key exchange response sent over MessageChannel */
|
|
17
|
-
KEY_EXCHANGE_RESPONSE = "aztec-wallet-key-exchange-response"
|
|
17
|
+
KEY_EXCHANGE_RESPONSE = "aztec-wallet-key-exchange-response",
|
|
18
|
+
/** Wallet ready signal */
|
|
19
|
+
WALLET_READY = "aztec-wallet-ready",
|
|
20
|
+
/** Encrypted wallet message wrapper */
|
|
21
|
+
SECURE_MESSAGE = "aztec-wallet-secure-message",
|
|
22
|
+
/** Encrypted wallet response wrapper */
|
|
23
|
+
SECURE_RESPONSE = "aztec-wallet-secure-response",
|
|
24
|
+
/** Session disconnected notification */
|
|
25
|
+
SESSION_DISCONNECTED = "aztec-wallet-session-disconnected"
|
|
18
26
|
}
|
|
19
27
|
/**
|
|
20
28
|
* Information about an installed Aztec wallet.
|
|
@@ -120,4 +128,8 @@ export interface KeyExchangeResponse {
|
|
|
120
128
|
/** Wallet's ECDH public key for deriving shared secret */
|
|
121
129
|
publicKey: ExportedPublicKey;
|
|
122
130
|
}
|
|
123
|
-
|
|
131
|
+
/**
|
|
132
|
+
* Callback invoked when a wallet connection is disconnected.
|
|
133
|
+
*/
|
|
134
|
+
export type DisconnectCallback = () => void;
|
|
135
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHlwZXMuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3NyYy90eXBlcy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxTQUFTLEVBQUUsTUFBTSx5QkFBeUIsQ0FBQztBQUV6RCxPQUFPLEtBQUssRUFBRSxpQkFBaUIsRUFBRSxNQUFNLGFBQWEsQ0FBQztBQUVyRDs7O0dBR0c7QUFDSCxvQkFBWSxpQkFBaUI7SUFDM0Isa0RBQWtEO0lBQ2xELFNBQVMsMkJBQTJCO0lBQ3BDLHVDQUF1QztJQUN2QyxrQkFBa0Isb0NBQW9DO0lBQ3RELHNFQUFzRTtJQUN0RSxVQUFVLDRCQUE0QjtJQUN0QyxvREFBb0Q7SUFDcEQsb0JBQW9CLHNDQUFzQztJQUMxRCxxREFBcUQ7SUFDckQscUJBQXFCLHVDQUF1QztJQUM1RCwwQkFBMEI7SUFDMUIsWUFBWSx1QkFBdUI7SUFDbkMsdUNBQXVDO0lBQ3ZDLGNBQWMsZ0NBQWdDO0lBQzlDLHdDQUF3QztJQUN4QyxlQUFlLGlDQUFpQztJQUNoRC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0FBQztDQUM5QjtBQUVEOztHQUVHO0FBQ0gsTUFBTSxNQUFNLGtCQUFrQixHQUFHLE1BQU0sSUFBSSxDQUFDIn0=
|
package/dest/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEzD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAErD;;;GAGG;AACH,oBAAY,iBAAiB;IAC3B,kDAAkD;IAClD,SAAS,2BAA2B;IACpC,uCAAuC;IACvC,kBAAkB,oCAAoC;IACtD,sEAAsE;IACtE,UAAU,4BAA4B;IACtC,oDAAoD;IACpD,oBAAoB,sCAAsC;IAC1D,qDAAqD;IACrD,qBAAqB,uCAAuC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEzD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAErD;;;GAGG;AACH,oBAAY,iBAAiB;IAC3B,kDAAkD;IAClD,SAAS,2BAA2B;IACpC,uCAAuC;IACvC,kBAAkB,oCAAoC;IACtD,sEAAsE;IACtE,UAAU,4BAA4B;IACtC,oDAAoD;IACpD,oBAAoB,sCAAsC;IAC1D,qDAAqD;IACrD,qBAAqB,uCAAuC;IAC5D,0BAA0B;IAC1B,YAAY,uBAAuB;IACnC,uCAAuC;IACvC,cAAc,gCAAgC;IAC9C,wCAAwC;IACxC,eAAe,iCAAiC;IAChD,wCAAwC;IACxC,oBAAoB,sCAAsC;CAC3D;AAED;;;GAGG;AACH,MAAM,WAAW,UAAU;IACzB,uCAAuC;IACvC,EAAE,EAAE,MAAM,CAAC;IACX,iCAAiC;IACjC,IAAI,EAAE,MAAM,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,UAAU,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,mBAAmB;IACnB,IAAI,EAAE,iBAAiB,CAAC,oBAAoB,CAAC;IAC7C,gDAAgD;IAChD,SAAS,EAAE,MAAM,CAAC;IAClB,wDAAwD;IACxD,SAAS,EAAE,iBAAiB,CAAC;CAC9B;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,mBAAmB;IACnB,IAAI,EAAE,iBAAiB,CAAC,qBAAqB,CAAC;IAC9C,gDAAgD;IAChD,SAAS,EAAE,MAAM,CAAC;IAClB,0DAA0D;IAC1D,SAAS,EAAE,iBAAiB,CAAC;CAC9B;AAED;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG,MAAM,IAAI,CAAC"}
|
package/dest/types.js
CHANGED
|
@@ -7,5 +7,9 @@
|
|
|
7
7
|
/** Disconnect message (unencrypted control message, bidirectional) */ WalletMessageType["DISCONNECT"] = "aztec-wallet-disconnect";
|
|
8
8
|
/** Key exchange request sent over MessageChannel */ WalletMessageType["KEY_EXCHANGE_REQUEST"] = "aztec-wallet-key-exchange-request";
|
|
9
9
|
/** Key exchange response sent over MessageChannel */ WalletMessageType["KEY_EXCHANGE_RESPONSE"] = "aztec-wallet-key-exchange-response";
|
|
10
|
+
/** Wallet ready signal */ WalletMessageType["WALLET_READY"] = "aztec-wallet-ready";
|
|
11
|
+
/** Encrypted wallet message wrapper */ WalletMessageType["SECURE_MESSAGE"] = "aztec-wallet-secure-message";
|
|
12
|
+
/** Encrypted wallet response wrapper */ WalletMessageType["SECURE_RESPONSE"] = "aztec-wallet-secure-response";
|
|
13
|
+
/** Session disconnected notification */ WalletMessageType["SESSION_DISCONNECTED"] = "aztec-wallet-session-disconnected";
|
|
10
14
|
return WalletMessageType;
|
|
11
15
|
}({});
|
package/package.json
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/wallet-sdk",
|
|
3
3
|
"homepage": "https://github.com/AztecProtocol/aztec-packages/tree/master/yarn-project/wallet-sdk",
|
|
4
|
-
"version": "0.0.1-commit.
|
|
4
|
+
"version": "0.0.1-commit.f650c0a5c",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
7
7
|
"./base-wallet": "./dest/base-wallet/index.js",
|
|
8
8
|
"./extension/handlers": "./dest/extension/handlers/index.js",
|
|
9
9
|
"./extension/provider": "./dest/extension/provider/index.js",
|
|
10
|
+
"./iframe/handlers": "./dest/iframe/handlers/index.js",
|
|
11
|
+
"./iframe/provider": "./dest/iframe/provider/index.js",
|
|
10
12
|
"./crypto": "./dest/crypto.js",
|
|
11
13
|
"./types": "./dest/types.js",
|
|
12
14
|
"./manager": "./dest/manager/index.js"
|
|
@@ -16,6 +18,8 @@
|
|
|
16
18
|
"./src/base-wallet/index.ts",
|
|
17
19
|
"./src/extension/handlers/index.ts",
|
|
18
20
|
"./src/extension/provider/index.ts",
|
|
21
|
+
"./src/iframe/handlers/index.ts",
|
|
22
|
+
"./src/iframe/provider/index.ts",
|
|
19
23
|
"./src/crypto.ts",
|
|
20
24
|
"./src/types.ts",
|
|
21
25
|
"./src/manager/index.ts"
|
|
@@ -71,15 +75,15 @@
|
|
|
71
75
|
]
|
|
72
76
|
},
|
|
73
77
|
"dependencies": {
|
|
74
|
-
"@aztec/aztec.js": "0.0.1-commit.
|
|
75
|
-
"@aztec/constants": "0.0.1-commit.
|
|
76
|
-
"@aztec/entrypoints": "0.0.1-commit.
|
|
77
|
-
"@aztec/foundation": "0.0.1-commit.
|
|
78
|
-
"@aztec/pxe": "0.0.1-commit.
|
|
79
|
-
"@aztec/stdlib": "0.0.1-commit.
|
|
78
|
+
"@aztec/aztec.js": "0.0.1-commit.f650c0a5c",
|
|
79
|
+
"@aztec/constants": "0.0.1-commit.f650c0a5c",
|
|
80
|
+
"@aztec/entrypoints": "0.0.1-commit.f650c0a5c",
|
|
81
|
+
"@aztec/foundation": "0.0.1-commit.f650c0a5c",
|
|
82
|
+
"@aztec/pxe": "0.0.1-commit.f650c0a5c",
|
|
83
|
+
"@aztec/stdlib": "0.0.1-commit.f650c0a5c"
|
|
80
84
|
},
|
|
81
85
|
"devDependencies": {
|
|
82
|
-
"@aztec/noir-contracts.js": "0.0.1-commit.
|
|
86
|
+
"@aztec/noir-contracts.js": "0.0.1-commit.f650c0a5c",
|
|
83
87
|
"@jest/globals": "^30.0.0",
|
|
84
88
|
"@types/jest": "^30.0.0",
|
|
85
89
|
"@types/node": "^22.15.17",
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { Account } from '@aztec/aztec.js/account';
|
|
1
|
+
import type { Account, NoFrom } from '@aztec/aztec.js/account';
|
|
2
|
+
import { NO_FROM } from '@aztec/aztec.js/account';
|
|
2
3
|
import type { CallIntent, IntentInnerHash } from '@aztec/aztec.js/authorization';
|
|
3
4
|
import {
|
|
4
5
|
type InteractionWaitOptions,
|
|
@@ -8,32 +9,28 @@ import {
|
|
|
8
9
|
} from '@aztec/aztec.js/contracts';
|
|
9
10
|
import type { FeePaymentMethod } from '@aztec/aztec.js/fee';
|
|
10
11
|
import { waitForTx } from '@aztec/aztec.js/node';
|
|
11
|
-
import type {
|
|
12
|
-
Aliased,
|
|
13
|
-
AppCapabilities,
|
|
14
|
-
BatchResults,
|
|
15
|
-
BatchedMethod,
|
|
16
|
-
ExecuteUtilityOptions,
|
|
17
|
-
PrivateEvent,
|
|
18
|
-
PrivateEventFilter,
|
|
19
|
-
ProfileOptions,
|
|
20
|
-
SendOptions,
|
|
21
|
-
SimulateOptions,
|
|
22
|
-
Wallet,
|
|
23
|
-
WalletCapabilities,
|
|
24
|
-
} from '@aztec/aztec.js/wallet';
|
|
25
12
|
import {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
13
|
+
type Aliased,
|
|
14
|
+
type AppCapabilities,
|
|
15
|
+
type BatchResults,
|
|
16
|
+
type BatchedMethod,
|
|
17
|
+
ContractInitializationStatus,
|
|
18
|
+
type ExecuteUtilityOptions,
|
|
19
|
+
type PrivateEvent,
|
|
20
|
+
type PrivateEventFilter,
|
|
21
|
+
type ProfileOptions,
|
|
22
|
+
type SendOptions,
|
|
23
|
+
type SimulateOptions,
|
|
24
|
+
type Wallet,
|
|
25
|
+
type WalletCapabilities,
|
|
26
|
+
} from '@aztec/aztec.js/wallet';
|
|
31
27
|
import { AccountFeePaymentMethodOptions, type DefaultAccountEntrypointOptions } from '@aztec/entrypoints/account';
|
|
28
|
+
import { DefaultEntrypoint } from '@aztec/entrypoints/default';
|
|
32
29
|
import type { ChainInfo } from '@aztec/entrypoints/interfaces';
|
|
33
30
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
34
31
|
import { createLogger } from '@aztec/foundation/log';
|
|
35
32
|
import type { FieldsOf } from '@aztec/foundation/types';
|
|
36
|
-
import {
|
|
33
|
+
import { displayDebugLogs } from '@aztec/pxe/client/lazy';
|
|
37
34
|
import type { PXE, PackedPrivateEvent } from '@aztec/pxe/server';
|
|
38
35
|
import {
|
|
39
36
|
type ContractArtifact,
|
|
@@ -49,8 +46,11 @@ import {
|
|
|
49
46
|
getContractClassFromArtifact,
|
|
50
47
|
} from '@aztec/stdlib/contract';
|
|
51
48
|
import { SimulationError } from '@aztec/stdlib/errors';
|
|
52
|
-
import { Gas, GasSettings } from '@aztec/stdlib/gas';
|
|
53
|
-
import {
|
|
49
|
+
import { Gas, GasFees, GasSettings } from '@aztec/stdlib/gas';
|
|
50
|
+
import {
|
|
51
|
+
computeSiloedPrivateInitializationNullifier,
|
|
52
|
+
computeSiloedPublicInitializationNullifier,
|
|
53
|
+
} from '@aztec/stdlib/hash';
|
|
54
54
|
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
55
55
|
import {
|
|
56
56
|
BlockHeader,
|
|
@@ -75,11 +75,34 @@ export type FeeOptions = {
|
|
|
75
75
|
*/
|
|
76
76
|
walletFeePaymentMethod?: FeePaymentMethod;
|
|
77
77
|
/** Configuration options for the account to properly handle the selected fee payment method */
|
|
78
|
-
accountFeePaymentMethodOptions
|
|
78
|
+
accountFeePaymentMethodOptions?: AccountFeePaymentMethodOptions;
|
|
79
79
|
/** The gas settings to use for the transaction */
|
|
80
80
|
gasSettings: GasSettings;
|
|
81
81
|
};
|
|
82
82
|
|
|
83
|
+
/** Options for `simulateViaEntrypoint`. */
|
|
84
|
+
export type SimulateViaEntrypointOptions = Pick<
|
|
85
|
+
SimulateOptions,
|
|
86
|
+
'from' | 'additionalScopes' | 'skipTxValidation' | 'skipFeeEnforcement'
|
|
87
|
+
> & {
|
|
88
|
+
/** Fee options for the entrypoint */
|
|
89
|
+
feeOptions: FeeOptions;
|
|
90
|
+
/** Scopes to use for the simulation */
|
|
91
|
+
scopes: AztecAddress[];
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
/** Options for `completeFeeOptions`. */
|
|
95
|
+
export type CompleteFeeOptionsConfig = {
|
|
96
|
+
/** The address where the transaction is being sent from. */
|
|
97
|
+
from: AztecAddress | NoFrom;
|
|
98
|
+
/** The address paying for fees (if any fee payment method is embedded in the execution payload). */
|
|
99
|
+
feePayer?: AztecAddress;
|
|
100
|
+
/** User-provided partial gas settings. */
|
|
101
|
+
gasSettings?: Partial<FieldsOf<GasSettings>>;
|
|
102
|
+
/** If true, returns gas settings with high gas limits for estimation. If false, uses fallback limits. */
|
|
103
|
+
forEstimation?: boolean;
|
|
104
|
+
};
|
|
105
|
+
|
|
83
106
|
/**
|
|
84
107
|
* A base class for Wallet implementations
|
|
85
108
|
*/
|
|
@@ -94,8 +117,8 @@ export abstract class BaseWallet implements Wallet {
|
|
|
94
117
|
protected log = createLogger('wallet-sdk:base_wallet'),
|
|
95
118
|
) {}
|
|
96
119
|
|
|
97
|
-
protected scopesFrom(from: AztecAddress, additionalScopes: AztecAddress[] = []): AztecAddress[] {
|
|
98
|
-
const allScopes = from
|
|
120
|
+
protected scopesFrom(from: AztecAddress | NoFrom, additionalScopes: AztecAddress[] = []): AztecAddress[] {
|
|
121
|
+
const allScopes = from === NO_FROM ? additionalScopes : [from, ...additionalScopes];
|
|
99
122
|
const scopeSet = new Set(allScopes.map(address => address.toString()));
|
|
100
123
|
return [...scopeSet].map(AztecAddress.fromString);
|
|
101
124
|
}
|
|
@@ -123,26 +146,33 @@ export abstract class BaseWallet implements Wallet {
|
|
|
123
146
|
|
|
124
147
|
protected async createTxExecutionRequestFromPayloadAndFee(
|
|
125
148
|
executionPayload: ExecutionPayload,
|
|
126
|
-
from: AztecAddress,
|
|
149
|
+
from: AztecAddress | NoFrom,
|
|
127
150
|
feeOptions: FeeOptions,
|
|
128
151
|
): Promise<TxExecutionRequest> {
|
|
129
152
|
const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
|
|
130
|
-
const executionOptions: DefaultAccountEntrypointOptions = {
|
|
131
|
-
txNonce: Fr.random(),
|
|
132
|
-
cancellable: this.cancellableTransactions,
|
|
133
|
-
feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions,
|
|
134
|
-
};
|
|
135
153
|
const finalExecutionPayload = feeExecutionPayload
|
|
136
154
|
? mergeExecutionPayloads([feeExecutionPayload, executionPayload])
|
|
137
155
|
: executionPayload;
|
|
138
|
-
const fromAccount = await this.getAccountFromAddress(from);
|
|
139
156
|
const chainInfo = await this.getChainInfo();
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
chainInfo
|
|
144
|
-
|
|
145
|
-
|
|
157
|
+
|
|
158
|
+
if (from === NO_FROM) {
|
|
159
|
+
const entrypoint = new DefaultEntrypoint();
|
|
160
|
+
return entrypoint.createTxExecutionRequest(finalExecutionPayload, feeOptions.gasSettings, chainInfo);
|
|
161
|
+
} else {
|
|
162
|
+
const fromAccount = await this.getAccountFromAddress(from);
|
|
163
|
+
const executionOptions: DefaultAccountEntrypointOptions = {
|
|
164
|
+
txNonce: Fr.random(),
|
|
165
|
+
cancellable: this.cancellableTransactions,
|
|
166
|
+
// If from is an address, feeOptions include the way the account contract should handle the fee payment
|
|
167
|
+
feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions!,
|
|
168
|
+
};
|
|
169
|
+
return fromAccount.createTxExecutionRequest(
|
|
170
|
+
finalExecutionPayload,
|
|
171
|
+
feeOptions.gasSettings,
|
|
172
|
+
chainInfo,
|
|
173
|
+
executionOptions,
|
|
174
|
+
);
|
|
175
|
+
}
|
|
146
176
|
}
|
|
147
177
|
|
|
148
178
|
public async createAuthWit(
|
|
@@ -191,31 +221,39 @@ export abstract class BaseWallet implements Wallet {
|
|
|
191
221
|
|
|
192
222
|
/**
|
|
193
223
|
* Completes partial user-provided fee options with wallet defaults.
|
|
194
|
-
* @param
|
|
195
|
-
* @param feePayer - The address paying for fees (if any fee payment method is embedded in the execution payload)
|
|
196
|
-
* @param gasSettings - User-provided partial gas settings
|
|
197
|
-
* @returns - Complete fee options that can be used to create a transaction execution request
|
|
224
|
+
* @param config - Fee completion config.
|
|
198
225
|
*/
|
|
199
|
-
protected async completeFeeOptions(
|
|
200
|
-
from
|
|
201
|
-
feePayer?: AztecAddress,
|
|
202
|
-
gasSettings?: Partial<FieldsOf<GasSettings>>,
|
|
203
|
-
): Promise<FeeOptions> {
|
|
226
|
+
protected async completeFeeOptions(config: CompleteFeeOptionsConfig): Promise<FeeOptions> {
|
|
227
|
+
const { from, feePayer, gasSettings, forEstimation } = config;
|
|
204
228
|
const maxFeesPerGas =
|
|
205
229
|
gasSettings?.maxFeesPerGas ?? (await this.aztecNode.getCurrentMinFees()).mul(1 + this.minFeePadding);
|
|
206
230
|
let accountFeePaymentMethodOptions;
|
|
207
|
-
//
|
|
208
|
-
//
|
|
209
|
-
if (
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
231
|
+
// If from is an address, we need to determine the appropriate fee payment method options for the
|
|
232
|
+
// account contract entrypoint to use
|
|
233
|
+
if (from !== NO_FROM) {
|
|
234
|
+
if (!feePayer) {
|
|
235
|
+
// The transaction does not include a fee payment method, so we set the flag
|
|
236
|
+
// for the account to use its fee juice balance
|
|
237
|
+
accountFeePaymentMethodOptions = AccountFeePaymentMethodOptions.PREEXISTING_FEE_JUICE;
|
|
238
|
+
} else {
|
|
239
|
+
// The transaction includes fee payment method, so we check if we are the fee payer for it
|
|
240
|
+
// (this can only happen if the embedded payment method is FeeJuiceWithClaim)
|
|
241
|
+
accountFeePaymentMethodOptions = from.equals(feePayer)
|
|
242
|
+
? AccountFeePaymentMethodOptions.FEE_JUICE_WITH_CLAIM
|
|
243
|
+
: AccountFeePaymentMethodOptions.EXTERNAL;
|
|
244
|
+
}
|
|
217
245
|
}
|
|
218
|
-
const
|
|
246
|
+
const gasSettingsOverrides = {
|
|
247
|
+
gasLimits: gasSettings?.gasLimits ? Gas.from(gasSettings.gasLimits) : undefined,
|
|
248
|
+
teardownGasLimits: gasSettings?.teardownGasLimits ? Gas.from(gasSettings.teardownGasLimits) : undefined,
|
|
249
|
+
maxFeesPerGas,
|
|
250
|
+
maxPriorityFeesPerGas: gasSettings?.maxPriorityFeesPerGas ?? GasFees.empty(),
|
|
251
|
+
};
|
|
252
|
+
// When estimating gas (simulation), use high limits so the simulation doesn't run out of gas.
|
|
253
|
+
// When sending for real, use protocol max limits that the network will actually accept.
|
|
254
|
+
const fullGasSettings = forEstimation
|
|
255
|
+
? GasSettings.forEstimation(gasSettingsOverrides)
|
|
256
|
+
: GasSettings.fallback(gasSettingsOverrides);
|
|
219
257
|
this.log.debug(`Using L2 gas settings`, fullGasSettings);
|
|
220
258
|
return {
|
|
221
259
|
gasSettings: fullGasSettings,
|
|
@@ -224,37 +262,6 @@ export abstract class BaseWallet implements Wallet {
|
|
|
224
262
|
};
|
|
225
263
|
}
|
|
226
264
|
|
|
227
|
-
/**
|
|
228
|
-
* Completes partial user-provided fee options with unreasonably high gas limits
|
|
229
|
-
* for gas estimation. Uses the same logic as completeFeeOptions but sets high limits
|
|
230
|
-
* to avoid running out of gas during estimation.
|
|
231
|
-
* @param from - The address where the transaction is being sent from
|
|
232
|
-
* @param feePayer - The address paying for fees (if any fee payment method is embedded in the execution payload)
|
|
233
|
-
* @param gasSettings - User-provided partial gas settings
|
|
234
|
-
*/
|
|
235
|
-
protected async completeFeeOptionsForEstimation(
|
|
236
|
-
from: AztecAddress,
|
|
237
|
-
feePayer?: AztecAddress,
|
|
238
|
-
gasSettings?: Partial<FieldsOf<GasSettings>>,
|
|
239
|
-
) {
|
|
240
|
-
const defaultFeeOptions = await this.completeFeeOptions(from, feePayer, gasSettings);
|
|
241
|
-
const {
|
|
242
|
-
gasSettings: { maxFeesPerGas, maxPriorityFeesPerGas },
|
|
243
|
-
} = defaultFeeOptions;
|
|
244
|
-
// Use unrealistically high gas limits for estimation to avoid running out of gas.
|
|
245
|
-
// They will be tuned down after the simulation.
|
|
246
|
-
const gasSettingsForEstimation = new GasSettings(
|
|
247
|
-
new Gas(GAS_ESTIMATION_DA_GAS_LIMIT, GAS_ESTIMATION_L2_GAS_LIMIT),
|
|
248
|
-
new Gas(GAS_ESTIMATION_TEARDOWN_DA_GAS_LIMIT, GAS_ESTIMATION_TEARDOWN_L2_GAS_LIMIT),
|
|
249
|
-
maxFeesPerGas,
|
|
250
|
-
maxPriorityFeesPerGas,
|
|
251
|
-
);
|
|
252
|
-
return {
|
|
253
|
-
...defaultFeeOptions,
|
|
254
|
-
gasSettings: gasSettingsForEstimation,
|
|
255
|
-
};
|
|
256
|
-
}
|
|
257
|
-
|
|
258
265
|
registerSender(address: AztecAddress, _alias: string = ''): Promise<AztecAddress> {
|
|
259
266
|
return this.pxe.registerSender(address);
|
|
260
267
|
}
|
|
@@ -300,22 +307,20 @@ export abstract class BaseWallet implements Wallet {
|
|
|
300
307
|
/**
|
|
301
308
|
* Simulates calls through the standard PXE path (account entrypoint).
|
|
302
309
|
* @param executionPayload - The execution payload to simulate.
|
|
303
|
-
* @param
|
|
304
|
-
* @param feeOptions - Fee options for the transaction.
|
|
305
|
-
* @param skipTxValidation - Whether to skip tx validation.
|
|
306
|
-
* @param skipFeeEnforcement - Whether to skip fee enforcement.
|
|
307
|
-
* @param scopes - The scopes to use for the simulation.
|
|
310
|
+
* @param opts - Simulation options.
|
|
308
311
|
*/
|
|
309
|
-
protected async simulateViaEntrypoint(
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
312
|
+
protected async simulateViaEntrypoint(executionPayload: ExecutionPayload, opts: SimulateViaEntrypointOptions) {
|
|
313
|
+
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(
|
|
314
|
+
executionPayload,
|
|
315
|
+
opts.from,
|
|
316
|
+
opts.feeOptions,
|
|
317
|
+
);
|
|
318
|
+
return this.pxe.simulateTx(txRequest, {
|
|
319
|
+
simulatePublic: true,
|
|
320
|
+
skipTxValidation: opts.skipTxValidation,
|
|
321
|
+
skipFeeEnforcement: opts.skipFeeEnforcement,
|
|
322
|
+
scopes: opts.scopes,
|
|
323
|
+
});
|
|
319
324
|
}
|
|
320
325
|
|
|
321
326
|
/**
|
|
@@ -327,9 +332,12 @@ export abstract class BaseWallet implements Wallet {
|
|
|
327
332
|
* @returns The merged simulation result.
|
|
328
333
|
*/
|
|
329
334
|
async simulateTx(executionPayload: ExecutionPayload, opts: SimulateOptions): Promise<TxSimulationResult> {
|
|
330
|
-
const feeOptions =
|
|
331
|
-
|
|
332
|
-
:
|
|
335
|
+
const feeOptions = await this.completeFeeOptions({
|
|
336
|
+
from: opts.from,
|
|
337
|
+
feePayer: executionPayload.feePayer,
|
|
338
|
+
gasSettings: opts.fee?.gasSettings,
|
|
339
|
+
forEstimation: true,
|
|
340
|
+
});
|
|
333
341
|
const { optimizableCalls, remainingCalls } = extractOptimizablePublicStaticCalls(executionPayload);
|
|
334
342
|
const remainingPayload = { ...executionPayload, calls: remainingCalls };
|
|
335
343
|
|
|
@@ -343,12 +351,13 @@ export abstract class BaseWallet implements Wallet {
|
|
|
343
351
|
blockHeader = (await this.aztecNode.getBlockHeader())!;
|
|
344
352
|
}
|
|
345
353
|
|
|
354
|
+
const simulationOrigin = opts.from === NO_FROM ? AztecAddress.ZERO : opts.from;
|
|
346
355
|
const [optimizedResults, normalResult] = await Promise.all([
|
|
347
356
|
optimizableCalls.length > 0
|
|
348
357
|
? simulateViaNode(
|
|
349
358
|
this.aztecNode,
|
|
350
359
|
optimizableCalls,
|
|
351
|
-
|
|
360
|
+
simulationOrigin,
|
|
352
361
|
chainInfo,
|
|
353
362
|
feeOptions.gasSettings,
|
|
354
363
|
blockHeader,
|
|
@@ -357,14 +366,13 @@ export abstract class BaseWallet implements Wallet {
|
|
|
357
366
|
)
|
|
358
367
|
: Promise.resolve([]),
|
|
359
368
|
remainingCalls.length > 0
|
|
360
|
-
? this.simulateViaEntrypoint(
|
|
361
|
-
|
|
362
|
-
opts.from,
|
|
369
|
+
? this.simulateViaEntrypoint(remainingPayload, {
|
|
370
|
+
from: opts.from,
|
|
363
371
|
feeOptions,
|
|
364
|
-
this.scopesFrom(opts.from, opts.additionalScopes),
|
|
365
|
-
opts.skipTxValidation,
|
|
366
|
-
opts.skipFeeEnforcement ?? true,
|
|
367
|
-
)
|
|
372
|
+
scopes: this.scopesFrom(opts.from, opts.additionalScopes),
|
|
373
|
+
skipTxValidation: opts.skipTxValidation,
|
|
374
|
+
skipFeeEnforcement: opts.skipFeeEnforcement ?? true,
|
|
375
|
+
})
|
|
368
376
|
: Promise.resolve(null),
|
|
369
377
|
]);
|
|
370
378
|
|
|
@@ -372,7 +380,11 @@ export abstract class BaseWallet implements Wallet {
|
|
|
372
380
|
}
|
|
373
381
|
|
|
374
382
|
async profileTx(executionPayload: ExecutionPayload, opts: ProfileOptions): Promise<TxProfileResult> {
|
|
375
|
-
const feeOptions = await this.completeFeeOptions(
|
|
383
|
+
const feeOptions = await this.completeFeeOptions({
|
|
384
|
+
from: opts.from,
|
|
385
|
+
feePayer: executionPayload.feePayer,
|
|
386
|
+
gasSettings: opts.fee?.gasSettings,
|
|
387
|
+
});
|
|
376
388
|
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, opts.from, feeOptions);
|
|
377
389
|
return this.pxe.profileTx(txRequest, {
|
|
378
390
|
profileMode: opts.profileMode,
|
|
@@ -385,10 +397,17 @@ export abstract class BaseWallet implements Wallet {
|
|
|
385
397
|
executionPayload: ExecutionPayload,
|
|
386
398
|
opts: SendOptions<W>,
|
|
387
399
|
): Promise<SendReturn<W>> {
|
|
388
|
-
const feeOptions = await this.completeFeeOptions(
|
|
400
|
+
const feeOptions = await this.completeFeeOptions({
|
|
401
|
+
from: opts.from,
|
|
402
|
+
feePayer: executionPayload.feePayer,
|
|
403
|
+
gasSettings: opts.fee?.gasSettings,
|
|
404
|
+
});
|
|
389
405
|
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(executionPayload, opts.from, feeOptions);
|
|
390
406
|
const provenTx = await this.pxe.proveTx(txRequest, this.scopesFrom(opts.from, opts.additionalScopes));
|
|
391
|
-
const offchainOutput = extractOffchainOutput(
|
|
407
|
+
const offchainOutput = extractOffchainOutput(
|
|
408
|
+
provenTx.getOffchainEffects(),
|
|
409
|
+
provenTx.publicInputs.constants.anchorBlockHeader.globalVariables.timestamp,
|
|
410
|
+
);
|
|
392
411
|
const tx = await provenTx.toTx();
|
|
393
412
|
const txHash = tx.getTxHash();
|
|
394
413
|
if (await this.aztecNode.getTxEffect(txHash)) {
|
|
@@ -445,7 +464,7 @@ export abstract class BaseWallet implements Wallet {
|
|
|
445
464
|
}
|
|
446
465
|
|
|
447
466
|
executeUtility(call: FunctionCall, opts: ExecuteUtilityOptions): Promise<UtilityExecutionResult> {
|
|
448
|
-
return this.pxe.executeUtility(call, { authwits: opts.authWitnesses, scopes:
|
|
467
|
+
return this.pxe.executeUtility(call, { authwits: opts.authWitnesses, scopes: opts.scopes });
|
|
449
468
|
}
|
|
450
469
|
|
|
451
470
|
async getPrivateEvents<T>(
|
|
@@ -468,17 +487,39 @@ export abstract class BaseWallet implements Wallet {
|
|
|
468
487
|
return decodedEvents;
|
|
469
488
|
}
|
|
470
489
|
|
|
490
|
+
/**
|
|
491
|
+
* Returns metadata about a contract, including whether it has been initialized, published, and updated.
|
|
492
|
+
* @param address - The contract address to query.
|
|
493
|
+
*/
|
|
471
494
|
async getContractMetadata(address: AztecAddress) {
|
|
472
495
|
const instance = await this.pxe.getContractInstance(address);
|
|
473
|
-
const
|
|
474
|
-
|
|
475
|
-
|
|
496
|
+
const publiclyRegisteredContractPromise = this.aztecNode.getContract(address);
|
|
497
|
+
|
|
498
|
+
let initializationStatus: ContractInitializationStatus;
|
|
499
|
+
if (instance) {
|
|
500
|
+
// We have the instance, so we can compute the private initialization nullifier (which includes init_hash and is
|
|
501
|
+
// emitted by both private and public initializers) and get a definitive INITIALIZED/UNINITIALIZED answer.
|
|
502
|
+
const initNullifier = await computeSiloedPrivateInitializationNullifier(address, instance.initializationHash);
|
|
503
|
+
const witness = await this.aztecNode.getNullifierMembershipWitness('latest', initNullifier);
|
|
504
|
+
initializationStatus = witness
|
|
505
|
+
? ContractInitializationStatus.INITIALIZED
|
|
506
|
+
: ContractInitializationStatus.UNINITIALIZED;
|
|
507
|
+
} else {
|
|
508
|
+
// Without the instance we lack the init_hash needed for the private nullifier. We fall back to checking the
|
|
509
|
+
// public initialization nullifier (computed from address alone). Not all contracts emit it (only those with
|
|
510
|
+
// public functions that require initialization checks), so its absence doesn't mean the contract is
|
|
511
|
+
// uninitialized.
|
|
512
|
+
const publicNullifier = await computeSiloedPublicInitializationNullifier(address);
|
|
513
|
+
const witness = await this.aztecNode.getNullifierMembershipWitness('latest', publicNullifier);
|
|
514
|
+
initializationStatus = witness ? ContractInitializationStatus.INITIALIZED : ContractInitializationStatus.UNKNOWN;
|
|
515
|
+
}
|
|
516
|
+
const publiclyRegisteredContract = await publiclyRegisteredContractPromise;
|
|
476
517
|
const isContractUpdated =
|
|
477
518
|
publiclyRegisteredContract &&
|
|
478
519
|
!publiclyRegisteredContract.currentContractClassId.equals(publiclyRegisteredContract.originalContractClassId);
|
|
479
520
|
return {
|
|
480
521
|
instance: instance ?? undefined,
|
|
481
|
-
|
|
522
|
+
initializationStatus,
|
|
482
523
|
isContractPublished: !!publiclyRegisteredContract,
|
|
483
524
|
isContractUpdated: !!isContractUpdated,
|
|
484
525
|
updatedContractClassId: isContractUpdated ? publiclyRegisteredContract.currentContractClassId : undefined,
|