@inco/js 0.1.21 → 0.1.23

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/README.md CHANGED
@@ -1,50 +1,106 @@
1
- # @inco/js (called `@inco/js` for now)
1
+ # @inco/js
2
2
 
3
3
  The @inco/js package contains the TypeScript SDK for creating dapps built on Inco.
4
4
 
5
- ## Install the package
5
+ ## Current Status: Active Development
6
6
 
7
- Since the package is private in the Github package registry, you'll need to use npm to log in into the registry first. Obviously, this is only needed if you want to access the package from outside the monorepo, as the monorepo already has workspaces set up.
7
+ The SDK is currently going through active development, to support all new features that Inco offers. As such, do expect breaking changes in subsequent releases, which will be documented in the [CHANGELOG](./CHANGELOG.md). The current state of `@inco/js` includes all low-level blocks to build functional dapps, but an improved public-facing API is also in the works.
8
8
 
9
- 1. Create a Github Personal Access Token (Classic)
9
+ ## Install
10
10
 
11
- Go to the [Personal Access Tokens](https://github.com/settings/tokens) page on Github, and create a new access token with the `read:packages` permission. Give it an explicit name like `inco-js-npm-github-pkg-registry`, and save the access token in a secure place, e.g. your password manager.
12
-
13
- 2. Login via npm to Github Package Registry.
11
+ Choose your favorite package manager:
14
12
 
15
13
  ```bash
16
- cd /path/to/my/project
17
- npm login --scope=@inco-fhevm --registry=https://npm.pkg.github.com
14
+ npm install @inco/js
15
+ # or
16
+ bun install @inco/js
17
+ # or
18
+ yarn add @inco/js
18
19
  ```
19
20
 
20
- You'll be asked to enter Username and Password. Put in your Github username, and paste the access token on step 1 as password.
21
-
22
- 3. Tell npm to look into Github Package Registry.
23
-
24
- Create a new `.npmrc` in `/path/to/my/project`, with the following lines:
21
+ ## Usage
25
22
 
26
- ```
27
- @inco-fhevm:registry=https://npm.pkg.github.com
28
- //npm.pkg.github.com/:_authToken=${READ_PACKAGE_TOKEN}
23
+ A typical usage of `@inco/js` includes 3 steps:
24
+
25
+ 1. Encrypting a value.
26
+ 2. Posting the ciphertext to the contract, which will perform confidential computes on it.
27
+ 3. Requesting a reencryption of the result of the computation.
28
+
29
+ ### 1. Encrypt a value
30
+
31
+ ```ts
32
+ import { getSupportedChain, getViemChain, handleTypes, HexString } from '@inco/js';
33
+ import { EciesScheme, encryptionSchemes, PlaintextWithContextOf } from '@inco/js/encryption';
34
+ import {
35
+ decodeSecp256k1PublicKey,
36
+ generateSecp256k1Keypair,
37
+ getActiveLightningDeployment,
38
+ getEciesEncryptor,
39
+ } from '@inco/js/lite';
40
+ import { createWalletClient, hexToBytes } from 'viem';
41
+
42
+ // Setup. Do it once at initialization.
43
+ const chain = getSupportedChain('baseSepolia');
44
+ const lightningConfig = getActiveLightningDeployment(chain);
45
+ const walletClient = createWalletClient({
46
+ chain: getViemChain(chain),
47
+ account: /* Choose your account */,
48
+ transport: /* Choose your transport */,
49
+ });
50
+ const dappAddress = '0x0000000000000000000000000000000000000000'; // Put your contract address here
51
+
52
+ // Define plaintext, along with context needed for verification.
53
+ const plaintext = 42n; // bigint
54
+ const plaintextWithContext: PlaintextWithContextOf<EciesScheme, typeof handleTypes.euint256> = {
55
+ plaintext: {
56
+ scheme: encryptionSchemes.ecies,
57
+ value: plaintext,
58
+ type: handleTypes.euint256,
59
+ },
60
+ context: {
61
+ hostChainId: BigInt(chain.id),
62
+ aclAddress: lightningConfig.executorAddress,
63
+ userAddress: walletClient.account.address,
64
+ contractAddress: dappAddress,
65
+ },
66
+ };
67
+
68
+ // Encrypt.
69
+ const ephemeralKeypair = await generateSecp256k1Keypair();
70
+ const eciesPubKey = decodeSecp256k1PublicKey(hexToBytes(lightningConfig.eciesPublicKey));
71
+ const encryptor = getEciesEncryptor({
72
+ scheme: encryptionSchemes.ecies,
73
+ pubKeyA: eciesPubKey,
74
+ privKeyB: ephemeralKeypair,
75
+ });
76
+ const { ciphertext } = await encryptor(plaintextWithContext);
77
+ console.log(ciphertext.value); // Will print the encrypted value as hex
29
78
  ```
30
79
 
31
- Then, you can do `npm install @inco/js`!
80
+ ### 2. Post the ciphertext to the contract
32
81
 
33
- Note: If using bun or another package manager, take a look how they manage install scopes.
82
+ For this step, there is nothing specific to the `@inco/js`. We recommend continue using [viem](https://viem.sh). In particular, take a look at their [`writeContract`](https://viem.sh/docs/contract/writeContract) methods to make a transaction on chain, and pass in the `ciphertext.value` from the previous step as the input ciphertext.
34
83
 
35
- 4. Resources
84
+ ### 3. Request a reencryption
36
85
 
37
- - Github docs: https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-npm-registry
38
- - Medium article: https://medium.com/@aamiralihussain53/a-guide-to-publishing-private-npm-package-on-github-9c533a251e2d
86
+ After submitting your transaction, the Inco covalidators will process your request and perform the computation. In your contract, the result handle of the computation should be stored on chain, let's call it `resultHandle` of type `Handle` (hex).
39
87
 
40
- ## Usage
41
-
42
- Currently, there are no docs as how to use the @inco/js package, as it only exposes low-level functions. There's some API work to do to make it more user-friendly.
88
+ ```ts
89
+ import { incoLiteReencryptor } from "@inco/js/lite";
90
+ import { Hex } from "viem";
43
91
 
44
- To take a look at the low-level functions, see [the E2E test](./test/incolite.ts), which shows how to encrypt, send an encrypted input to the host chain, request a reencrypt and wait for a decrypt.
45
-
46
- ## Publishing the package
92
+ // Reencrypt.
93
+ let resultHandle = "0x..." as Hex; // Retrieve it, e.g. by reading from your dapp contract.
94
+ const reencryptor = await incoLiteReencryptor({
95
+ chainId: BigInt(chain.id),
96
+ walletClient: walletClient,
97
+ }); // This step will ask you to sign an EIP-712 needed for reencryption verification
98
+ const resultPlaintext = await reencryptor({
99
+ handle: resultHandle,
100
+ });
101
+ console.log(resultPlaintext.value); // Plaintext of the final result after computation
102
+ ```
47
103
 
48
- Currently the publishing process is manual, and anyone with enough rights can run `bun run publish:github` to publish to the Github Packages registry.
104
+ ## License
49
105
 
50
- Some gitops process should replace this manual setup.
106
+ See the [LICENSE](./LICENSE) file.
package/dist/binary.d.ts CHANGED
@@ -15,3 +15,6 @@ export declare function bytesToHex(bs: Uint8Array): Hex;
15
15
  export declare const Bytes32: Schema.brand<Schema.filter<Schema.transformOrFail<Schema.Union<[typeof Schema.String, Schema.refine<object & Uint8Array<ArrayBufferLike>, Schema.Schema<object, object, never>>]>, Schema.TemplateLiteral<`0x${string}`>, never>>, "Bytes32">;
16
16
  export declare function asBytes32(x: BytesIsh): Bytes32;
17
17
  export type Bytes32 = typeof Bytes32.Type;
18
+ export type Address = typeof Address.Type;
19
+ export declare const Address: Schema.brand<Schema.filter<Schema.TemplateLiteral<`0x${string}`>>, "Address">;
20
+ export declare function parseAddress(address: string): Address;
@@ -41,7 +41,7 @@ var __export = (target, all) => {
41
41
  };
42
42
  var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
43
43
 
44
- // node_modules/viem/_esm/utils/data/isHex.js
44
+ // ../node_modules/viem/_esm/utils/data/isHex.js
45
45
  function isHex(value6, { strict: strict2 = true } = {}) {
46
46
  if (!value6)
47
47
  return false;
@@ -50,19 +50,18 @@ function isHex(value6, { strict: strict2 = true } = {}) {
50
50
  return strict2 ? /^0x[0-9a-fA-F]*$/.test(value6) : value6.startsWith("0x");
51
51
  }
52
52
 
53
- // node_modules/viem/_esm/utils/data/size.js
53
+ // ../node_modules/viem/_esm/utils/data/size.js
54
54
  function size21(value6) {
55
55
  if (isHex(value6, { strict: false }))
56
56
  return Math.ceil((value6.length - 2) / 2);
57
57
  return value6.length;
58
58
  }
59
- var init_size = () => {
60
- };
59
+ var init_size = () => {};
61
60
 
62
- // node_modules/viem/_esm/errors/version.js
63
- var version = "2.22.23";
61
+ // ../node_modules/viem/_esm/errors/version.js
62
+ var version = "2.24.3";
64
63
 
65
- // node_modules/viem/_esm/errors/base.js
64
+ // ../node_modules/viem/_esm/errors/base.js
66
65
  function walk(err, fn) {
67
66
  if (fn?.(err))
68
67
  return err;
@@ -150,7 +149,7 @@ var init_base = __esm(() => {
150
149
  };
151
150
  });
152
151
 
153
- // node_modules/viem/_esm/errors/abi.js
152
+ // ../node_modules/viem/_esm/errors/abi.js
154
153
  var AbiEncodingLengthMismatchError, BytesSizeMismatchError, UnsupportedPackedAbiType;
155
154
  var init_abi = __esm(() => {
156
155
  init_base();
@@ -180,7 +179,7 @@ var init_abi = __esm(() => {
180
179
  };
181
180
  });
182
181
 
183
- // node_modules/viem/_esm/errors/data.js
182
+ // ../node_modules/viem/_esm/errors/data.js
184
183
  var SizeExceedsPaddingSizeError;
185
184
  var init_data = __esm(() => {
186
185
  init_base();
@@ -191,7 +190,7 @@ var init_data = __esm(() => {
191
190
  };
192
191
  });
193
192
 
194
- // node_modules/viem/_esm/utils/data/pad.js
193
+ // ../node_modules/viem/_esm/utils/data/pad.js
195
194
  function pad(hexOrBytes, { dir: dir2, size: size22 = 32 } = {}) {
196
195
  if (typeof hexOrBytes === "string")
197
196
  return padHex(hexOrBytes, { dir: dir2, size: size22 });
@@ -229,7 +228,7 @@ var init_pad = __esm(() => {
229
228
  init_data();
230
229
  });
231
230
 
232
- // node_modules/viem/_esm/errors/encoding.js
231
+ // ../node_modules/viem/_esm/errors/encoding.js
233
232
  var IntegerOutOfRangeError, SizeOverflowError;
234
233
  var init_encoding = __esm(() => {
235
234
  init_base();
@@ -245,7 +244,7 @@ var init_encoding = __esm(() => {
245
244
  };
246
245
  });
247
246
 
248
- // node_modules/viem/_esm/utils/encoding/fromHex.js
247
+ // ../node_modules/viem/_esm/utils/encoding/fromHex.js
249
248
  function assertSize(hexOrBytes, { size: size22 }) {
250
249
  if (size21(hexOrBytes) > size22)
251
250
  throw new SizeOverflowError({
@@ -258,7 +257,7 @@ var init_fromHex = __esm(() => {
258
257
  init_size();
259
258
  });
260
259
 
261
- // node_modules/viem/_esm/utils/encoding/toHex.js
260
+ // ../node_modules/viem/_esm/utils/encoding/toHex.js
262
261
  function toHex(value6, opts = {}) {
263
262
  if (typeof value6 === "number" || typeof value6 === "bigint")
264
263
  return numberToHex(value6, opts);
@@ -330,7 +329,7 @@ var init_toHex = __esm(() => {
330
329
  encoder2 = /* @__PURE__ */ new TextEncoder;
331
330
  });
332
331
 
333
- // node_modules/viem/_esm/utils/encoding/toBytes.js
332
+ // ../node_modules/viem/_esm/utils/encoding/toBytes.js
334
333
  function toBytes(value6, opts = {}) {
335
334
  if (typeof value6 === "number" || typeof value6 === "bigint")
336
335
  return numberToBytes(value6, opts);
@@ -435,8 +434,7 @@ function aoutput(out, instance) {
435
434
  throw new Error("digestInto() expects output buffer of length at least " + min4);
436
435
  }
437
436
  }
438
- var init__assert = () => {
439
- };
437
+ var init__assert = () => {};
440
438
 
441
439
  // ../node_modules/@noble/hashes/esm/_u64.js
442
440
  function fromBig(n, le = false) {
@@ -698,7 +696,7 @@ var init_sha3 = __esm(() => {
698
696
  shake256 = /* @__PURE__ */ genShake(31, 136, 256 / 8);
699
697
  });
700
698
 
701
- // node_modules/viem/_esm/utils/hash/keccak256.js
699
+ // ../node_modules/viem/_esm/utils/hash/keccak256.js
702
700
  function keccak256(value6, to_) {
703
701
  const to = to_ || "hex";
704
702
  const bytes = keccak_256(isHex(value6, { strict: false }) ? toBytes(value6) : value6);
@@ -712,7 +710,7 @@ var init_keccak256 = __esm(() => {
712
710
  init_toHex();
713
711
  });
714
712
 
715
- // node_modules/viem/_esm/errors/address.js
713
+ // ../node_modules/viem/_esm/errors/address.js
716
714
  var InvalidAddressError;
717
715
  var init_address = __esm(() => {
718
716
  init_base();
@@ -729,7 +727,7 @@ var init_address = __esm(() => {
729
727
  };
730
728
  });
731
729
 
732
- // node_modules/viem/_esm/utils/lru.js
730
+ // ../node_modules/viem/_esm/utils/lru.js
733
731
  var LruMap;
734
732
  var init_lru = __esm(() => {
735
733
  LruMap = class LruMap extends Map {
@@ -763,7 +761,7 @@ var init_lru = __esm(() => {
763
761
  };
764
762
  });
765
763
 
766
- // node_modules/viem/_esm/utils/address/getAddress.js
764
+ // ../node_modules/viem/_esm/utils/address/getAddress.js
767
765
  function checksumAddress(address_, chainId) {
768
766
  if (checksumAddressCache.has(`${address_}.${chainId}`))
769
767
  return checksumAddressCache.get(`${address_}.${chainId}`);
@@ -790,7 +788,7 @@ var init_getAddress = __esm(() => {
790
788
  checksumAddressCache = /* @__PURE__ */ new LruMap(8192);
791
789
  });
792
790
 
793
- // node_modules/viem/_esm/utils/address/isAddress.js
791
+ // ../node_modules/viem/_esm/utils/address/isAddress.js
794
792
  function isAddress(address, options) {
795
793
  const { strict: strict2 = true } = options ?? {};
796
794
  const cacheKey = `${address}.${strict2}`;
@@ -816,12 +814,12 @@ var init_isAddress = __esm(() => {
816
814
  isAddressCache = /* @__PURE__ */ new LruMap(8192);
817
815
  });
818
816
 
819
- // node_modules/viem/_esm/utils/data/concat.js
817
+ // ../node_modules/viem/_esm/utils/data/concat.js
820
818
  function concatHex(values7) {
821
819
  return `0x${values7.reduce((acc, x) => acc + x.replace("0x", ""), "")}`;
822
820
  }
823
821
 
824
- // node_modules/viem/_esm/utils/regex.js
822
+ // ../node_modules/viem/_esm/utils/regex.js
825
823
  var arrayRegex, bytesRegex, integerRegex;
826
824
  var init_regex = __esm(() => {
827
825
  arrayRegex = /^(.*)\[([0-9]*)\]$/;
@@ -1503,8 +1501,7 @@ var tracingFunction = (name) => {
1503
1501
  };
1504
1502
  };
1505
1503
  var internalCall = /* @__PURE__ */ tracingFunction("effect_internal_function");
1506
- var genConstructor = function* () {
1507
- }.constructor;
1504
+ var genConstructor = function* () {}.constructor;
1508
1505
 
1509
1506
  // ../node_modules/effect/dist/esm/Hash.js
1510
1507
  var randomHashCache = /* @__PURE__ */ globalValue(/* @__PURE__ */ Symbol.for("effect/Hash/randomHashCache"), () => new WeakMap);
@@ -1851,8 +1848,7 @@ var StructuralCommitPrototype = {
1851
1848
  ...StructuralPrototype
1852
1849
  };
1853
1850
  var Base = /* @__PURE__ */ function() {
1854
- function Base2() {
1855
- }
1851
+ function Base2() {}
1856
1852
  Base2.prototype = CommitPrototype;
1857
1853
  return Base2;
1858
1854
  }();
@@ -5355,8 +5351,7 @@ var Reference = () => (id, options) => {
5355
5351
  Error.stackTraceLimit = 2;
5356
5352
  const creationError = new Error;
5357
5353
  Error.stackTraceLimit = limit;
5358
- function ReferenceClass() {
5359
- }
5354
+ function ReferenceClass() {}
5360
5355
  Object.setPrototypeOf(ReferenceClass, ReferenceProto);
5361
5356
  ReferenceClass.key = id;
5362
5357
  ReferenceClass.defaultValue = options.defaultValue;
@@ -8296,8 +8291,7 @@ var prettyErrorMessage = (u) => {
8296
8291
  if (hasProperty(u, "toString") && isFunction2(u["toString"]) && u["toString"] !== Object.prototype.toString && u["toString"] !== globalThis.Array.prototype.toString) {
8297
8292
  return u["toString"]();
8298
8293
  }
8299
- } catch {
8300
- }
8294
+ } catch {}
8301
8295
  return stringifyCircular(u);
8302
8296
  };
8303
8297
  var locationRegex = /\((.*)\)/g;
@@ -8871,8 +8865,7 @@ var zip2 = /* @__PURE__ */ dual(2, (self, that) => flatMap6(self, (a) => map9(th
8871
8865
  var zipLeft = /* @__PURE__ */ dual(2, (self, that) => flatMap6(self, (a) => as(that, a)));
8872
8866
  var zipRight = /* @__PURE__ */ dual(2, (self, that) => flatMap6(self, () => that));
8873
8867
  var never = /* @__PURE__ */ asyncInterrupt(() => {
8874
- const interval = setInterval(() => {
8875
- }, 2 ** 31 - 1);
8868
+ const interval = setInterval(() => {}, 2 ** 31 - 1);
8876
8869
  return sync(() => clearInterval(interval));
8877
8870
  });
8878
8871
  var interruptFiber = (self) => flatMap6(fiberId, (fiberId2) => pipe(self, interruptAsFiber(fiberId2)));
@@ -12692,16 +12685,11 @@ class Const {
12692
12685
  get value() {
12693
12686
  return this.effect;
12694
12687
  }
12695
- onStart(_context, _effect, _parent, _fiber) {
12696
- }
12697
- onEnd(_value, _fiber) {
12698
- }
12699
- onEffect(_fiber, _effect) {
12700
- }
12701
- onSuspend(_fiber) {
12702
- }
12703
- onResume(_fiber) {
12704
- }
12688
+ onStart(_context, _effect, _parent, _fiber) {}
12689
+ onEnd(_value, _fiber) {}
12690
+ onEffect(_fiber, _effect) {}
12691
+ onSuspend(_fiber) {}
12692
+ onResume(_fiber) {}
12705
12693
  map(f) {
12706
12694
  return new ProxySupervisor(this, pipe(this.value, map9(f)));
12707
12695
  }
@@ -13175,8 +13163,7 @@ class FiberRuntime extends Class {
13175
13163
  return whileLoop({
13176
13164
  while: () => !isDone3,
13177
13165
  body,
13178
- step: () => {
13179
- }
13166
+ step: () => {}
13180
13167
  });
13181
13168
  }
13182
13169
  return null;
@@ -22706,7 +22693,7 @@ class TrieIterator {
22706
22693
  }
22707
22694
  }
22708
22695
  var isTrie = (u) => hasProperty(u, TrieTypeId);
22709
- // node_modules/viem/_esm/utils/abi/encodePacked.js
22696
+ // ../node_modules/viem/_esm/utils/abi/encodePacked.js
22710
22697
  init_abi();
22711
22698
  init_address();
22712
22699
  init_isAddress();
@@ -22775,7 +22762,7 @@ function encode6(type2, value6, isArray2 = false) {
22775
22762
  throw new UnsupportedPackedAbiType(type2);
22776
22763
  }
22777
22764
 
22778
- // node_modules/viem/_esm/index.js
22765
+ // ../node_modules/viem/_esm/index.js
22779
22766
  init_toBytes();
22780
22767
  init_toHex();
22781
22768
  // src/schema.ts
@@ -22837,6 +22824,10 @@ var Bytes32 = BytesToHex.pipe(exports_Schema.filter((x) => x.length === 66 || `E
22837
22824
  function asBytes32(x) {
22838
22825
  return parse3(Bytes32, x);
22839
22826
  }
22827
+ var Address = HexString.pipe(exports_Schema.filter((s) => s.length === 42 || `Address must be a 20-byte '0x'-prefixed hex string, but got: ${s}`), exports_Schema.brand("Address"));
22828
+ function parseAddress(address) {
22829
+ return parse3(Address, address);
22830
+ }
22840
22831
 
22841
22832
  // src/handle.ts
22842
22833
  var import_sha32 = __toESM(require_sha3());