nightkit-bridge 0.0.0-stage → 0.1.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/LICENSE +55 -0
- package/README.md +62 -2
- package/dist/assert-shim.d.ts +14 -0
- package/dist/assert-shim.js +39 -0
- package/dist/assert-shim.js.map +1 -0
- package/dist/contract/index.d.ts +469 -0
- package/dist/contract/index.js +7666 -0
- package/dist/index.d.ts +149 -0
- package/dist/index.js +623 -0
- package/dist/index.js.map +1 -0
- package/dist/vite.d.ts +1 -0
- package/dist/vite.js +31 -0
- package/dist/vite.js.map +1 -0
- package/package.json +73 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
|
|
5
|
+
http://www.apache.org/licenses/
|
|
6
|
+
|
|
7
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
8
|
+
|
|
9
|
+
1. Definitions.
|
|
10
|
+
|
|
11
|
+
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
|
|
16
|
+
|
|
17
|
+
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
|
|
18
|
+
|
|
19
|
+
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
|
|
20
|
+
|
|
21
|
+
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
|
|
22
|
+
|
|
23
|
+
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
|
|
24
|
+
|
|
25
|
+
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
|
|
26
|
+
|
|
27
|
+
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
|
|
28
|
+
|
|
29
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
|
|
30
|
+
|
|
31
|
+
2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
|
|
32
|
+
|
|
33
|
+
3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
|
|
34
|
+
|
|
35
|
+
4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
|
|
36
|
+
|
|
37
|
+
You must give any other recipients of the Work or Derivative Works a copy of this License; and
|
|
38
|
+
|
|
39
|
+
You must cause any modified files to carry prominent notices stating that You changed the files; and
|
|
40
|
+
|
|
41
|
+
You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
|
|
42
|
+
|
|
43
|
+
If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
|
|
44
|
+
|
|
45
|
+
5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
|
|
46
|
+
|
|
47
|
+
6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
|
|
48
|
+
|
|
49
|
+
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
|
|
50
|
+
|
|
51
|
+
8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
|
|
52
|
+
|
|
53
|
+
9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
|
|
54
|
+
|
|
55
|
+
END OF TERMS AND CONDITIONS
|
package/README.md
CHANGED
|
@@ -1,3 +1,63 @@
|
|
|
1
|
-
#
|
|
1
|
+
# nightkit-bridge
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Take ETH, USDC and other assets from Ethereum or Base into a Midnight account, and back, through the 1AM bridge. Works with any [NightKit](https://www.npmjs.com/package/nightkit) session: 1AM, or an account opened from MetaMask, Coinbase Wallet and others. By [1AM](https://1am.xyz), built by [Webisoft](https://webisoft.com). Developed by Utkarsh Varma.
|
|
4
|
+
|
|
5
|
+
> **Beta. Testnets only.** Sepolia and Base Sepolia on one side, Midnight stagenet on the other. Midnight mainnet and EVM mainnets are refused in code. No outside security audit yet; do not put real funds behind it.
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install nightkit nightkit-bridge viem
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import { createBridge } from "nightkit-bridge";
|
|
13
|
+
|
|
14
|
+
// Choose the currencies your app accepts.
|
|
15
|
+
const bridge = await createBridge(session, { accept: ["ETH", "USDC"], app: "My game" });
|
|
16
|
+
|
|
17
|
+
bridge.assets(); // what the user can pay with: symbol, chain, decimals, minimum
|
|
18
|
+
|
|
19
|
+
// What it costs, before the user confirms.
|
|
20
|
+
const { fee, arrives } = await bridge.quote("ETH", amount, window.ethereum);
|
|
21
|
+
|
|
22
|
+
// Deposit into the user's own Midnight account…
|
|
23
|
+
await bridge.deposit({ asset: "ETH", amount, evm: window.ethereum, onStep: console.log });
|
|
24
|
+
|
|
25
|
+
// …or take a payment: the bridged token goes to your app's Midnight address.
|
|
26
|
+
await bridge.deposit({ asset: "ETH", amount, evm: window.ethereum, to: "mn_addr_stagenet1…" });
|
|
27
|
+
|
|
28
|
+
// Back to the EVM chain.
|
|
29
|
+
await bridge.withdraw({ asset: "ETH", amount: midnightUnits, to: "0x…" });
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
With Vite, add the plugin (WebAssembly support and two settings the Midnight SDK needs):
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
import { nightkitBridge } from "nightkit-bridge/vite";
|
|
36
|
+
|
|
37
|
+
export default defineConfig({ plugins: [react(), nightkitBridge()] });
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
`evm` is the user's Ethereum wallet as an EIP-1193 provider (`window.ethereum`, or a wagmi connector's provider). `amount` is in the asset's smallest unit on its own chain (wei for ETH).
|
|
41
|
+
|
|
42
|
+
## How it works
|
|
43
|
+
|
|
44
|
+
1. The user's Ethereum wallet sends one transaction: the asset is locked in the 1AM bridge contract (through 1AM's fee router where one is deployed, which keeps the fee shown by `quote`).
|
|
45
|
+
2. 1AM's attesters confirm the lock and 1AM's venue records it on Midnight. This takes a few minutes.
|
|
46
|
+
3. The user's Midnight wallet claims the token (`wETH`, `wUSDC`, …) into their own account, or to the address your app named.
|
|
47
|
+
|
|
48
|
+
A withdrawal burns the token on Midnight; the bridge releases the asset on the EVM chain, usually within a minute.
|
|
49
|
+
|
|
50
|
+
## What you should know
|
|
51
|
+
|
|
52
|
+
- **The bridge contracts are fixed in this package**, not taken from the server, so a tampered server cannot point a deposit at another contract.
|
|
53
|
+
- **Deposits survive a closed tab.** `bridge.deposits()` lists them; `bridge.resume(mnRecipient)` finishes one; `bridge.recover()` finds deposits from the chain.
|
|
54
|
+
- **Accounts opened through the NightKit vault** derive the deposit secret from the wallet, so a deposit can be recovered on any browser.
|
|
55
|
+
- **A 1AM (injected) wallet cannot do that.** Its deposit secret lives in this browser's storage. A deposit that is locked but not yet claimed is lost if that storage is cleared. Call `bridge.backup()` and have the user keep the result before their first deposit; `bridge.restore(secret)` puts it back.
|
|
56
|
+
- **A payment (`to`) only accepts an unshielded address of the same network** (`mn_addr_<network>1…`). A claim to a wrong address cannot be undone.
|
|
57
|
+
- **The claim on Midnight needs DUST** for its fee, and a synced account.
|
|
58
|
+
- **A website on another domain cannot call `markets.1am.xyz` yet.** Until 1AM opens those routes, pass `apiUrl` pointing at your own proxy of it.
|
|
59
|
+
|
|
60
|
+
## Who makes this
|
|
61
|
+
|
|
62
|
+
NightKit is made by [1AM](https://1am.xyz), the wallet for Midnight, and built by [Webisoft](https://webisoft.com).
|
|
63
|
+
Site and docs: [nightkit.1am.xyz](https://nightkit.1am.xyz). Licence: Apache-2.0.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
declare class AssertionError extends Error {
|
|
2
|
+
constructor(message: string);
|
|
3
|
+
}
|
|
4
|
+
declare function assert(value: unknown, message?: string | Error): asserts value;
|
|
5
|
+
declare namespace assert {
|
|
6
|
+
var ok: typeof assert;
|
|
7
|
+
var equal: (a: unknown, b: unknown, message?: string | Error) => void;
|
|
8
|
+
var strictEqual: (a: unknown, b: unknown, message?: string | Error) => void;
|
|
9
|
+
var notStrictEqual: (a: unknown, b: unknown, message?: string | Error) => void;
|
|
10
|
+
var fail: (message?: string | Error) => never;
|
|
11
|
+
var AssertionError: typeof import("./assert-shim").AssertionError;
|
|
12
|
+
}
|
|
13
|
+
export default assert;
|
|
14
|
+
export { AssertionError };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// Node's `assert`, as much of it as the browser bundle needs.
|
|
2
|
+
//
|
|
3
|
+
// @subsquid/scale-codec (reached through wallet-sdk-address-format, which the
|
|
4
|
+
// MetaMask path's in-page wallet uses for DUST addresses) does
|
|
5
|
+
// `require("assert")`. Vite would otherwise externalize it to an empty object,
|
|
6
|
+
// and the first `assert(...)` would throw "is not a function". vite.config.ts
|
|
7
|
+
// aliases `assert` here; Node keeps its built-in.
|
|
8
|
+
class AssertionError extends Error {
|
|
9
|
+
constructor(message) {
|
|
10
|
+
super(message);
|
|
11
|
+
this.name = "AssertionError";
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
const fail = (message, fallback) => {
|
|
15
|
+
throw message instanceof Error ? message : new AssertionError(message ?? fallback);
|
|
16
|
+
};
|
|
17
|
+
function assert(value, message) {
|
|
18
|
+
if (!value)
|
|
19
|
+
fail(message, "assertion failed");
|
|
20
|
+
}
|
|
21
|
+
assert.ok = assert;
|
|
22
|
+
assert.equal = (a, b, message) => {
|
|
23
|
+
// eslint-disable-next-line eqeqeq
|
|
24
|
+
if (a != b)
|
|
25
|
+
fail(message, `${String(a)} == ${String(b)}`);
|
|
26
|
+
};
|
|
27
|
+
assert.strictEqual = (a, b, message) => {
|
|
28
|
+
if (a !== b)
|
|
29
|
+
fail(message, `${String(a)} === ${String(b)}`);
|
|
30
|
+
};
|
|
31
|
+
assert.notStrictEqual = (a, b, message) => {
|
|
32
|
+
if (a === b)
|
|
33
|
+
fail(message, `${String(a)} !== ${String(b)}`);
|
|
34
|
+
};
|
|
35
|
+
assert.fail = (message) => fail(message, "failed");
|
|
36
|
+
assert.AssertionError = AssertionError;
|
|
37
|
+
export default assert;
|
|
38
|
+
export { AssertionError };
|
|
39
|
+
//# sourceMappingURL=assert-shim.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assert-shim.js","sourceRoot":"","sources":["../src/assert-shim.ts"],"names":[],"mappings":"AAAA,8DAA8D;AAC9D,EAAE;AACF,8EAA8E;AAC9E,+DAA+D;AAC/D,+EAA+E;AAC/E,8EAA8E;AAC9E,kDAAkD;AAElD,MAAM,cAAe,SAAQ,KAAK;IAChC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;IAC/B,CAAC;CACF;AAED,MAAM,IAAI,GAAG,CAAC,OAAmC,EAAE,QAAgB,EAAS,EAAE;IAC5E,MAAM,OAAO,YAAY,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,cAAc,CAAC,OAAO,IAAI,QAAQ,CAAC,CAAC;AACrF,CAAC,CAAC;AAEF,SAAS,MAAM,CAAC,KAAc,EAAE,OAAwB;IACtD,IAAI,CAAC,KAAK;QAAE,IAAI,CAAC,OAAO,EAAE,kBAAkB,CAAC,CAAC;AAChD,CAAC;AAED,MAAM,CAAC,EAAE,GAAG,MAAM,CAAC;AACnB,MAAM,CAAC,KAAK,GAAG,CAAC,CAAU,EAAE,CAAU,EAAE,OAAwB,EAAE,EAAE;IAClE,kCAAkC;IAClC,IAAI,CAAC,IAAI,CAAC;QAAE,IAAI,CAAC,OAAO,EAAE,GAAG,MAAM,CAAC,CAAC,CAAC,OAAO,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;AAC5D,CAAC,CAAC;AACF,MAAM,CAAC,WAAW,GAAG,CAAC,CAAU,EAAE,CAAU,EAAE,OAAwB,EAAE,EAAE;IACxE,IAAI,CAAC,KAAK,CAAC;QAAE,IAAI,CAAC,OAAO,EAAE,GAAG,MAAM,CAAC,CAAC,CAAC,QAAQ,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;AAC9D,CAAC,CAAC;AACF,MAAM,CAAC,cAAc,GAAG,CAAC,CAAU,EAAE,CAAU,EAAE,OAAwB,EAAE,EAAE;IAC3E,IAAI,CAAC,KAAK,CAAC;QAAE,IAAI,CAAC,OAAO,EAAE,GAAG,MAAM,CAAC,CAAC,CAAC,QAAQ,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;AAC9D,CAAC,CAAC;AACF,MAAM,CAAC,IAAI,GAAG,CAAC,OAAwB,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;AACpE,MAAM,CAAC,cAAc,GAAG,cAAc,CAAC;AAEvC,eAAe,MAAM,CAAC;AACtB,OAAO,EAAE,cAAc,EAAE,CAAC"}
|