@inversealtruism/cairn-sdk 0.1.2 → 0.1.4

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.
Files changed (49) hide show
  1. package/dist/board.cjs +33 -2
  2. package/dist/board.d.cts +1 -1
  3. package/dist/board.d.ts +1 -1
  4. package/dist/board.js +2 -2
  5. package/dist/chain.cjs +29 -0
  6. package/dist/chain.d.cts +24 -3
  7. package/dist/chain.d.ts +24 -3
  8. package/dist/chain.js +5 -1
  9. package/dist/{chunk-G7FABIF4.js → chunk-BGJZF7S2.js} +11 -2
  10. package/dist/{chunk-6VWLWF7R.js → chunk-C452UODV.js} +31 -2
  11. package/dist/{chunk-OGP2W7DL.js → chunk-FSQZVNEM.js} +1 -1
  12. package/dist/chunk-K7SJOW3O.js +213 -0
  13. package/dist/chunk-MBSPHWZG.js +96 -0
  14. package/dist/{chunk-BZVJVL4Q.js → chunk-MVX7VQT4.js} +4 -3
  15. package/dist/{chunk-FNBE2FPE.js → chunk-OG4KA3LS.js} +49 -17
  16. package/dist/chunk-RELP23CH.js +99 -0
  17. package/dist/connect.cjs +145 -18
  18. package/dist/connect.d.cts +140 -2
  19. package/dist/connect.d.ts +140 -2
  20. package/dist/connect.js +4 -2
  21. package/dist/content.cjs +37 -5
  22. package/dist/content.d.cts +1 -1
  23. package/dist/content.d.ts +1 -1
  24. package/dist/content.js +2 -2
  25. package/dist/controller.cjs +355 -0
  26. package/dist/controller.d.cts +37 -0
  27. package/dist/controller.d.ts +37 -0
  28. package/dist/controller.js +8 -0
  29. package/dist/{http-D2CzfOsm.d.cts → http-CQsNL8w9.d.cts} +5 -0
  30. package/dist/{http-D2CzfOsm.d.ts → http-CQsNL8w9.d.ts} +5 -0
  31. package/dist/index.cjs +386 -48
  32. package/dist/index.d.cts +39 -6
  33. package/dist/index.d.ts +39 -6
  34. package/dist/index.js +75 -20
  35. package/dist/indexer.cjs +49 -17
  36. package/dist/indexer.d.cts +15 -4
  37. package/dist/indexer.d.ts +15 -4
  38. package/dist/indexer.js +1 -1
  39. package/dist/react.cjs +371 -0
  40. package/dist/react.d.cts +30 -0
  41. package/dist/react.d.ts +30 -0
  42. package/dist/react.js +23 -0
  43. package/dist/registry.cjs +11 -2
  44. package/dist/registry.d.cts +12 -3
  45. package/dist/registry.d.ts +12 -3
  46. package/dist/registry.js +1 -1
  47. package/package.json +21 -10
  48. package/dist/chunk-PHMU3CG5.js +0 -63
  49. package/dist/chunk-SMAPCKVG.js +0 -118
@@ -1,118 +0,0 @@
1
- import {
2
- NotInstalledError,
3
- UnsupportedMethodError,
4
- mapProviderError
5
- } from "./chunk-PHMU3CG5.js";
6
-
7
- // src/connect.ts
8
- function detectProvider(opts = {}) {
9
- const timeoutMs = opts.timeoutMs ?? 3e3;
10
- return new Promise((resolve, reject) => {
11
- if (typeof window === "undefined") {
12
- reject(new NotInstalledError("Not running in a browser \u2014 `window.cairn` is unavailable."));
13
- return;
14
- }
15
- if (window.cairn?.isCairn) {
16
- resolve(window.cairn);
17
- return;
18
- }
19
- let done = false;
20
- const onInit = () => {
21
- if (done) return;
22
- if (window.cairn?.isCairn) {
23
- done = true;
24
- cleanup();
25
- resolve(window.cairn);
26
- }
27
- };
28
- const timer = setTimeout(() => {
29
- if (done) return;
30
- done = true;
31
- cleanup();
32
- reject(new NotInstalledError());
33
- }, timeoutMs);
34
- const cleanup = () => {
35
- clearTimeout(timer);
36
- window.removeEventListener("cairn#initialized", onInit);
37
- };
38
- window.addEventListener("cairn#initialized", onInit);
39
- onInit();
40
- });
41
- }
42
- function isInstalled() {
43
- return typeof window !== "undefined" && !!window.cairn?.isCairn;
44
- }
45
- function unwrap(reply) {
46
- if (reply && reply.ok) return reply.result;
47
- throw mapProviderError(reply?.error ?? "Unknown wallet error");
48
- }
49
- var WalletConnection = class {
50
- provider;
51
- _addr = null;
52
- constructor(provider) {
53
- this.provider = provider;
54
- }
55
- /** The wallet's version string (e.g. "0.2.x"). */
56
- get version() {
57
- return this.provider.version;
58
- }
59
- /** The connected address, if `connect()`/`getAddress()` has resolved. */
60
- get address() {
61
- return this._addr;
62
- }
63
- /** Request connection. First time per origin prompts the user; afterwards may be silent. */
64
- async connect() {
65
- const { addr } = unwrap(await this.provider.connect());
66
- this._addr = addr;
67
- return addr;
68
- }
69
- /** Get the connected address (does not force a new connection prompt if already consented). */
70
- async getAddress() {
71
- const { addr } = unwrap(await this.provider.getAddress());
72
- this._addr = addr;
73
- return addr;
74
- }
75
- /** Passwordless sign-in: a signature over a login nonce (always prompts; structurally cannot sign a tx). */
76
- signIn() {
77
- return Promise.resolve(this.provider.signIn()).then(unwrap);
78
- }
79
- /** Send CSD (always prompts with clear-signing; wallet picks inputs + returns change to itself). */
80
- send(params) {
81
- return Promise.resolve(this.provider.send(params)).then(unwrap);
82
- }
83
- /** Low-level Propose (always prompts). Prefer `cairn.board.propose()` which computes the hash/uri/expiry. */
84
- propose(params) {
85
- return Promise.resolve(this.provider.propose(params)).then(unwrap);
86
- }
87
- /** Attest/support a proposal (always prompts). */
88
- attest(params) {
89
- return Promise.resolve(this.provider.attest(params)).then(unwrap);
90
- }
91
- /** Seal a commit-reveal claim (always prompts; salt stays inside the wallet). */
92
- sealClaim(params) {
93
- return Promise.resolve(this.provider.sealClaim(params)).then(unwrap);
94
- }
95
- /** Reveal a previously sealed claim by its sealing txid (always prompts). */
96
- revealClaim(txid) {
97
- if (typeof txid !== "string" || !txid) {
98
- return Promise.reject(new UnsupportedMethodError("revealClaim requires the sealing txid"));
99
- }
100
- return Promise.resolve(this.provider.revealClaim(txid)).then(unwrap);
101
- }
102
- };
103
- async function getWallet(opts = {}) {
104
- return new WalletConnection(await detectProvider(opts));
105
- }
106
- async function connect(opts = {}) {
107
- const wallet = await getWallet(opts);
108
- const address = await wallet.connect();
109
- return { wallet, address };
110
- }
111
-
112
- export {
113
- detectProvider,
114
- isInstalled,
115
- WalletConnection,
116
- getWallet,
117
- connect
118
- };