@haneullabs/seal 0.1.0 → 1.1.1
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/CHANGELOG.md +118 -57
- package/dist/bcs.d.mts +39 -0
- package/dist/bcs.d.mts.map +1 -0
- package/dist/bcs.mjs +86 -0
- package/dist/bcs.mjs.map +1 -0
- package/dist/bls12381.d.mts +29 -0
- package/dist/bls12381.d.mts.map +1 -0
- package/dist/bls12381.mjs +135 -0
- package/dist/bls12381.mjs.map +1 -0
- package/dist/client.d.mts +105 -0
- package/dist/client.d.mts.map +1 -0
- package/dist/client.mjs +274 -0
- package/dist/client.mjs.map +1 -0
- package/dist/decrypt.mjs +53 -0
- package/dist/decrypt.mjs.map +1 -0
- package/dist/dem.d.mts +1 -0
- package/dist/dem.mjs +134 -0
- package/dist/dem.mjs.map +1 -0
- package/dist/elgamal.mjs +35 -0
- package/dist/elgamal.mjs.map +1 -0
- package/dist/encrypt.d.mts +14 -0
- package/dist/encrypt.d.mts.map +1 -0
- package/dist/encrypt.mjs +61 -0
- package/dist/encrypt.mjs.map +1 -0
- package/dist/error.d.mts +75 -0
- package/dist/error.d.mts.map +1 -0
- package/dist/error.mjs +150 -0
- package/dist/error.mjs.map +1 -0
- package/dist/ibe.mjs +176 -0
- package/dist/ibe.mjs.map +1 -0
- package/dist/index.d.mts +7 -0
- package/dist/index.mjs +7 -0
- package/dist/kdf.mjs +81 -0
- package/dist/kdf.mjs.map +1 -0
- package/dist/key-server.d.mts +22 -0
- package/dist/key-server.d.mts.map +1 -0
- package/dist/key-server.mjs +195 -0
- package/dist/key-server.mjs.map +1 -0
- package/dist/session-key.d.mts +82 -0
- package/dist/session-key.d.mts.map +1 -0
- package/dist/session-key.mjs +171 -0
- package/dist/session-key.mjs.map +1 -0
- package/dist/shamir.mjs +730 -0
- package/dist/shamir.mjs.map +1 -0
- package/dist/types.d.mts +79 -0
- package/dist/types.d.mts.map +1 -0
- package/dist/utils.mjs +89 -0
- package/dist/utils.mjs.map +1 -0
- package/dist/version.mjs +6 -0
- package/dist/version.mjs.map +1 -0
- package/docs/index.md +84 -0
- package/docs/llms-index.md +6 -0
- package/package.json +29 -25
- package/dist/cjs/bcs.d.ts +0 -71
- package/dist/cjs/bcs.js +0 -74
- package/dist/cjs/bcs.js.map +0 -7
- package/dist/cjs/bls12381.d.ts +0 -44
- package/dist/cjs/bls12381.js +0 -151
- package/dist/cjs/bls12381.js.map +0 -7
- package/dist/cjs/client.d.ts +0 -84
- package/dist/cjs/client.js +0 -414
- package/dist/cjs/client.js.map +0 -7
- package/dist/cjs/decrypt.d.ts +0 -22
- package/dist/cjs/decrypt.js +0 -109
- package/dist/cjs/decrypt.js.map +0 -7
- package/dist/cjs/dem.d.ts +0 -38
- package/dist/cjs/dem.js +0 -185
- package/dist/cjs/dem.js.map +0 -7
- package/dist/cjs/elgamal.d.ts +0 -13
- package/dist/cjs/elgamal.js +0 -46
- package/dist/cjs/elgamal.js.map +0 -7
- package/dist/cjs/encrypt.d.ts +0 -32
- package/dist/cjs/encrypt.js +0 -104
- package/dist/cjs/encrypt.js.map +0 -7
- package/dist/cjs/error.d.ts +0 -86
- package/dist/cjs/error.js +0 -239
- package/dist/cjs/error.js.map +0 -7
- package/dist/cjs/ibe.d.ts +0 -98
- package/dist/cjs/ibe.js +0 -167
- package/dist/cjs/ibe.js.map +0 -7
- package/dist/cjs/index.d.ts +0 -6
- package/dist/cjs/index.js +0 -33
- package/dist/cjs/index.js.map +0 -7
- package/dist/cjs/kdf.d.ts +0 -30
- package/dist/cjs/kdf.js +0 -97
- package/dist/cjs/kdf.js.map +0 -7
- package/dist/cjs/key-server.d.ts +0 -98
- package/dist/cjs/key-server.js +0 -171
- package/dist/cjs/key-server.js.map +0 -7
- package/dist/cjs/package.json +0 -5
- package/dist/cjs/session-key.d.ts +0 -74
- package/dist/cjs/session-key.js +0 -245
- package/dist/cjs/session-key.js.map +0 -7
- package/dist/cjs/shamir.d.ts +0 -91
- package/dist/cjs/shamir.js +0 -770
- package/dist/cjs/shamir.js.map +0 -7
- package/dist/cjs/types.d.ts +0 -83
- package/dist/cjs/types.js +0 -17
- package/dist/cjs/types.js.map +0 -7
- package/dist/cjs/utils.d.ts +0 -47
- package/dist/cjs/utils.js +0 -106
- package/dist/cjs/utils.js.map +0 -7
- package/dist/cjs/version.d.ts +0 -1
- package/dist/cjs/version.js +0 -25
- package/dist/cjs/version.js.map +0 -7
- package/dist/esm/bcs.d.ts +0 -71
- package/dist/esm/bcs.js +0 -54
- package/dist/esm/bcs.js.map +0 -7
- package/dist/esm/bls12381.d.ts +0 -44
- package/dist/esm/bls12381.js +0 -131
- package/dist/esm/bls12381.js.map +0 -7
- package/dist/esm/client.d.ts +0 -84
- package/dist/esm/client.js +0 -407
- package/dist/esm/client.js.map +0 -7
- package/dist/esm/decrypt.d.ts +0 -22
- package/dist/esm/decrypt.js +0 -94
- package/dist/esm/decrypt.js.map +0 -7
- package/dist/esm/dem.d.ts +0 -38
- package/dist/esm/dem.js +0 -165
- package/dist/esm/dem.js.map +0 -7
- package/dist/esm/elgamal.d.ts +0 -13
- package/dist/esm/elgamal.js +0 -26
- package/dist/esm/elgamal.js.map +0 -7
- package/dist/esm/encrypt.d.ts +0 -32
- package/dist/esm/encrypt.js +0 -84
- package/dist/esm/encrypt.js.map +0 -7
- package/dist/esm/error.d.ts +0 -86
- package/dist/esm/error.js +0 -219
- package/dist/esm/error.js.map +0 -7
- package/dist/esm/ibe.d.ts +0 -98
- package/dist/esm/ibe.js +0 -147
- package/dist/esm/ibe.js.map +0 -7
- package/dist/esm/index.d.ts +0 -6
- package/dist/esm/index.js +0 -12
- package/dist/esm/index.js.map +0 -7
- package/dist/esm/kdf.d.ts +0 -30
- package/dist/esm/kdf.js +0 -83
- package/dist/esm/kdf.js.map +0 -7
- package/dist/esm/key-server.d.ts +0 -98
- package/dist/esm/key-server.js +0 -151
- package/dist/esm/key-server.js.map +0 -7
- package/dist/esm/package.json +0 -5
- package/dist/esm/session-key.d.ts +0 -74
- package/dist/esm/session-key.js +0 -230
- package/dist/esm/session-key.js.map +0 -7
- package/dist/esm/shamir.d.ts +0 -91
- package/dist/esm/shamir.js +0 -750
- package/dist/esm/shamir.js.map +0 -7
- package/dist/esm/types.d.ts +0 -83
- package/dist/esm/types.js +0 -1
- package/dist/esm/types.js.map +0 -7
- package/dist/esm/utils.d.ts +0 -47
- package/dist/esm/utils.js +0 -86
- package/dist/esm/utils.js.map +0 -7
- package/dist/esm/version.d.ts +0 -1
- package/dist/esm/version.js +0 -5
- package/dist/esm/version.js.map +0 -7
- package/dist/tsconfig.esm.tsbuildinfo +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shamir.mjs","names":[],"sources":["../src/shamir.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { allEqual, hasDuplicates } from './utils.js';\n\nconst GF256_SIZE = 256;\n\n/**\n * A field element in the Rijndael finite field GF(2⁸) with a fixed generator g = 0x03.\n */\nexport class GF256 {\n\tvalue: number;\n\n\tconstructor(value: number) {\n\t\tif (value < 0 || value >= GF256_SIZE) {\n\t\t\tthrow new Error(`Invalid value ${value} for GF256`);\n\t\t}\n\t\tthis.value = value;\n\t}\n\n\tlog(): number {\n\t\tif (this.value === 0) {\n\t\t\tthrow new Error('Invalid value');\n\t\t}\n\t\treturn LOG[this.value - 1];\n\t}\n\n\tstatic exp(x: number): GF256 {\n\t\treturn new GF256(EXP[x % (GF256_SIZE - 1)]);\n\t}\n\n\tadd(other: GF256): GF256 {\n\t\treturn new GF256(this.value ^ other.value);\n\t}\n\n\tsub(other: GF256): GF256 {\n\t\t// Addition is the same as subtraction in a binary field.\n\t\treturn this.add(other);\n\t}\n\n\tneg(): GF256 {\n\t\t// Negation doesn't change the value in a binary field.\n\t\treturn this;\n\t}\n\n\tmul(other: GF256): GF256 {\n\t\tif (this.value === 0 || other.value === 0) {\n\t\t\treturn new GF256(0);\n\t\t}\n\t\treturn GF256.exp(this.log() + other.log());\n\t}\n\n\tdiv(other: GF256): GF256 {\n\t\treturn this.mul(GF256.exp(GF256_SIZE - other.log() - 1));\n\t}\n\n\tequals(other: GF256): boolean {\n\t\treturn this.value === other.value;\n\t}\n\n\tstatic zero(): GF256 {\n\t\treturn new GF256(0);\n\t}\n\n\tstatic one(): GF256 {\n\t\treturn new GF256(1);\n\t}\n}\n\n/// Table of Eᵢ = gⁱ where g = 0x03 generates the multiplicative group of the field.\nconst EXP: number[] = [\n\t0x01, 0x03, 0x05, 0x0f, 0x11, 0x33, 0x55, 0xff, 0x1a, 0x2e, 0x72, 0x96, 0xa1, 0xf8, 0x13, 0x35,\n\t0x5f, 0xe1, 0x38, 0x48, 0xd8, 0x73, 0x95, 0xa4, 0xf7, 0x02, 0x06, 0x0a, 0x1e, 0x22, 0x66, 0xaa,\n\t0xe5, 0x34, 0x5c, 0xe4, 0x37, 0x59, 0xeb, 0x26, 0x6a, 0xbe, 0xd9, 0x70, 0x90, 0xab, 0xe6, 0x31,\n\t0x53, 0xf5, 0x04, 0x0c, 0x14, 0x3c, 0x44, 0xcc, 0x4f, 0xd1, 0x68, 0xb8, 0xd3, 0x6e, 0xb2, 0xcd,\n\t0x4c, 0xd4, 0x67, 0xa9, 0xe0, 0x3b, 0x4d, 0xd7, 0x62, 0xa6, 0xf1, 0x08, 0x18, 0x28, 0x78, 0x88,\n\t0x83, 0x9e, 0xb9, 0xd0, 0x6b, 0xbd, 0xdc, 0x7f, 0x81, 0x98, 0xb3, 0xce, 0x49, 0xdb, 0x76, 0x9a,\n\t0xb5, 0xc4, 0x57, 0xf9, 0x10, 0x30, 0x50, 0xf0, 0x0b, 0x1d, 0x27, 0x69, 0xbb, 0xd6, 0x61, 0xa3,\n\t0xfe, 0x19, 0x2b, 0x7d, 0x87, 0x92, 0xad, 0xec, 0x2f, 0x71, 0x93, 0xae, 0xe9, 0x20, 0x60, 0xa0,\n\t0xfb, 0x16, 0x3a, 0x4e, 0xd2, 0x6d, 0xb7, 0xc2, 0x5d, 0xe7, 0x32, 0x56, 0xfa, 0x15, 0x3f, 0x41,\n\t0xc3, 0x5e, 0xe2, 0x3d, 0x47, 0xc9, 0x40, 0xc0, 0x5b, 0xed, 0x2c, 0x74, 0x9c, 0xbf, 0xda, 0x75,\n\t0x9f, 0xba, 0xd5, 0x64, 0xac, 0xef, 0x2a, 0x7e, 0x82, 0x9d, 0xbc, 0xdf, 0x7a, 0x8e, 0x89, 0x80,\n\t0x9b, 0xb6, 0xc1, 0x58, 0xe8, 0x23, 0x65, 0xaf, 0xea, 0x25, 0x6f, 0xb1, 0xc8, 0x43, 0xc5, 0x54,\n\t0xfc, 0x1f, 0x21, 0x63, 0xa5, 0xf4, 0x07, 0x09, 0x1b, 0x2d, 0x77, 0x99, 0xb0, 0xcb, 0x46, 0xca,\n\t0x45, 0xcf, 0x4a, 0xde, 0x79, 0x8b, 0x86, 0x91, 0xa8, 0xe3, 0x3e, 0x42, 0xc6, 0x51, 0xf3, 0x0e,\n\t0x12, 0x36, 0x5a, 0xee, 0x29, 0x7b, 0x8d, 0x8c, 0x8f, 0x8a, 0x85, 0x94, 0xa7, 0xf2, 0x0d, 0x17,\n\t0x39, 0x4b, 0xdd, 0x7c, 0x84, 0x97, 0xa2, 0xfd, 0x1c, 0x24, 0x6c, 0xb4, 0xc7, 0x52, 0xf6,\n];\n\n/// Table of Lᵢ = LOG[i + 1] such that g^Lᵢ = i where g = 0x03.\nconst LOG: number[] = [\n\t0x00, 0x19, 0x01, 0x32, 0x02, 0x1a, 0xc6, 0x4b, 0xc7, 0x1b, 0x68, 0x33, 0xee, 0xdf, 0x03, 0x64,\n\t0x04, 0xe0, 0x0e, 0x34, 0x8d, 0x81, 0xef, 0x4c, 0x71, 0x08, 0xc8, 0xf8, 0x69, 0x1c, 0xc1, 0x7d,\n\t0xc2, 0x1d, 0xb5, 0xf9, 0xb9, 0x27,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, 0x2a, 0x9e, 0x5d, 0x56, 0xf2, 0xd3, 0xab, 0x44,\n\t0x11, 0x92, 0xd9, 0x23, 0x20, 0x2e, 0x89, 0xb4, 0x7c, 0xb8, 0x26, 0x77, 0x99, 0xe3, 0xa5, 0x67,\n\t0x4a, 0xed, 0xde, 0xc5, 0x31, 0xfe, 0x18, 0x0d, 0x63, 0x8c, 0x80, 0xc0, 0xf7, 0x70, 0x07,\n];\n\n/**\n * A polynomial over the field GF(2⁸).\n */\nexport class Polynomial {\n\tcoefficients: GF256[];\n\n\t/**\n\t * Construct a new Polynomial over [GF256] from the given coefficients.\n\t * The first coefficient is the constant term.\n\t */\n\tconstructor(coefficients: GF256[]) {\n\t\tthis.coefficients = coefficients.slice();\n\n\t\t// The highest degree coefficient is always non-zero.\n\t\twhile (\n\t\t\tthis.coefficients.length > 0 &&\n\t\t\tthis.coefficients[this.coefficients.length - 1].value === 0\n\t\t) {\n\t\t\tthis.coefficients.pop();\n\t\t}\n\t}\n\n\t/**\n\t * Construct a polynomial from the given bytes.\n\t * Each byte is a coefficient of the polynomial starting from the constant term.\n\t */\n\tstatic fromBytes(bytes: Uint8Array): Polynomial {\n\t\treturn new Polynomial(Array.from(bytes, (b) => new GF256(b)));\n\t}\n\n\tdegree(): number {\n\t\tif (this.coefficients.length === 0) {\n\t\t\treturn 0;\n\t\t}\n\t\treturn this.coefficients.length - 1;\n\t}\n\n\t/** Get the coefficient of the polynomial at the given index. */\n\tgetCoefficient(index: number): GF256 {\n\t\tif (index >= this.coefficients.length) {\n\t\t\treturn GF256.zero();\n\t\t}\n\t\treturn this.coefficients[index];\n\t}\n\n\t/** Add two polynomials. */\n\tadd(other: Polynomial): Polynomial {\n\t\tconst degree = Math.max(this.degree(), other.degree());\n\t\treturn new Polynomial(\n\t\t\tArray.from({ length: degree + 1 }, (_, i) =>\n\t\t\t\tthis.getCoefficient(i).add(other.getCoefficient(i)),\n\t\t\t),\n\t\t);\n\t}\n\n\t/** Multiply two polynomials. */\n\tmul(other: Polynomial): Polynomial {\n\t\tconst degree = this.degree() + other.degree();\n\t\treturn new Polynomial(\n\t\t\tArray.from({ length: degree + 1 }, (_, i) => {\n\t\t\t\tlet sum = GF256.zero();\n\t\t\t\tfor (let j = 0; j <= i; j++) {\n\t\t\t\t\tif (j <= this.degree() && i - j <= other.degree()) {\n\t\t\t\t\t\tsum = sum.add(this.getCoefficient(j).mul(other.getCoefficient(i - j)));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn sum;\n\t\t\t}),\n\t\t);\n\t}\n\n\t/** The polynomial s * this. */\n\tscale(s: GF256): Polynomial {\n\t\treturn new Polynomial(this.coefficients.map((c) => c.mul(s)));\n\t}\n\n\t/** The polynomial (1 / s) * this. */\n\tdiv(s: GF256): Polynomial {\n\t\treturn this.scale(new GF256(1).div(s));\n\t}\n\n\t/** The polynomial x + c. */\n\tstatic monic_linear(c: GF256): Polynomial {\n\t\treturn new Polynomial([c, GF256.one()]);\n\t}\n\n\t/** The zero polynomial. */\n\tstatic zero(): Polynomial {\n\t\treturn new Polynomial([]);\n\t}\n\n\t/** The polynomial 1. */\n\tstatic one(): Polynomial {\n\t\treturn new Polynomial([GF256.one()]);\n\t}\n\n\t/** Given a set of coordinates, interpolate a polynomial. */\n\tstatic interpolate(coordinates: { x: GF256; y: GF256 }[]): Polynomial {\n\t\tif (coordinates.length < 1) {\n\t\t\tthrow new Error('At least one coefficient is required');\n\t\t}\n\n\t\tif (hasDuplicates(coordinates.map(({ x }) => x.value))) {\n\t\t\tthrow new Error('Coefficients must have unique x values');\n\t\t}\n\n\t\treturn coordinates.reduce(\n\t\t\t(sum, { x: x_j, y: y_j }, j) =>\n\t\t\t\tsum.add(\n\t\t\t\t\tcoordinates\n\t\t\t\t\t\t.filter((_, i) => i !== j)\n\t\t\t\t\t\t.reduce(\n\t\t\t\t\t\t\t(product, { x: x_i }) =>\n\t\t\t\t\t\t\t\tproduct.mul(Polynomial.monic_linear(x_i.neg()).div(x_j.sub(x_i))),\n\t\t\t\t\t\t\tPolynomial.one(),\n\t\t\t\t\t\t)\n\t\t\t\t\t\t.scale(y_j),\n\t\t\t\t),\n\t\t\tPolynomial.zero(),\n\t\t);\n\t}\n\n\t/** Given a set of coordinates, interpolate a polynomial and evaluate it at x = 0. */\n\tstatic combine(coordinates: { x: GF256; y: GF256 }[]): GF256 {\n\t\tif (coordinates.length < 1) {\n\t\t\tthrow new Error('At least one coefficient is required');\n\t\t}\n\n\t\tif (hasDuplicates(coordinates.map(({ x }) => x.value))) {\n\t\t\tthrow new Error('Coefficients must have unique x values');\n\t\t}\n\n\t\tconst quotient: GF256 = coordinates.reduce((sum, { x: x_j, y: y_j }, j) => {\n\t\t\tconst denominator = x_j.mul(\n\t\t\t\tcoordinates\n\t\t\t\t\t.filter((_, i) => i !== j)\n\t\t\t\t\t.reduce((product, { x: x_i }) => product.mul(x_i.sub(x_j)), GF256.one()),\n\t\t\t);\n\t\t\treturn sum.add(y_j.div(denominator));\n\t\t}, GF256.zero());\n\n\t\tconst xProduct = coordinates.reduce((product, { x }) => product.mul(x), GF256.one());\n\t\treturn xProduct.mul(quotient);\n\t}\n\n\t/** Evaluate the polynomial at x. */\n\tevaluate(x: GF256): GF256 {\n\t\treturn this.coefficients\n\t\t\t.toReversed()\n\t\t\t.reduce((sum, coefficient) => sum.mul(x).add(coefficient), GF256.zero());\n\t}\n}\n\n/** Representation of a share of a secret. The index is a number between 1 and 255. */\nexport type Share = {\n\tindex: number;\n\tshare: Uint8Array<ArrayBuffer>;\n};\n\nfunction toInternalShare(share: Share): InternalShare {\n\treturn {\n\t\tindex: new GF256(share.index),\n\t\tshare: Array.from(share.share, (byte) => new GF256(byte)),\n\t};\n}\n\n/** Internal representation of a share of a secret. The index is a non-zero GF256. */\ntype InternalShare = {\n\tindex: GF256;\n\tshare: GF256[];\n};\n\nfunction toShare(internalShare: InternalShare): Share {\n\treturn {\n\t\tindex: internalShare.index.value,\n\t\tshare: new Uint8Array(internalShare.share.map((byte) => byte.value)),\n\t};\n}\n\n/**\n * Sample a random polynomial with the given constant and degree.\n *\n * @param constant The constant term of the polynomial.\n * @param degree The degree of the polynomial.\n * @returns A random polynomial with the given constant and degree.\n */\nfunction samplePolynomial(constant: GF256, degree: number): Polynomial {\n\tconst randomCoefficients = new Uint8Array(degree);\n\tcrypto.getRandomValues(randomCoefficients);\n\n\t// The resulting polynomial has degree + 1 coefficients.\n\treturn Polynomial.fromBytes(new Uint8Array([constant.value, ...randomCoefficients]));\n}\n\n/**\n * Split a secret into shares.\n *\n * @param secret The secret to split.\n * @param threshold The minimum number of shares required to reconstruct the secret.\n * @param total The total number of shares to generate.\n * @returns The shares.\n */\nexport function split(secret: Uint8Array, threshold: number, total: number): Share[] {\n\tif (threshold > total || threshold < 1 || total >= GF256_SIZE) {\n\t\tthrow new Error(`Invalid threshold ${threshold} or total ${total}`);\n\t}\n\n\tconst polynomials = Array.from(secret, (s) => samplePolynomial(new GF256(s), threshold - 1));\n\treturn Array.from({ length: total }, (_, i) => {\n\t\t// Indexes start at 1 because 0 is reserved for the constant term (which is also the secret).\n\t\tconst index = new GF256(i + 1);\n\t\tconst share = polynomials.map((p) => p.evaluate(index));\n\t\treturn toShare({ index, share });\n\t});\n}\n\n/** Validate a set of shares and return them in internal shares representation along with the length of the shares. */\nfunction validateShares(shares: Share[]): { internalShares: InternalShare[]; length: number } {\n\tif (shares.length < 1) {\n\t\tthrow new Error('At least one share is required');\n\t}\n\n\tif (!allEqual(shares.map(({ share }) => share.length))) {\n\t\tthrow new Error('All shares must have the same length');\n\t}\n\n\tif (hasDuplicates(shares.map(({ index }) => index))) {\n\t\tthrow new Error('Shares must have unique indices');\n\t}\n\n\tconst internalShares = shares.map(toInternalShare);\n\tconst length = internalShares[0].share.length;\n\n\treturn { internalShares, length };\n}\n\n/**\n * Combine shares into a secret. If fewer than the threshold number of shares are provided,\n * the result will be indistinguishable from random.\n *\n * @param shares The shares to combine.\n * @returns The secret.\n */\nexport function combine(shares: Share[]): Uint8Array<ArrayBuffer> {\n\tconst { internalShares, length } = validateShares(shares);\n\n\treturn new Uint8Array(\n\t\tArray.from(\n\t\t\t{ length },\n\t\t\t(_, i) =>\n\t\t\t\tPolynomial.combine(\n\t\t\t\t\tinternalShares.map(({ index, share }) => ({\n\t\t\t\t\t\tx: index,\n\t\t\t\t\t\ty: share[i],\n\t\t\t\t\t})),\n\t\t\t\t).value,\n\t\t),\n\t);\n}\n\n/**\n * Interpolate a polynomial from the given shares.\n *\n * @param shares The shares to interpolate from.\n * @returns A function that evaluates the polynomial at a given x.\n */\nexport function interpolate(shares: Share[]): (x: number) => Uint8Array {\n\tconst { internalShares, length } = validateShares(shares);\n\n\tconst polynomials = Array.from({ length }, (_, i) =>\n\t\tPolynomial.interpolate(internalShares.map(({ index, share }) => ({ x: index, y: share[i] }))),\n\t);\n\n\treturn (x: number) => {\n\t\treturn new Uint8Array(polynomials.map((p) => p.evaluate(new GF256(x)).value));\n\t};\n}\n"],"mappings":";;;AAKA,MAAM,aAAa;;;;AAKnB,IAAa,QAAb,MAAa,MAAM;CAGlB,YAAY,OAAe;AAC1B,MAAI,QAAQ,KAAK,SAAS,WACzB,OAAM,IAAI,MAAM,iBAAiB,MAAM,YAAY;AAEpD,OAAK,QAAQ;;CAGd,MAAc;AACb,MAAI,KAAK,UAAU,EAClB,OAAM,IAAI,MAAM,gBAAgB;AAEjC,SAAO,IAAI,KAAK,QAAQ;;CAGzB,OAAO,IAAI,GAAkB;AAC5B,SAAO,IAAI,MAAM,IAAI,KAAK,aAAa,IAAI;;CAG5C,IAAI,OAAqB;AACxB,SAAO,IAAI,MAAM,KAAK,QAAQ,MAAM,MAAM;;CAG3C,IAAI,OAAqB;AAExB,SAAO,KAAK,IAAI,MAAM;;CAGvB,MAAa;AAEZ,SAAO;;CAGR,IAAI,OAAqB;AACxB,MAAI,KAAK,UAAU,KAAK,MAAM,UAAU,EACvC,QAAO,IAAI,MAAM,EAAE;AAEpB,SAAO,MAAM,IAAI,KAAK,K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IAAI,MAAM,kCAAkC;CAGnD,MAAM,iBAAiB,OAAO,IAAI,gBAAgB;AAGlD,QAAO;EAAE;EAAgB,QAFV,eAAe,GAAG,MAAM;EAEN;;;;;;;;;AAUlC,SAAgB,QAAQ,QAA0C;CACjE,MAAM,EAAE,gBAAgB,WAAW,eAAe,OAAO;AAEzD,QAAO,IAAI,WACV,MAAM,KACL,EAAE,QAAQ,GACT,GAAG,MACH,WAAW,QACV,eAAe,KAAK,EAAE,OAAO,aAAa;EACzC,GAAG;EACH,GAAG,MAAM;EACT,EAAE,CACH,CAAC,MACH,CACD;;;;;;;;AASF,SAAgB,YAAY,QAA4C;CACvE,MAAM,EAAE,gBAAgB,WAAW,eAAe,OAAO;CAEzD,MAAM,cAAc,MAAM,KAAK,EAAE,QAAQ,GAAG,GAAG,MAC9C,WAAW,YAAY,eAAe,KAAK,EAAE,OAAO,aAAa;EAAE,GAAG;EAAO,GAAG,MAAM;EAAI,EAAE,CAAC,CAC7F;AAED,SAAQ,MAAc;AACrB,SAAO,IAAI,WAAW,YAAY,KAAK,MAAM,EAAE,SAAS,IAAI,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC"}
|
package/dist/types.d.mts
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { DemType, KemType } from "./encrypt.mjs";
|
|
2
|
+
import { SessionKey } from "./session-key.mjs";
|
|
3
|
+
import { ClientWithExtensions, CoreClient } from "@haneullabs/haneul/client";
|
|
4
|
+
|
|
5
|
+
//#region src/types.d.ts
|
|
6
|
+
type SealCompatibleClient = ClientWithExtensions<{
|
|
7
|
+
core: CoreClient;
|
|
8
|
+
}>;
|
|
9
|
+
interface KeyServerConfig {
|
|
10
|
+
objectId: string;
|
|
11
|
+
weight: number;
|
|
12
|
+
apiKeyName?: string;
|
|
13
|
+
apiKey?: string;
|
|
14
|
+
/** Must be provided if object ID is for a committee mode server since all fetch key calls go
|
|
15
|
+
* through an aggregator. */
|
|
16
|
+
aggregatorUrl?: string;
|
|
17
|
+
}
|
|
18
|
+
/** Configuration options for initializing a SealClient*/
|
|
19
|
+
interface SealClientOptions {
|
|
20
|
+
haneulClient: SealCompatibleClient;
|
|
21
|
+
/** Array of key server configs consisting of objectId, weight, optional API key name and API key */
|
|
22
|
+
serverConfigs: KeyServerConfig[];
|
|
23
|
+
/** Whether to verify the key servers' authenticity. */
|
|
24
|
+
verifyKeyServers?: boolean;
|
|
25
|
+
/** Timeout in milliseconds for network requests. */
|
|
26
|
+
timeout?: number;
|
|
27
|
+
}
|
|
28
|
+
interface EncryptOptions {
|
|
29
|
+
/** The type of KEM to use. */
|
|
30
|
+
kemType?: KemType;
|
|
31
|
+
/** The type of DEM to use. */
|
|
32
|
+
demType?: DemType;
|
|
33
|
+
/** The threshold for the TSS encryption. */
|
|
34
|
+
threshold: number;
|
|
35
|
+
/** The packageId namespace. */
|
|
36
|
+
packageId: string;
|
|
37
|
+
/** The identity to use. */
|
|
38
|
+
id: string;
|
|
39
|
+
/** The data to encrypt. */
|
|
40
|
+
data: Uint8Array;
|
|
41
|
+
/** Optional additional authenticated data. */
|
|
42
|
+
aad?: Uint8Array;
|
|
43
|
+
}
|
|
44
|
+
interface DecryptOptions {
|
|
45
|
+
/** The encrypted bytes to decrypt. */
|
|
46
|
+
data: Uint8Array;
|
|
47
|
+
/** The session key to use. */
|
|
48
|
+
sessionKey: SessionKey;
|
|
49
|
+
/** The transaction bytes to use (that calls seal_approve* functions). */
|
|
50
|
+
txBytes: Uint8Array;
|
|
51
|
+
/** Whether to check share consistency. */
|
|
52
|
+
checkShareConsistency?: boolean;
|
|
53
|
+
/** Whether to check also using an LE encoded nonce. */
|
|
54
|
+
checkLEEncoding?: boolean;
|
|
55
|
+
}
|
|
56
|
+
interface FetchKeysOptions {
|
|
57
|
+
/** The ids of the encrypted objects. */
|
|
58
|
+
ids: string[];
|
|
59
|
+
/** The transaction bytes to use (that calls seal_approve* functions). */
|
|
60
|
+
txBytes: Uint8Array;
|
|
61
|
+
/** The session key to use. */
|
|
62
|
+
sessionKey: SessionKey;
|
|
63
|
+
/** The threshold. */
|
|
64
|
+
threshold: number;
|
|
65
|
+
}
|
|
66
|
+
interface GetDerivedKeysOptions {
|
|
67
|
+
kemType?: KemType;
|
|
68
|
+
/** The id of the encrypted object. */
|
|
69
|
+
id: string;
|
|
70
|
+
/** The transaction bytes to use (that calls seal_approve* functions). */
|
|
71
|
+
txBytes: Uint8Array;
|
|
72
|
+
/** The session key to use. */
|
|
73
|
+
sessionKey: SessionKey;
|
|
74
|
+
/** The threshold. */
|
|
75
|
+
threshold: number;
|
|
76
|
+
}
|
|
77
|
+
//#endregion
|
|
78
|
+
export { DecryptOptions, EncryptOptions, FetchKeysOptions, GetDerivedKeysOptions, KeyServerConfig, SealClientOptions, SealCompatibleClient };
|
|
79
|
+
//# sourceMappingURL=types.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.mts","names":[],"sources":["../src/types.ts"],"mappings":";;;;;KAQY,oBAAA,GAAuB,oBAAA;EAClC,IAAA,EAAM,UAAA;AAAA;AAAA,UAcU,eAAA;EAChB,QAAA;EACA,MAAA;EACA,UAAA;EACA,MAAA;EAAA;;EAGA,aAAA;AAAA;AAID;AAAA,UAAiB,iBAAA;EAChB,YAAA,EAAc,oBAAA;EAEgB;EAA9B,aAAA,EAAe,eAAA;EAFD;EAId,gBAAA;EAFe;EAIf,OAAA;AAAA;AAAA,UAGgB,cAAA;EAHT;EAKP,OAAA,GAAU,OAAA;EAFoB;EAI9B,OAAA,GAAU,OAAA;EAFA;EAIV,SAAA;EAMM;EAJN,SAAA;EAMgB;EAJhB,EAAA;EARA;EAUA,IAAA,EAAM,UAAA;EARN;EAUA,GAAA,GAAM,UAAA;AAAA;AAAA,UAGU,cAAA;EAPhB;EASA,IAAA,EAAM,UAAA;EAPA;EASN,UAAA,EAAY,UAAA;EAPN;EASN,OAAA,EAAS,UAAA;EATO;EAWhB,qBAAA;EAR8B;EAU9B,eAAA;AAAA;AAAA,UAGgB,gBAAA;EAPP;EAST,GAAA;EATmB;EAWnB,OAAA,EAAS,UAAA;EAfH;EAiBN,UAAA,EAAY,UAAA;EAfA;EAiBZ,SAAA;AAAA;AAAA,UAGgB,qBAAA;EAChB,OAAA,GAAU,OAAA;EAfK;EAiBf,EAAA;EAdgB;EAgBhB,OAAA,EAAS,UAAA;;EAET,UAAA,EAAY,UAAA;EAhBZ;EAkBA,SAAA;AAAA"}
|
package/dist/utils.mjs
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { UserError } from "./error.mjs";
|
|
2
|
+
import { fromHex, toHex } from "@haneullabs/bcs";
|
|
3
|
+
import { isValidHaneulObjectId } from "@haneullabs/haneul/utils";
|
|
4
|
+
|
|
5
|
+
//#region src/utils.ts
|
|
6
|
+
/** Maximum value for a u8 (unsigned 8-bit integer). */
|
|
7
|
+
const MAX_U8 = 255;
|
|
8
|
+
/** Length of a Haneul address. */
|
|
9
|
+
const HANEUL_ADDRESS_LENGTH = 32;
|
|
10
|
+
/** Length of an encrypted share. */
|
|
11
|
+
const ENCRYPTED_SHARE_LENGTH = 32;
|
|
12
|
+
/** Length of a key. */
|
|
13
|
+
const KEY_LENGTH = 32;
|
|
14
|
+
function xor(a, b) {
|
|
15
|
+
if (a.length !== b.length) throw new Error("Invalid input");
|
|
16
|
+
return xorUnchecked(a, b);
|
|
17
|
+
}
|
|
18
|
+
function xorUnchecked(a, b) {
|
|
19
|
+
return a.map((ai, i) => ai ^ b[i]);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Create a full ID concatenating package ID || inner ID.
|
|
23
|
+
* @param packageId - The package ID.
|
|
24
|
+
* @param innerId - The inner ID.
|
|
25
|
+
* @returns The full ID.
|
|
26
|
+
*/
|
|
27
|
+
function createFullId(packageId, innerId) {
|
|
28
|
+
if (!isValidHaneulObjectId(packageId)) throw new UserError(`Invalid package ID ${packageId}`);
|
|
29
|
+
return toHex(flatten([fromHex(packageId), fromHex(innerId)]));
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Flatten an array of Uint8Arrays into a single Uint8Array.
|
|
33
|
+
*
|
|
34
|
+
* @param arrays - An array of Uint8Arrays to flatten.
|
|
35
|
+
* @returns A single Uint8Array containing all the elements of the input arrays in the given order.
|
|
36
|
+
*/
|
|
37
|
+
function flatten(arrays) {
|
|
38
|
+
const length = arrays.reduce((sum, arr) => sum + arr.length, 0);
|
|
39
|
+
const result = new Uint8Array(length);
|
|
40
|
+
arrays.reduce((offset, array) => {
|
|
41
|
+
result.set(array, offset);
|
|
42
|
+
return offset + array.length;
|
|
43
|
+
}, 0);
|
|
44
|
+
return result;
|
|
45
|
+
}
|
|
46
|
+
/** Count the number of occurrences of a value in an array. */
|
|
47
|
+
function count(array, value) {
|
|
48
|
+
return array.reduce((count$1, item) => item === value ? count$1 + 1 : count$1, 0);
|
|
49
|
+
}
|
|
50
|
+
/** Check if the array has any duplicate elements. */
|
|
51
|
+
function hasDuplicates(array) {
|
|
52
|
+
return new Set(array).size !== array.length;
|
|
53
|
+
}
|
|
54
|
+
/** Check if all elements in the array are equal. */
|
|
55
|
+
function allEqual(array) {
|
|
56
|
+
if (array.length === 0) return true;
|
|
57
|
+
return array.every((item) => item === array[0]);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Check if two Uint8Arrays are equal.
|
|
61
|
+
* @param a - The first Uint8Array.
|
|
62
|
+
* @param b - The second Uint8Array.
|
|
63
|
+
* @returns True if the two Uint8Arrays are equal, false otherwise.
|
|
64
|
+
*/
|
|
65
|
+
function equals(a, b) {
|
|
66
|
+
if (a.length !== b.length) return false;
|
|
67
|
+
return a.every((ai, i) => ai === b[i]);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* A simple class to represent a version number of the form x.y.z.
|
|
71
|
+
*/
|
|
72
|
+
var Version = class {
|
|
73
|
+
constructor(version) {
|
|
74
|
+
const parts = version.split(".").map(Number);
|
|
75
|
+
if (parts.length !== 3 || parts.some((part) => isNaN(part) || !Number.isInteger(part) || part < 0)) throw new UserError(`Invalid version format: ${version}`);
|
|
76
|
+
this.major = parts[0];
|
|
77
|
+
this.minor = parts[1];
|
|
78
|
+
this.patch = parts[2];
|
|
79
|
+
}
|
|
80
|
+
older_than(other) {
|
|
81
|
+
if (this.major !== other.major) return this.major < other.major;
|
|
82
|
+
else if (this.minor !== other.minor) return this.minor < other.minor;
|
|
83
|
+
return this.patch < other.patch;
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
//#endregion
|
|
88
|
+
export { ENCRYPTED_SHARE_LENGTH, HANEUL_ADDRESS_LENGTH, KEY_LENGTH, MAX_U8, Version, allEqual, count, createFullId, equals, flatten, hasDuplicates, xor, xorUnchecked };
|
|
89
|
+
//# sourceMappingURL=utils.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.mjs","names":["count"],"sources":["../src/utils.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { fromHex, toHex } from '@haneullabs/bcs';\nimport { isValidHaneulObjectId } from '@haneullabs/haneul/utils';\n\nimport { UserError } from './error.js';\n\n/** Maximum value for a u8 (unsigned 8-bit integer). */\nexport const MAX_U8 = 255;\n\n/** Length of a Haneul address. */\nexport const HANEUL_ADDRESS_LENGTH = 32;\n\n/** Length of an encrypted share. */\nexport const ENCRYPTED_SHARE_LENGTH = 32;\n\n/** Length of a key. */\nexport const KEY_LENGTH = 32;\n\nexport function xor(a: Uint8Array, b: Uint8Array): Uint8Array {\n\tif (a.length !== b.length) {\n\t\tthrow new Error('Invalid input');\n\t}\n\treturn xorUnchecked(a, b);\n}\n\nexport function xorUnchecked(a: Uint8Array, b: Uint8Array): Uint8Array {\n\treturn a.map((ai, i) => ai ^ b[i]);\n}\n\n/**\n * Create a full ID concatenating package ID || inner ID.\n * @param packageId - The package ID.\n * @param innerId - The inner ID.\n * @returns The full ID.\n */\nexport function createFullId(packageId: string, innerId: string): string {\n\tif (!isValidHaneulObjectId(packageId)) {\n\t\tthrow new UserError(`Invalid package ID ${packageId}`);\n\t}\n\tconst fullId = flatten([fromHex(packageId), fromHex(innerId)]);\n\treturn toHex(fullId);\n}\n\n/**\n * Flatten an array of Uint8Arrays into a single Uint8Array.\n *\n * @param arrays - An array of Uint8Arrays to flatten.\n * @returns A single Uint8Array containing all the elements of the input arrays in the given order.\n */\nexport function flatten(arrays: Uint8Array[]): Uint8Array {\n\tconst length = arrays.reduce((sum, arr) => sum + arr.length, 0);\n\tconst result = new Uint8Array(length);\n\tarrays.reduce((offset, array) => {\n\t\tresult.set(array, offset);\n\t\treturn offset + array.length;\n\t}, 0);\n\treturn result;\n}\n\n/** Count the number of occurrences of a value in an array. */\nexport function count<T>(array: T[], value: T): number {\n\treturn array.reduce((count, item) => (item === value ? count + 1 : count), 0);\n}\n\n/** Check if the array has any duplicate elements. */\nexport function hasDuplicates(array: number[]): boolean {\n\treturn new Set(array).size !== array.length;\n}\n\n/** Check if all elements in the array are equal. */\nexport function allEqual(array: number[]): boolean {\n\tif (array.length === 0) {\n\t\treturn true;\n\t}\n\treturn array.every((item) => item === array[0]);\n}\n\n/**\n * Check if two Uint8Arrays are equal.\n * @param a - The first Uint8Array.\n * @param b - The second Uint8Array.\n * @returns True if the two Uint8Arrays are equal, false otherwise.\n */\nexport function equals(a: Uint8Array, b: Uint8Array): boolean {\n\tif (a.length !== b.length) {\n\t\treturn false;\n\t}\n\treturn a.every((ai, i) => ai === b[i]);\n}\n\n/**\n * A simple class to represent a version number of the form x.y.z.\n */\nexport class Version {\n\tmajor: number;\n\tminor: number;\n\tpatch: number;\n\n\tconstructor(version: string) {\n\t\t// Very basic version parsing. Assumes version is in the format x.y.z where x, y, and z are non-negative integers.\n\t\tconst parts = version.split('.').map(Number);\n\t\tif (\n\t\t\tparts.length !== 3 ||\n\t\t\tparts.some((part) => isNaN(part) || !Number.isInteger(part) || part < 0)\n\t\t) {\n\t\t\tthrow new UserError(`Invalid version format: ${version}`);\n\t\t}\n\t\tthis.major = parts[0];\n\t\tthis.minor = parts[1];\n\t\tthis.patch = parts[2];\n\t}\n\n\t// Compare this version with another version. True if this version is older than the other version.\n\tolder_than(other: Version): boolean {\n\t\tif (this.major !== other.major) {\n\t\t\treturn this.major < other.major;\n\t\t} else if (this.minor !== other.minor) {\n\t\t\treturn this.minor < other.minor;\n\t\t}\n\t\treturn this.patch < other.patch;\n\t}\n}\n"],"mappings":";;;;;;AASA,MAAa,SAAS;;AAGtB,MAAa,wBAAwB;;AAGrC,MAAa,yBAAyB;;AAGtC,MAAa,aAAa;AAE1B,SAAgB,IAAI,GAAe,GAA2B;AAC7D,KAAI,EAAE,WAAW,EAAE,OAClB,OAAM,IAAI,MAAM,gBAAgB;AAEjC,QAAO,aAAa,GAAG,EAAE;;AAG1B,SAAgB,aAAa,GAAe,GAA2B;AACtE,QAAO,EAAE,KAAK,IAAI,MAAM,KAAK,EAAE,GAAG;;;;;;;;AASnC,SAAgB,aAAa,WAAmB,SAAyB;AACxE,KAAI,CAAC,sBAAsB,UAAU,CACpC,OAAM,IAAI,UAAU,sBAAsB,YAAY;AAGvD,QAAO,MADQ,QAAQ,CAAC,QAAQ,UAAU,EAAE,QAAQ,QAAQ,CAAC,CAAC,CAC1C;;;;;;;;AASrB,SAAgB,QAAQ,QAAkC;CACzD,MAAM,SAAS,OAAO,QAAQ,KAAK,QAAQ,MAAM,IAAI,QAAQ,EAAE;CAC/D,MAAM,SAAS,IAAI,WAAW,OAAO;AACrC,QAAO,QAAQ,QAAQ,UAAU;AAChC,SAAO,IAAI,OAAO,OAAO;AACzB,SAAO,SAAS,MAAM;IACpB,EAAE;AACL,QAAO;;;AAIR,SAAgB,MAAS,OAAY,OAAkB;AACtD,QAAO,MAAM,QAAQ,SAAO,SAAU,SAAS,QAAQA,UAAQ,IAAIA,SAAQ,EAAE;;;AAI9E,SAAgB,cAAc,OAA0B;AACvD,QAAO,IAAI,IAAI,MAAM,CAAC,SAAS,MAAM;;;AAItC,SAAgB,SAAS,OAA0B;AAClD,KAAI,MAAM,WAAW,EACpB,QAAO;AAER,QAAO,MAAM,OAAO,SAAS,SAAS,MAAM,GAAG;;;;;;;;AAShD,SAAgB,OAAO,GAAe,GAAwB;AAC7D,KAAI,EAAE,WAAW,EAAE,OAClB,QAAO;AAER,QAAO,EAAE,OAAO,IAAI,MAAM,OAAO,EAAE,GAAG;;;;;AAMvC,IAAa,UAAb,MAAqB;CAKpB,YAAY,SAAiB;EAE5B,MAAM,QAAQ,QAAQ,MAAM,IAAI,CAAC,IAAI,OAAO;AAC5C,MACC,MAAM,WAAW,KACjB,MAAM,MAAM,SAAS,MAAM,KAAK,IAAI,CAAC,OAAO,UAAU,KAAK,IAAI,OAAO,EAAE,CAExE,OAAM,IAAI,UAAU,2BAA2B,UAAU;AAE1D,OAAK,QAAQ,MAAM;AACnB,OAAK,QAAQ,MAAM;AACnB,OAAK,QAAQ,MAAM;;CAIpB,WAAW,OAAyB;AACnC,MAAI,KAAK,UAAU,MAAM,MACxB,QAAO,KAAK,QAAQ,MAAM;WAChB,KAAK,UAAU,MAAM,MAC/B,QAAO,KAAK,QAAQ,MAAM;AAE3B,SAAO,KAAK,QAAQ,MAAM"}
|
package/dist/version.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.mjs","names":[],"sources":["../src/version.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\n// This file is generated by genversion.mjs. Do not edit it directly.\n\nexport const PACKAGE_VERSION = '1.1.1';\n"],"mappings":";AAKA,MAAa,kBAAkB"}
|
package/docs/index.md
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# Seal SDK
|
|
2
|
+
|
|
3
|
+
> Decentralized secrets management with threshold encryption on Haneul
|
|
4
|
+
|
|
5
|
+
> **Note:** This is a beta version of Seal. See https://github.com/GeunhwaJeong/seal for more
|
|
6
|
+
> details.
|
|
7
|
+
|
|
8
|
+
The Seal SDK provides threshold encryption capabilities for Haneul applications, enabling secure
|
|
9
|
+
data encryption with configurable key servers.
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```bash npm2yarn
|
|
14
|
+
npm install --save @haneullabs/seal @haneullabs/haneul
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Setup
|
|
18
|
+
|
|
19
|
+
To use the Seal SDK, create a Haneul client and extend it with the Seal extension:
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
const client = new HaneulGrpcClient({
|
|
23
|
+
network: 'testnet',
|
|
24
|
+
baseUrl: 'https://fullnode.testnet.haneul.io:443',
|
|
25
|
+
}).$extend(
|
|
26
|
+
seal({
|
|
27
|
+
serverConfigs: [
|
|
28
|
+
{ objectId: '0x...keyserver1', weight: 1 },
|
|
29
|
+
{ objectId: '0x...keyserver2', weight: 1 },
|
|
30
|
+
],
|
|
31
|
+
}),
|
|
32
|
+
);
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Configuration Options
|
|
36
|
+
|
|
37
|
+
The `seal()` function accepts the following options:
|
|
38
|
+
|
|
39
|
+
- **`serverConfigs`** (required) - Array of key server configurations with `objectId` and `weight`
|
|
40
|
+
- **`verifyKeyServers`** (optional) - Whether to verify key server authenticity (default: `true`)
|
|
41
|
+
- **`timeout`** (optional) - Timeout in milliseconds for network requests (default: `10000`)
|
|
42
|
+
|
|
43
|
+
## Basic Usage
|
|
44
|
+
|
|
45
|
+
### Encrypting Data
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
const data = new Uint8Array([1, 2, 3]);
|
|
49
|
+
|
|
50
|
+
const { encryptedObject } = await client.seal.encrypt({
|
|
51
|
+
threshold: 2, // Number of key servers needed to decrypt
|
|
52
|
+
packageId: '0x...your-package-id',
|
|
53
|
+
id: '0x...your-object-id',
|
|
54
|
+
data,
|
|
55
|
+
});
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Decrypting Data
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
// Create a session key for decryption
|
|
62
|
+
const sessionKey = await SessionKey.create({
|
|
63
|
+
address: senderAddress,
|
|
64
|
+
packageId: '0x...your-package-id',
|
|
65
|
+
ttlMin: 10, // Time-to-live in minutes
|
|
66
|
+
signer: keypair,
|
|
67
|
+
haneulClient: client,
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
// Build transaction bytes that call seal_approve
|
|
71
|
+
const txBytes = await buildApprovalTransaction(/* ... */);
|
|
72
|
+
|
|
73
|
+
// Decrypt the data
|
|
74
|
+
const decryptedData = await client.seal.decrypt({
|
|
75
|
+
data: encryptedObject,
|
|
76
|
+
sessionKey,
|
|
77
|
+
txBytes,
|
|
78
|
+
});
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Resources
|
|
82
|
+
|
|
83
|
+
For detailed documentation on threshold encryption and key server setup, see the
|
|
84
|
+
[Seal repository](https://github.com/GeunhwaJeong/seal).
|
package/package.json
CHANGED
|
@@ -1,48 +1,52 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@haneullabs/seal",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "Seal SDK",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
|
-
"author": "Haneul Labs <build@
|
|
7
|
-
"type": "
|
|
8
|
-
"main": "./dist/
|
|
9
|
-
"
|
|
10
|
-
"types": "./dist/cjs/index.d.ts",
|
|
6
|
+
"author": "Haneul Labs <build@haneul-labs.com>",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "./dist/index.mjs",
|
|
9
|
+
"types": "./dist/index.d.mts",
|
|
11
10
|
"exports": {
|
|
12
11
|
".": {
|
|
13
|
-
"
|
|
14
|
-
"
|
|
12
|
+
"types": "./dist/index.d.mts",
|
|
13
|
+
"import": "./dist/index.mjs",
|
|
14
|
+
"default": "./dist/index.mjs"
|
|
15
15
|
}
|
|
16
16
|
},
|
|
17
17
|
"sideEffects": false,
|
|
18
18
|
"files": [
|
|
19
19
|
"CHANGELOG.md",
|
|
20
|
-
"dist"
|
|
20
|
+
"dist",
|
|
21
|
+
"docs"
|
|
21
22
|
],
|
|
22
23
|
"repository": {
|
|
23
24
|
"type": "git",
|
|
24
|
-
"url": "git+https://github.com/GeunhwaJeong/
|
|
25
|
+
"url": "git+https://github.com/GeunhwaJeong/ts-sdks.git"
|
|
25
26
|
},
|
|
26
27
|
"bugs": {
|
|
27
|
-
"url": "https://github.com/
|
|
28
|
+
"url": "https://github.com/GeunhwaJeong/ts-sdks/issues"
|
|
28
29
|
},
|
|
29
|
-
"homepage": "https://github.com/
|
|
30
|
+
"homepage": "https://github.com/GeunhwaJeong/seal#readme",
|
|
30
31
|
"devDependencies": {
|
|
31
|
-
"@hey-api/openapi-ts": "^0.
|
|
32
|
-
"@types/node": "^
|
|
32
|
+
"@hey-api/openapi-ts": "^0.90.3",
|
|
33
|
+
"@types/node": "^25.0.8",
|
|
33
34
|
"typescript": "^5.9.3",
|
|
34
|
-
"vitest": "^4.0.
|
|
35
|
-
"@haneullabs/
|
|
35
|
+
"vitest": "^4.0.17",
|
|
36
|
+
"@haneullabs/haneul": "^2.13.0"
|
|
36
37
|
},
|
|
37
38
|
"dependencies": {
|
|
38
|
-
"@noble/curves": "
|
|
39
|
-
"@noble/hashes": "^
|
|
40
|
-
"@haneullabs/
|
|
41
|
-
|
|
39
|
+
"@noble/curves": "^2.0.1",
|
|
40
|
+
"@noble/hashes": "^2.0.1",
|
|
41
|
+
"@haneullabs/bcs": "^2.0.3"
|
|
42
|
+
},
|
|
43
|
+
"peerDependencies": {
|
|
44
|
+
"@haneullabs/haneul": "^2.13.0"
|
|
42
45
|
},
|
|
43
46
|
"scripts": {
|
|
44
47
|
"clean": "rm -rf tsconfig.tsbuildinfo ./dist",
|
|
45
|
-
"build": "node genversion.mjs &&
|
|
48
|
+
"build": "node genversion.mjs && rm -rf dist && tsc --noEmit && tsdown",
|
|
49
|
+
"build:docs": "tsx ../docs/scripts/build-docs.ts",
|
|
46
50
|
"codegen:version": "node genversion.mjs",
|
|
47
51
|
"vitest": "vitest",
|
|
48
52
|
"test": "pnpm test:typecheck && pnpm test:unit",
|
|
@@ -50,9 +54,9 @@
|
|
|
50
54
|
"test:unit": "vitest run unit __tests__",
|
|
51
55
|
"prettier:check": "prettier -c --ignore-unknown .",
|
|
52
56
|
"prettier:fix": "prettier -w --ignore-unknown .",
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"lint": "pnpm run
|
|
56
|
-
"lint:fix": "pnpm run
|
|
57
|
+
"oxlint:check": "oxlint .",
|
|
58
|
+
"oxlint:fix": "oxlint --fix",
|
|
59
|
+
"lint": "pnpm run oxlint:check && pnpm run prettier:check",
|
|
60
|
+
"lint:fix": "pnpm run oxlint:fix && pnpm run prettier:fix"
|
|
57
61
|
}
|
|
58
62
|
}
|
package/dist/cjs/bcs.d.ts
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
export declare const IBEEncryptions: import("@haneullabs/bcs").BcsEnum<{
|
|
2
|
-
BonehFranklinBLS12381: import("@haneullabs/bcs").BcsStruct<{
|
|
3
|
-
nonce: import("@haneullabs/bcs").BcsType<Uint8Array<ArrayBufferLike>, Iterable<number>, "bytes[96]">;
|
|
4
|
-
encryptedShares: import("@haneullabs/bcs").BcsType<Uint8Array<ArrayBufferLike>[], Iterable<Iterable<number>> & {
|
|
5
|
-
length: number;
|
|
6
|
-
}, string>;
|
|
7
|
-
encryptedRandomness: import("@haneullabs/bcs").BcsType<Uint8Array<ArrayBufferLike>, Iterable<number>, "bytes[32]">;
|
|
8
|
-
}, string>;
|
|
9
|
-
}, "IBEEncryptions">;
|
|
10
|
-
export declare const Ciphertext: import("@haneullabs/bcs").BcsEnum<{
|
|
11
|
-
Aes256Gcm: import("@haneullabs/bcs").BcsStruct<{
|
|
12
|
-
blob: import("@haneullabs/bcs").BcsType<Uint8Array<ArrayBufferLike>, Iterable<number>, "vector<u8>">;
|
|
13
|
-
aad: import("@haneullabs/bcs").BcsType<Uint8Array<ArrayBufferLike> | null, Iterable<number> | null | undefined, "Option<vector<u8>>">;
|
|
14
|
-
}, string>;
|
|
15
|
-
Hmac256Ctr: import("@haneullabs/bcs").BcsStruct<{
|
|
16
|
-
blob: import("@haneullabs/bcs").BcsType<Uint8Array<ArrayBufferLike>, Iterable<number>, "vector<u8>">;
|
|
17
|
-
aad: import("@haneullabs/bcs").BcsType<Uint8Array<ArrayBufferLike> | null, Iterable<number> | null | undefined, "Option<vector<u8>>">;
|
|
18
|
-
mac: import("@haneullabs/bcs").BcsType<Uint8Array<ArrayBufferLike>, Iterable<number>, "bytes[32]">;
|
|
19
|
-
}, string>;
|
|
20
|
-
Plain: import("@haneullabs/bcs").BcsStruct<{}, string>;
|
|
21
|
-
}, "Ciphertext">;
|
|
22
|
-
/**
|
|
23
|
-
* The encrypted object format. Should be aligned with the Rust implementation.
|
|
24
|
-
*/
|
|
25
|
-
export declare const EncryptedObject: import("@haneullabs/bcs").BcsStruct<{
|
|
26
|
-
version: import("@haneullabs/bcs").BcsType<number, number, "u8">;
|
|
27
|
-
packageId: import("@haneullabs/bcs").BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
|
|
28
|
-
id: import("@haneullabs/bcs").BcsType<string, string, string>;
|
|
29
|
-
services: import("@haneullabs/bcs").BcsType<[string, number][], Iterable<readonly [string | Uint8Array<ArrayBufferLike>, number]> & {
|
|
30
|
-
length: number;
|
|
31
|
-
}, string>;
|
|
32
|
-
threshold: import("@haneullabs/bcs").BcsType<number, number, "u8">;
|
|
33
|
-
encryptedShares: import("@haneullabs/bcs").BcsEnum<{
|
|
34
|
-
BonehFranklinBLS12381: import("@haneullabs/bcs").BcsStruct<{
|
|
35
|
-
nonce: import("@haneullabs/bcs").BcsType<Uint8Array<ArrayBufferLike>, Iterable<number>, "bytes[96]">;
|
|
36
|
-
encryptedShares: import("@haneullabs/bcs").BcsType<Uint8Array<ArrayBufferLike>[], Iterable<Iterable<number>> & {
|
|
37
|
-
length: number;
|
|
38
|
-
}, string>;
|
|
39
|
-
encryptedRandomness: import("@haneullabs/bcs").BcsType<Uint8Array<ArrayBufferLike>, Iterable<number>, "bytes[32]">;
|
|
40
|
-
}, string>;
|
|
41
|
-
}, "IBEEncryptions">;
|
|
42
|
-
ciphertext: import("@haneullabs/bcs").BcsEnum<{
|
|
43
|
-
Aes256Gcm: import("@haneullabs/bcs").BcsStruct<{
|
|
44
|
-
blob: import("@haneullabs/bcs").BcsType<Uint8Array<ArrayBufferLike>, Iterable<number>, "vector<u8>">;
|
|
45
|
-
aad: import("@haneullabs/bcs").BcsType<Uint8Array<ArrayBufferLike> | null, Iterable<number> | null | undefined, "Option<vector<u8>>">;
|
|
46
|
-
}, string>;
|
|
47
|
-
Hmac256Ctr: import("@haneullabs/bcs").BcsStruct<{
|
|
48
|
-
blob: import("@haneullabs/bcs").BcsType<Uint8Array<ArrayBufferLike>, Iterable<number>, "vector<u8>">;
|
|
49
|
-
aad: import("@haneullabs/bcs").BcsType<Uint8Array<ArrayBufferLike> | null, Iterable<number> | null | undefined, "Option<vector<u8>>">;
|
|
50
|
-
mac: import("@haneullabs/bcs").BcsType<Uint8Array<ArrayBufferLike>, Iterable<number>, "bytes[32]">;
|
|
51
|
-
}, string>;
|
|
52
|
-
Plain: import("@haneullabs/bcs").BcsStruct<{}, string>;
|
|
53
|
-
}, "Ciphertext">;
|
|
54
|
-
}, string>;
|
|
55
|
-
/**
|
|
56
|
-
* The Move struct for the KeyServerV1 object.
|
|
57
|
-
*/
|
|
58
|
-
export declare const KeyServerMoveV1: import("@haneullabs/bcs").BcsStruct<{
|
|
59
|
-
name: import("@haneullabs/bcs").BcsType<string, string, "string">;
|
|
60
|
-
url: import("@haneullabs/bcs").BcsType<string, string, "string">;
|
|
61
|
-
keyType: import("@haneullabs/bcs").BcsType<number, number, "u8">;
|
|
62
|
-
pk: import("@haneullabs/bcs").BcsType<Uint8Array<ArrayBufferLike>, Iterable<number>, "vector<u8>">;
|
|
63
|
-
}, string>;
|
|
64
|
-
/**
|
|
65
|
-
* The Move struct for the parent object.
|
|
66
|
-
*/
|
|
67
|
-
export declare const KeyServerMove: import("@haneullabs/bcs").BcsStruct<{
|
|
68
|
-
id: import("@haneullabs/bcs").BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
|
|
69
|
-
firstVersion: import("@haneullabs/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
70
|
-
lastVersion: import("@haneullabs/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
71
|
-
}, string>;
|
package/dist/cjs/bcs.js
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var bcs_exports = {};
|
|
20
|
-
__export(bcs_exports, {
|
|
21
|
-
Ciphertext: () => Ciphertext,
|
|
22
|
-
EncryptedObject: () => EncryptedObject,
|
|
23
|
-
IBEEncryptions: () => IBEEncryptions,
|
|
24
|
-
KeyServerMove: () => KeyServerMove,
|
|
25
|
-
KeyServerMoveV1: () => KeyServerMoveV1
|
|
26
|
-
});
|
|
27
|
-
module.exports = __toCommonJS(bcs_exports);
|
|
28
|
-
var import_bcs = require("@haneullabs/bcs");
|
|
29
|
-
var import_bcs2 = require("@haneullabs/haneul/bcs");
|
|
30
|
-
const IBEEncryptions = import_bcs2.bcs.enum("IBEEncryptions", {
|
|
31
|
-
BonehFranklinBLS12381: import_bcs2.bcs.struct("BonehFranklinBLS12381", {
|
|
32
|
-
nonce: import_bcs2.bcs.bytes(96),
|
|
33
|
-
encryptedShares: import_bcs2.bcs.vector(import_bcs2.bcs.bytes(32)),
|
|
34
|
-
encryptedRandomness: import_bcs2.bcs.bytes(32)
|
|
35
|
-
})
|
|
36
|
-
});
|
|
37
|
-
const Ciphertext = import_bcs2.bcs.enum("Ciphertext", {
|
|
38
|
-
Aes256Gcm: import_bcs2.bcs.struct("Aes256Gcm", {
|
|
39
|
-
blob: import_bcs2.bcs.byteVector(),
|
|
40
|
-
aad: import_bcs2.bcs.option(import_bcs2.bcs.byteVector())
|
|
41
|
-
}),
|
|
42
|
-
Hmac256Ctr: import_bcs2.bcs.struct("Hmac256Ctr", {
|
|
43
|
-
blob: import_bcs2.bcs.byteVector(),
|
|
44
|
-
aad: import_bcs2.bcs.option(import_bcs2.bcs.byteVector()),
|
|
45
|
-
mac: import_bcs2.bcs.bytes(32)
|
|
46
|
-
}),
|
|
47
|
-
Plain: import_bcs2.bcs.struct("Plain", {})
|
|
48
|
-
});
|
|
49
|
-
const EncryptedObject = import_bcs2.bcs.struct("EncryptedObject", {
|
|
50
|
-
version: import_bcs2.bcs.u8(),
|
|
51
|
-
packageId: import_bcs2.bcs.Address,
|
|
52
|
-
id: import_bcs2.bcs.byteVector().transform({
|
|
53
|
-
output: (val) => (0, import_bcs.toHex)(val),
|
|
54
|
-
input: (val) => (0, import_bcs.fromHex)(val)
|
|
55
|
-
}),
|
|
56
|
-
services: import_bcs2.bcs.vector(import_bcs2.bcs.tuple([import_bcs2.bcs.Address, import_bcs2.bcs.u8()])),
|
|
57
|
-
threshold: import_bcs2.bcs.u8(),
|
|
58
|
-
encryptedShares: IBEEncryptions,
|
|
59
|
-
ciphertext: Ciphertext
|
|
60
|
-
});
|
|
61
|
-
const KeyServerMoveV1 = import_bcs2.bcs.struct("KeyServerV1", {
|
|
62
|
-
name: import_bcs2.bcs.string(),
|
|
63
|
-
url: import_bcs2.bcs.string(),
|
|
64
|
-
keyType: import_bcs2.bcs.u8(),
|
|
65
|
-
pk: import_bcs2.bcs.byteVector()
|
|
66
|
-
});
|
|
67
|
-
const KeyServerMove = import_bcs2.bcs.struct("KeyServer", {
|
|
68
|
-
id: import_bcs2.bcs.Address,
|
|
69
|
-
firstVersion: import_bcs2.bcs.u64(),
|
|
70
|
-
// latest version
|
|
71
|
-
lastVersion: import_bcs2.bcs.u64()
|
|
72
|
-
// oldest version
|
|
73
|
-
});
|
|
74
|
-
//# sourceMappingURL=bcs.js.map
|
package/dist/cjs/bcs.js.map
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/bcs.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { fromHex, toHex } from '@haneullabs/bcs';\nimport { bcs } from '@haneullabs/haneul/bcs';\n\nexport const IBEEncryptions = bcs.enum('IBEEncryptions', {\n\tBonehFranklinBLS12381: bcs.struct('BonehFranklinBLS12381', {\n\t\tnonce: bcs.bytes(96),\n\t\tencryptedShares: bcs.vector(bcs.bytes(32)),\n\t\tencryptedRandomness: bcs.bytes(32),\n\t}),\n});\n\nexport const Ciphertext = bcs.enum('Ciphertext', {\n\tAes256Gcm: bcs.struct('Aes256Gcm', {\n\t\tblob: bcs.byteVector(),\n\t\taad: bcs.option(bcs.byteVector()),\n\t}),\n\tHmac256Ctr: bcs.struct('Hmac256Ctr', {\n\t\tblob: bcs.byteVector(),\n\t\taad: bcs.option(bcs.byteVector()),\n\t\tmac: bcs.bytes(32),\n\t}),\n\tPlain: bcs.struct('Plain', {}),\n});\n\n/**\n * The encrypted object format. Should be aligned with the Rust implementation.\n */\nexport const EncryptedObject = bcs.struct('EncryptedObject', {\n\tversion: bcs.u8(),\n\tpackageId: bcs.Address,\n\tid: bcs.byteVector().transform({\n\t\toutput: (val) => toHex(val),\n\t\tinput: (val: string) => fromHex(val),\n\t}),\n\tservices: bcs.vector(bcs.tuple([bcs.Address, bcs.u8()])),\n\tthreshold: bcs.u8(),\n\tencryptedShares: IBEEncryptions,\n\tciphertext: Ciphertext,\n});\n\n/**\n * The Move struct for the KeyServerV1 object.\n */\nexport const KeyServerMoveV1 = bcs.struct('KeyServerV1', {\n\tname: bcs.string(),\n\turl: bcs.string(),\n\tkeyType: bcs.u8(),\n\tpk: bcs.byteVector(),\n});\n\n/**\n * The Move struct for the parent object.\n */\nexport const KeyServerMove = bcs.struct('KeyServer', {\n\tid: bcs.Address,\n\tfirstVersion: bcs.u64(), // latest version\n\tlastVersion: bcs.u64(), // oldest version\n});\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,iBAA+B;AAC/B,IAAAA,cAAoB;AAEb,MAAM,iBAAiB,gBAAI,KAAK,kBAAkB;AAAA,EACxD,uBAAuB,gBAAI,OAAO,yBAAyB;AAAA,IAC1D,OAAO,gBAAI,MAAM,EAAE;AAAA,IACnB,iBAAiB,gBAAI,OAAO,gBAAI,MAAM,EAAE,CAAC;AAAA,IACzC,qBAAqB,gBAAI,MAAM,EAAE;AAAA,EAClC,CAAC;AACF,CAAC;AAEM,MAAM,aAAa,gBAAI,KAAK,cAAc;AAAA,EAChD,WAAW,gBAAI,OAAO,aAAa;AAAA,IAClC,MAAM,gBAA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WeierstrassPoint } from '@noble/curves/abstract/weierstrass';
|
|
3
|
-
export declare class G1Element {
|
|
4
|
-
point: WeierstrassPoint<bigint>;
|
|
5
|
-
static readonly SIZE = 48;
|
|
6
|
-
constructor(point: WeierstrassPoint<bigint>);
|
|
7
|
-
static generator(): G1Element;
|
|
8
|
-
static fromBytes(bytes: Uint8Array): G1Element;
|
|
9
|
-
toBytes(): Uint8Array<ArrayBuffer>;
|
|
10
|
-
multiply(scalar: Scalar): G1Element;
|
|
11
|
-
add(other: G1Element): G1Element;
|
|
12
|
-
subtract(other: G1Element): G1Element;
|
|
13
|
-
static hashToCurve(data: Uint8Array): G1Element;
|
|
14
|
-
pairing(other: G2Element): GTElement;
|
|
15
|
-
}
|
|
16
|
-
export declare class G2Element {
|
|
17
|
-
point: WeierstrassPoint<Fp2>;
|
|
18
|
-
static readonly SIZE = 96;
|
|
19
|
-
constructor(point: WeierstrassPoint<Fp2>);
|
|
20
|
-
static generator(): G2Element;
|
|
21
|
-
static fromBytes(bytes: Uint8Array): G2Element;
|
|
22
|
-
toBytes(): Uint8Array<ArrayBuffer>;
|
|
23
|
-
multiply(scalar: Scalar): G2Element;
|
|
24
|
-
add(other: G2Element): G2Element;
|
|
25
|
-
static hashToCurve(data: Uint8Array): G2Element;
|
|
26
|
-
equals(other: G2Element): boolean;
|
|
27
|
-
}
|
|
28
|
-
export declare class GTElement {
|
|
29
|
-
element: Fp12;
|
|
30
|
-
static readonly SIZE = 576;
|
|
31
|
-
constructor(element: Fp12);
|
|
32
|
-
toBytes(): Uint8Array<ArrayBuffer>;
|
|
33
|
-
equals(other: GTElement): boolean;
|
|
34
|
-
}
|
|
35
|
-
export declare class Scalar {
|
|
36
|
-
scalar: bigint;
|
|
37
|
-
static readonly SIZE = 32;
|
|
38
|
-
constructor(scalar: bigint);
|
|
39
|
-
static fromBigint(scalar: bigint): Scalar;
|
|
40
|
-
static random(): Scalar;
|
|
41
|
-
toBytes(): Uint8Array;
|
|
42
|
-
static fromBytes(bytes: Uint8Array): Scalar;
|
|
43
|
-
static fromBytesLE(bytes: Uint8Array): Scalar;
|
|
44
|
-
}
|