@haneullabs/signers 0.1.0 → 1.0.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 +121 -74
- package/README.md +11 -8
- package/dist/aws/aws-client.d.mts +48 -0
- package/dist/aws/aws-client.d.mts.map +1 -0
- package/dist/aws/aws-client.mjs +46 -0
- package/dist/aws/aws-client.mjs.map +1 -0
- package/dist/aws/aws-kms-signer.d.mts +63 -0
- package/dist/aws/aws-kms-signer.d.mts.map +1 -0
- package/dist/aws/aws-kms-signer.mjs +78 -0
- package/dist/aws/aws-kms-signer.mjs.map +1 -0
- package/dist/aws/aws4fetch.d.mts +62 -0
- package/dist/aws/aws4fetch.d.mts.map +1 -0
- package/dist/aws/aws4fetch.mjs +313 -0
- package/dist/aws/aws4fetch.mjs.map +1 -0
- package/dist/aws/index.d.mts +3 -0
- package/dist/aws/index.mjs +3 -0
- package/dist/gcp/gcp-kms-client.d.mts +71 -0
- package/dist/gcp/gcp-kms-client.d.mts.map +1 -0
- package/dist/gcp/gcp-kms-client.mjs +104 -0
- package/dist/gcp/gcp-kms-client.mjs.map +1 -0
- package/dist/gcp/index.d.mts +2 -0
- package/dist/gcp/index.mjs +3 -0
- package/dist/ledger/index.d.mts +74 -0
- package/dist/ledger/index.d.mts.map +1 -0
- package/dist/ledger/index.mjs +110 -0
- package/dist/ledger/index.mjs.map +1 -0
- package/dist/ledger/objects.d.mts +10 -0
- package/dist/ledger/objects.d.mts.map +1 -0
- package/dist/ledger/objects.mjs +16 -0
- package/dist/ledger/objects.mjs.map +1 -0
- package/dist/utils/utils.mjs +71 -0
- package/dist/utils/utils.mjs.map +1 -0
- package/dist/webcrypto/index.d.mts +32 -0
- package/dist/webcrypto/index.d.mts.map +1 -0
- package/dist/webcrypto/index.mjs +70 -0
- package/dist/webcrypto/index.mjs.map +1 -0
- package/package.json +35 -29
- package/src/aws/aws-kms-signer.ts +0 -9
- package/src/gcp/gcp-kms-client.ts +0 -9
- package/src/ledger/index.ts +8 -9
- package/src/ledger/objects.ts +10 -34
- package/src/utils/utils.ts +18 -10
- package/src/webcrypto/index.ts +6 -3
- package/aws/package.json +0 -6
- package/dist/cjs/aws/aws-client.d.ts +0 -43
- package/dist/cjs/aws/aws-client.js +0 -79
- package/dist/cjs/aws/aws-client.js.map +0 -7
- package/dist/cjs/aws/aws-kms-signer.d.ts +0 -61
- package/dist/cjs/aws/aws-kms-signer.js +0 -114
- package/dist/cjs/aws/aws-kms-signer.js.map +0 -7
- package/dist/cjs/aws/aws4fetch.d.ts +0 -125
- package/dist/cjs/aws/aws4fetch.js +0 -382
- package/dist/cjs/aws/aws4fetch.js.map +0 -7
- package/dist/cjs/aws/index.d.ts +0 -5
- package/dist/cjs/aws/index.js +0 -25
- package/dist/cjs/aws/index.js.map +0 -7
- package/dist/cjs/gcp/gcp-kms-client.d.ts +0 -68
- package/dist/cjs/gcp/gcp-kms-client.js +0 -147
- package/dist/cjs/gcp/gcp-kms-client.js.map +0 -7
- package/dist/cjs/gcp/index.d.ts +0 -4
- package/dist/cjs/gcp/index.js +0 -25
- package/dist/cjs/gcp/index.js.map +0 -7
- package/dist/cjs/ledger/bcs.d.ts +0 -14
- package/dist/cjs/ledger/bcs.js +0 -85
- package/dist/cjs/ledger/bcs.js.map +0 -7
- package/dist/cjs/ledger/index.d.ts +0 -66
- package/dist/cjs/ledger/index.js +0 -158
- package/dist/cjs/ledger/index.js.map +0 -7
- package/dist/cjs/ledger/objects.d.ts +0 -5
- package/dist/cjs/ledger/objects.js +0 -60
- package/dist/cjs/ledger/objects.js.map +0 -7
- package/dist/cjs/package.json +0 -5
- package/dist/cjs/utils/utils.d.ts +0 -18
- package/dist/cjs/utils/utils.js +0 -85
- package/dist/cjs/utils/utils.js.map +0 -7
- package/dist/cjs/webcrypto/index.d.ts +0 -26
- package/dist/cjs/webcrypto/index.js +0 -112
- package/dist/cjs/webcrypto/index.js.map +0 -7
- package/dist/esm/aws/aws-client.d.ts +0 -43
- package/dist/esm/aws/aws-client.js +0 -59
- package/dist/esm/aws/aws-client.js.map +0 -7
- package/dist/esm/aws/aws-kms-signer.d.ts +0 -61
- package/dist/esm/aws/aws-kms-signer.js +0 -94
- package/dist/esm/aws/aws-kms-signer.js.map +0 -7
- package/dist/esm/aws/aws4fetch.d.ts +0 -125
- package/dist/esm/aws/aws4fetch.js +0 -362
- package/dist/esm/aws/aws4fetch.js.map +0 -7
- package/dist/esm/aws/index.d.ts +0 -5
- package/dist/esm/aws/index.js +0 -5
- package/dist/esm/aws/index.js.map +0 -7
- package/dist/esm/gcp/gcp-kms-client.d.ts +0 -68
- package/dist/esm/gcp/gcp-kms-client.js +0 -127
- package/dist/esm/gcp/gcp-kms-client.js.map +0 -7
- package/dist/esm/gcp/index.d.ts +0 -4
- package/dist/esm/gcp/index.js +0 -5
- package/dist/esm/gcp/index.js.map +0 -7
- package/dist/esm/ledger/bcs.d.ts +0 -14
- package/dist/esm/ledger/bcs.js +0 -70
- package/dist/esm/ledger/bcs.js.map +0 -7
- package/dist/esm/ledger/index.d.ts +0 -66
- package/dist/esm/ledger/index.js +0 -138
- package/dist/esm/ledger/index.js.map +0 -7
- package/dist/esm/ledger/objects.d.ts +0 -5
- package/dist/esm/ledger/objects.js +0 -40
- package/dist/esm/ledger/objects.js.map +0 -7
- package/dist/esm/package.json +0 -5
- package/dist/esm/utils/utils.d.ts +0 -18
- package/dist/esm/utils/utils.js +0 -65
- package/dist/esm/utils/utils.js.map +0 -7
- package/dist/esm/webcrypto/index.d.ts +0 -26
- package/dist/esm/webcrypto/index.js +0 -92
- package/dist/esm/webcrypto/index.js.map +0 -7
- package/dist/tsconfig.esm.tsbuildinfo +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/gcp/package.json +0 -6
- package/ledger/package.json +0 -6
- package/src/ledger/bcs.ts +0 -87
- package/webcrypto/package.json +0 -6
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/ledger/index.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type HaneulLedgerClient from '@haneullabs/ledgerjs-hw-app-haneul';\nimport type { HaneulClient } from '@haneullabs/haneul/client';\nimport type { SignatureWithBytes } from '@haneullabs/haneul/cryptography';\nimport { messageWithIntent, Signer, toSerializedSignature } from '@haneullabs/haneul/cryptography';\nimport { Ed25519PublicKey } from '@haneullabs/haneul/keypairs/ed25519';\nimport { Transaction } from '@haneullabs/haneul/transactions';\nimport { toBase64 } from '@haneullabs/haneul/utils';\n\nimport { bcs } from '@haneullabs/haneul/bcs';\nimport { getInputObjects } from './objects.js';\nimport type { Resolution } from '@haneullabs/ledgerjs-hw-app-haneul';\n\nexport { HaneulMoveObject } from './bcs.js';\nexport { getInputObjects } from './objects.js';\n\n/**\n * Configuration options for initializing the LedgerSigner.\n */\nexport interface LedgerSignerOptions {\n\tpublicKey: Ed25519PublicKey;\n\tderivationPath: string;\n\tledgerClient: HaneulLedgerClient;\n\thaneulClient: HaneulClient;\n}\n\n/**\n * Ledger integrates with the Haneul blockchain to provide signing capabilities using Ledger devices.\n */\nexport class LedgerSigner extends Signer {\n\t#derivationPath: string;\n\t#publicKey: Ed25519PublicKey;\n\t#ledgerClient: HaneulLedgerClient;\n\t#haneulClient: HaneulClient;\n\n\t/**\n\t * Creates an instance of LedgerSigner. It's expected to call the static `fromDerivationPath` method to create an instance.\n\t * @example\n\t * ```\n\t * const signer = await LedgerSigner.fromDerivationPath(derivationPath, options);\n\t * ```\n\t */\n\tconstructor({ publicKey, derivationPath, ledgerClient, haneulClient }: LedgerSignerOptions) {\n\t\tsuper();\n\t\tthis.#publicKey = publicKey;\n\t\tthis.#derivationPath = derivationPath;\n\t\tthis.#ledgerClient = ledgerClient;\n\t\tthis.#haneulClient = haneulClient;\n\t}\n\n\t/**\n\t * Retrieves the key scheme used by this signer.\n\t */\n\toverride getKeyScheme() {\n\t\treturn 'ED25519' as const;\n\t}\n\n\t/**\n\t * Retrieves the public key associated with this signer.\n\t * @returns The Ed25519PublicKey instance.\n\t */\n\toverride getPublicKey() {\n\t\treturn this.#publicKey;\n\t}\n\n\t/**\n\t * Signs the provided transaction bytes.\n\t * @returns The signed transaction bytes and signature.\n\t */\n\toverride async signTransaction(\n\t\tbytes: Uint8Array,\n\t\tbcsObjects?: Uint8Array[],\n\t\tresolution?: Resolution,\n\t): Promise<SignatureWithBytes> {\n\t\tconst transactionOptions = bcsObjects\n\t\t\t? { bcsObjects }\n\t\t\t: await getInputObjects(Transaction.from(bytes), this.#haneulClient).catch(() => ({\n\t\t\t\t\t// Fail gracefully so network errors or serialization issues don't break transaction signing:\n\t\t\t\t\tbcsObjects: [],\n\t\t\t\t}));\n\n\t\tconst intentMessage = messageWithIntent('TransactionData', bytes);\n\t\tconst { signature } = await this.#ledgerClient.signTransaction(\n\t\t\tthis.#derivationPath,\n\t\t\tintentMessage,\n\t\t\ttransactionOptions,\n\t\t\tresolution,\n\t\t);\n\n\t\treturn {\n\t\t\tbytes: toBase64(bytes),\n\t\t\tsignature: toSerializedSignature({\n\t\t\t\tsignature,\n\t\t\t\tsignatureScheme: this.getKeyScheme(),\n\t\t\t\tpublicKey: this.#publicKey,\n\t\t\t}),\n\t\t};\n\t}\n\n\t/**\n\t * Signs the provided personal message.\n\t * @returns The signed message bytes and signature.\n\t */\n\toverride async signPersonalMessage(bytes: Uint8Array): Promise<SignatureWithBytes> {\n\t\tconst intentMessage = messageWithIntent(\n\t\t\t'PersonalMessage',\n\t\t\tbcs.byteVector().serialize(bytes).toBytes(),\n\t\t);\n\t\tconst { signature } = await this.#ledgerClient.signTransaction(\n\t\t\tthis.#derivationPath,\n\t\t\tintentMessage,\n\t\t);\n\n\t\treturn {\n\t\t\tbytes: toBase64(bytes),\n\t\t\tsignature: toSerializedSignature({\n\t\t\t\tsignature,\n\t\t\t\tsignatureScheme: this.getKeyScheme(),\n\t\t\t\tpublicKey: this.#publicKey,\n\t\t\t}),\n\t\t};\n\t}\n\n\t/**\n\t * Prepares the signer by fetching and setting the public key from a Ledger device.\n\t * It is recommended to initialize an `LedgerSigner` instance using this function.\n\t * @returns A promise that resolves once a `LedgerSigner` instance is prepared (public key is set).\n\t */\n\tstatic async fromDerivationPath(\n\t\tderivationPath: string,\n\t\tledgerClient: HaneulLedgerClient,\n\t\thaneulClient: HaneulClient,\n\t) {\n\t\tconst { publicKey } = await ledgerClient.getPublicKey(derivationPath);\n\t\tif (!publicKey) {\n\t\t\tthrow new Error('Failed to get public key from Ledger.');\n\t\t}\n\n\t\treturn new LedgerSigner({\n\t\t\tderivationPath,\n\t\t\tpublicKey: new Ed25519PublicKey(publicKey),\n\t\t\tledgerClient,\n\t\t\thaneulClient,\n\t\t});\n\t}\n\n\t/**\n\t * Generic signing is not supported by Ledger.\n\t * @throws Always throws an error indicating generic signing is unsupported.\n\t */\n\toverride sign(): never {\n\t\tthrow new Error('Ledger Signer does not support generic signing.');\n\t}\n\n\t/**\n\t * Generic signing is not supported by Ledger.\n\t * @throws Always throws an error indicating generic signing is unsupported.\n\t */\n\toverride signWithIntent(): never {\n\t\tthrow new Error('Ledger Signer does not support generic signing.');\n\t}\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;AAAA;AAMA,SAAS,mBAAmB,QAAQ,6BAA6B;AACjE,SAAS,wBAAwB;AACjC,SAAS,mBAAmB;AAC5B,SAAS,gBAAgB;AAEzB,SAAS,WAAW;AACpB,SAAS,uBAAuB;AAGhC,SAAS,wBAAwB;AACjC,SAAS,mBAAAA,wBAAuB;AAezB,MAAM,gBAAN,MAAM,sBAAqB,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAaxC,YAAY,EAAE,WAAW,gBAAgB,cAAc,aAAa,GAAwB;AAC3F,UAAM;AAbP;AACA;AACA;AACA;AAWC,uBAAK,YAAa;AAClB,uBAAK,iBAAkB;AACvB,uBAAK,eAAgB;AACrB,uBAAK,eAAgB;AAAA,EACtB;AAAA;AAAA;AAAA;AAAA,EAKS,eAAe;AACvB,WAAO;AAAA,EACR;AAAA;AAAA;AAAA;AAAA;AAAA,EAMS,eAAe;AACvB,WAAO,mBAAK;AAAA,EACb;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAe,gBACd,OACA,YACA,YAC8B;AAC9B,UAAM,qBAAqB,aACxB,EAAE,WAAW,IACb,MAAM,gBAAgB,YAAY,KAAK,KAAK,GAAG,mBAAK,cAAa,EAAE,MAAM,OAAO;AAAA;AAAA,MAEhF,YAAY,CAAC;AAAA,IACd,EAAE;AAEJ,UAAM,gBAAgB,kBAAkB,mBAAmB,KAAK;AAChE,UAAM,EAAE,UAAU,IAAI,MAAM,mBAAK,eAAc;AAAA,MAC9C,mBAAK;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,IACD;AAEA,WAAO;AAAA,MACN,OAAO,SAAS,KAAK;AAAA,MACrB,WAAW,sBAAsB;AAAA,QAChC;AAAA,QACA,iBAAiB,KAAK,aAAa;AAAA,QACnC,WAAW,mBAAK;AAAA,MACjB,CAAC;AAAA,IACF;AAAA,EACD;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAe,oBAAoB,OAAgD;AAClF,UAAM,gBAAgB;AAAA,MACrB;AAAA,MACA,IAAI,WAAW,EAAE,UAAU,KAAK,EAAE,QAAQ;AAAA,IAC3C;AACA,UAAM,EAAE,UAAU,IAAI,MAAM,mBAAK,eAAc;AAAA,MAC9C,mBAAK;AAAA,MACL;AAAA,IACD;AAEA,WAAO;AAAA,MACN,OAAO,SAAS,KAAK;AAAA,MACrB,WAAW,sBAAsB;AAAA,QAChC;AAAA,QACA,iBAAiB,KAAK,aAAa;AAAA,QACnC,WAAW,mBAAK;AAAA,MACjB,CAAC;AAAA,IACF;AAAA,EACD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,aAAa,mBACZ,gBACA,cACA,cACC;AACD,UAAM,EAAE,UAAU,IAAI,MAAM,aAAa,aAAa,cAAc;AACpE,QAAI,CAAC,WAAW;AACf,YAAM,IAAI,MAAM,uCAAuC;AAAA,IACxD;AAEA,WAAO,IAAI,cAAa;AAAA,MACvB;AAAA,MACA,WAAW,IAAI,iBAAiB,SAAS;AAAA,MACzC;AAAA,MACA;AAAA,IACD,CAAC;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA,EAMS,OAAc;AACtB,UAAM,IAAI,MAAM,iDAAiD;AAAA,EAClE;AAAA;AAAA;AAAA;AAAA;AAAA,EAMS,iBAAwB;AAChC,UAAM,IAAI,MAAM,iDAAiD;AAAA,EAClE;AACD;AAnIC;AACA;AACA;AACA;AAJM,IAAM,eAAN;",
|
|
6
|
-
"names": ["getInputObjects"]
|
|
7
|
-
}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { Transaction } from '@haneullabs/haneul/transactions';
|
|
2
|
-
import type { HaneulClient } from '@haneullabs/haneul/client';
|
|
3
|
-
export declare const getInputObjects: (transaction: Transaction, client: HaneulClient) => Promise<{
|
|
4
|
-
bcsObjects: Uint8Array<ArrayBuffer>[];
|
|
5
|
-
}>;
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { HaneulMoveObject } from "./bcs.js";
|
|
2
|
-
const getInputObjects = async (transaction, client) => {
|
|
3
|
-
const data = transaction.getData();
|
|
4
|
-
const gasObjectIds = data.gasData.payment?.map((object) => object.objectId) ?? [];
|
|
5
|
-
const inputObjectIds = data.inputs.map((input) => {
|
|
6
|
-
return input.$kind === "Object" && input.Object.$kind === "ImmOrOwnedObject" ? input.Object.ImmOrOwnedObject.objectId : null;
|
|
7
|
-
}).filter((objectId) => !!objectId);
|
|
8
|
-
const objects = await client.multiGetObjects({
|
|
9
|
-
ids: [...gasObjectIds, ...inputObjectIds],
|
|
10
|
-
options: {
|
|
11
|
-
showBcs: true,
|
|
12
|
-
showPreviousTransaction: true,
|
|
13
|
-
showStorageRebate: true,
|
|
14
|
-
showOwner: true
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
const bcsObjects = objects.map((object) => {
|
|
18
|
-
if (object.error || !object.data || object.data.bcs?.dataType !== "moveObject") {
|
|
19
|
-
return null;
|
|
20
|
-
}
|
|
21
|
-
return HaneulMoveObject.serialize({
|
|
22
|
-
data: {
|
|
23
|
-
MoveObject: {
|
|
24
|
-
type: object.data.bcs.type,
|
|
25
|
-
hasPublicTransfer: object.data.bcs.hasPublicTransfer,
|
|
26
|
-
version: object.data.bcs.version,
|
|
27
|
-
contents: object.data.bcs.bcsBytes
|
|
28
|
-
}
|
|
29
|
-
},
|
|
30
|
-
owner: object.data.owner,
|
|
31
|
-
previousTransaction: object.data.previousTransaction,
|
|
32
|
-
storageRebate: object.data.storageRebate
|
|
33
|
-
}).toBytes();
|
|
34
|
-
}).filter((bcsBytes) => !!bcsBytes);
|
|
35
|
-
return { bcsObjects };
|
|
36
|
-
};
|
|
37
|
-
export {
|
|
38
|
-
getInputObjects
|
|
39
|
-
};
|
|
40
|
-
//# sourceMappingURL=objects.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/ledger/objects.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { Transaction } from '@haneullabs/haneul/transactions';\nimport type { HaneulClient } from '@haneullabs/haneul/client';\nimport { HaneulMoveObject } from './bcs.js';\n\nexport const getInputObjects = async (transaction: Transaction, client: HaneulClient) => {\n\tconst data = transaction.getData();\n\n\tconst gasObjectIds = data.gasData.payment?.map((object) => object.objectId) ?? [];\n\tconst inputObjectIds = data.inputs\n\t\t.map((input) => {\n\t\t\treturn input.$kind === 'Object' && input.Object.$kind === 'ImmOrOwnedObject'\n\t\t\t\t? input.Object.ImmOrOwnedObject.objectId\n\t\t\t\t: null;\n\t\t})\n\t\t.filter((objectId): objectId is string => !!objectId);\n\n\tconst objects = await client.multiGetObjects({\n\t\tids: [...gasObjectIds, ...inputObjectIds],\n\t\toptions: {\n\t\t\tshowBcs: true,\n\t\t\tshowPreviousTransaction: true,\n\t\t\tshowStorageRebate: true,\n\t\t\tshowOwner: true,\n\t\t},\n\t});\n\n\t// NOTE: We should probably get rid of this manual serialization logic in favor of using the\n\t// already serialized object bytes from the GraphQL API once there is more mainstream support\n\t// for it + we can enforce the transport type on the Haneul client.\n\tconst bcsObjects = objects\n\t\t.map((object) => {\n\t\t\tif (object.error || !object.data || object.data.bcs?.dataType !== 'moveObject') {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\treturn HaneulMoveObject.serialize({\n\t\t\t\tdata: {\n\t\t\t\t\tMoveObject: {\n\t\t\t\t\t\ttype: object.data.bcs.type,\n\t\t\t\t\t\thasPublicTransfer: object.data.bcs.hasPublicTransfer,\n\t\t\t\t\t\tversion: object.data.bcs.version,\n\t\t\t\t\t\tcontents: object.data.bcs.bcsBytes,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\towner: object.data.owner!,\n\t\t\t\tpreviousTransaction: object.data.previousTransaction!,\n\t\t\t\tstorageRebate: object.data.storageRebate!,\n\t\t\t}).toBytes();\n\t\t})\n\t\t.filter((bcsBytes): bcsBytes is Uint8Array<ArrayBuffer> => !!bcsBytes);\n\n\treturn { bcsObjects };\n};\n"],
|
|
5
|
-
"mappings": "AAKA,SAAS,wBAAwB;AAE1B,MAAM,kBAAkB,OAAO,aAA0B,WAAyB;AACxF,QAAM,OAAO,YAAY,QAAQ;AAEjC,QAAM,eAAe,KAAK,QAAQ,SAAS,IAAI,CAAC,WAAW,OAAO,QAAQ,KAAK,CAAC;AAChF,QAAM,iBAAiB,KAAK,OAC1B,IAAI,CAAC,UAAU;AACf,WAAO,MAAM,UAAU,YAAY,MAAM,OAAO,UAAU,qBACvD,MAAM,OAAO,iBAAiB,WAC9B;AAAA,EACJ,CAAC,EACA,OAAO,CAAC,aAAiC,CAAC,CAAC,QAAQ;AAErD,QAAM,UAAU,MAAM,OAAO,gBAAgB;AAAA,IAC5C,KAAK,CAAC,GAAG,cAAc,GAAG,cAAc;AAAA,IACxC,SAAS;AAAA,MACR,SAAS;AAAA,MACT,yBAAyB;AAAA,MACzB,mBAAmB;AAAA,MACnB,WAAW;AAAA,IACZ;AAAA,EACD,CAAC;AAKD,QAAM,aAAa,QACjB,IAAI,CAAC,WAAW;AAChB,QAAI,OAAO,SAAS,CAAC,OAAO,QAAQ,OAAO,KAAK,KAAK,aAAa,cAAc;AAC/E,aAAO;AAAA,IACR;AAEA,WAAO,iBAAiB,UAAU;AAAA,MACjC,MAAM;AAAA,QACL,YAAY;AAAA,UACX,MAAM,OAAO,KAAK,IAAI;AAAA,UACtB,mBAAmB,OAAO,KAAK,IAAI;AAAA,UACnC,SAAS,OAAO,KAAK,IAAI;AAAA,UACzB,UAAU,OAAO,KAAK,IAAI;AAAA,QAC3B;AAAA,MACD;AAAA,MACA,OAAO,OAAO,KAAK;AAAA,MACnB,qBAAqB,OAAO,KAAK;AAAA,MACjC,eAAe,OAAO,KAAK;AAAA,IAC5B,CAAC,EAAE,QAAQ;AAAA,EACZ,CAAC,EACA,OAAO,CAAC,aAAkD,CAAC,CAAC,QAAQ;AAEtE,SAAO,EAAE,WAAW;AACrB;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
package/dist/esm/package.json
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/** The total number of bits in the DER bit string for the uncompressed public key. */
|
|
2
|
-
export declare const DER_BIT_STRING_LENGTH = 520;
|
|
3
|
-
/** The total number of bytes corresponding to the DER bit string length. */
|
|
4
|
-
export declare const DER_BYTES_LENGTH: number;
|
|
5
|
-
export declare function publicKeyFromDER(derBytes: Uint8Array): Uint8Array<ArrayBufferLike>;
|
|
6
|
-
export declare function getConcatenatedSignature(signature: Uint8Array, keyScheme: string): Uint8Array<ArrayBuffer>;
|
|
7
|
-
/**
|
|
8
|
-
* Compresses an uncompressed public key into its compressed form.
|
|
9
|
-
*
|
|
10
|
-
* The uncompressed key must follow the DER bit string format as specified in [RFC 5480](https://datatracker.ietf.org/doc/html/rfc5480#section-2.2)
|
|
11
|
-
* and [SEC 1: Elliptic Curve Cryptography](https://www.secg.org/sec1-v2.pdf).
|
|
12
|
-
*
|
|
13
|
-
* @param uncompressedKey - A `Uint8ClampedArray` representing the uncompressed public key bits.
|
|
14
|
-
* @returns A `Uint8Array` containing the compressed public key.
|
|
15
|
-
*
|
|
16
|
-
* @throws {Error} If the uncompressed key has an unexpected length or does not start with the expected prefix.
|
|
17
|
-
*/
|
|
18
|
-
export declare function compressPublicKeyClamped(uncompressedKey: Uint8ClampedArray): Uint8Array;
|
package/dist/esm/utils/utils.js
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { secp256r1 } from "@noble/curves/p256";
|
|
2
|
-
import { secp256k1 } from "@noble/curves/secp256k1";
|
|
3
|
-
import { ASN1Construction, ASN1TagClass, DERElement } from "asn1-ts";
|
|
4
|
-
const DER_BIT_STRING_LENGTH = 520;
|
|
5
|
-
const DER_BYTES_LENGTH = DER_BIT_STRING_LENGTH / 8;
|
|
6
|
-
function bitsToBytes(bitsArray) {
|
|
7
|
-
const bytes = new Uint8Array(DER_BYTES_LENGTH);
|
|
8
|
-
for (let i = 0; i < DER_BIT_STRING_LENGTH; i++) {
|
|
9
|
-
if (bitsArray[i] === 1) {
|
|
10
|
-
bytes[Math.floor(i / 8)] |= 1 << 7 - i % 8;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
return bytes;
|
|
14
|
-
}
|
|
15
|
-
function publicKeyFromDER(derBytes) {
|
|
16
|
-
const encodedData = derBytes;
|
|
17
|
-
const derElement = new DERElement();
|
|
18
|
-
derElement.fromBytes(encodedData);
|
|
19
|
-
if (!(derElement.tagClass === ASN1TagClass.universal && derElement.construction === ASN1Construction.constructed)) {
|
|
20
|
-
throw new Error("Unexpected ASN.1 structure");
|
|
21
|
-
}
|
|
22
|
-
const components = derElement.components;
|
|
23
|
-
const publicKeyElement = components[1];
|
|
24
|
-
if (!publicKeyElement) {
|
|
25
|
-
throw new Error("Public Key not found in the DER structure");
|
|
26
|
-
}
|
|
27
|
-
return compressPublicKeyClamped(publicKeyElement.bitString);
|
|
28
|
-
}
|
|
29
|
-
function getConcatenatedSignature(signature, keyScheme) {
|
|
30
|
-
if (!signature || signature.length === 0) {
|
|
31
|
-
throw new Error("Invalid signature");
|
|
32
|
-
}
|
|
33
|
-
const derElement = new DERElement();
|
|
34
|
-
derElement.fromBytes(signature);
|
|
35
|
-
const [r, s] = derElement.toJSON();
|
|
36
|
-
switch (keyScheme) {
|
|
37
|
-
case "Secp256k1":
|
|
38
|
-
return new secp256k1.Signature(BigInt(r), BigInt(s)).normalizeS().toCompactRawBytes();
|
|
39
|
-
case "Secp256r1":
|
|
40
|
-
return new secp256r1.Signature(BigInt(r), BigInt(s)).normalizeS().toCompactRawBytes();
|
|
41
|
-
default:
|
|
42
|
-
throw new Error("Unsupported key scheme");
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
function compressPublicKeyClamped(uncompressedKey) {
|
|
46
|
-
if (uncompressedKey.length !== DER_BIT_STRING_LENGTH) {
|
|
47
|
-
throw new Error("Unexpected length for an uncompressed public key");
|
|
48
|
-
}
|
|
49
|
-
const uncompressedBytes = bitsToBytes(uncompressedKey);
|
|
50
|
-
if (uncompressedBytes[0] !== 4) {
|
|
51
|
-
throw new Error("Public key does not start with 0x04");
|
|
52
|
-
}
|
|
53
|
-
const xCoord = uncompressedBytes.slice(1, 33);
|
|
54
|
-
const yCoordLastByte = uncompressedBytes[64];
|
|
55
|
-
const parityByte = yCoordLastByte % 2 === 0 ? 2 : 3;
|
|
56
|
-
return new Uint8Array([parityByte, ...xCoord]);
|
|
57
|
-
}
|
|
58
|
-
export {
|
|
59
|
-
DER_BIT_STRING_LENGTH,
|
|
60
|
-
DER_BYTES_LENGTH,
|
|
61
|
-
compressPublicKeyClamped,
|
|
62
|
-
getConcatenatedSignature,
|
|
63
|
-
publicKeyFromDER
|
|
64
|
-
};
|
|
65
|
-
//# sourceMappingURL=utils.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/utils/utils.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { secp256r1 } from '@noble/curves/p256';\nimport { secp256k1 } from '@noble/curves/secp256k1';\nimport { ASN1Construction, ASN1TagClass, DERElement } from 'asn1-ts';\n\n/** The total number of bits in the DER bit string for the uncompressed public key. */\nexport const DER_BIT_STRING_LENGTH = 520;\n\n/** The total number of bytes corresponding to the DER bit string length. */\nexport const DER_BYTES_LENGTH = DER_BIT_STRING_LENGTH / 8;\n\n// Reference Specifications:\n// https://datatracker.ietf.org/doc/html/rfc5480#section-2.2\n// https://www.secg.org/sec1-v2.pdf\n\n/**\n * Converts an array of bits into a byte array.\n *\n * @param bitsArray - A `Uint8ClampedArray` representing the bits to convert.\n * @returns A `Uint8Array` containing the corresponding bytes.\n *\n * @throws {Error} If the input array does not have the expected length.\n */\nfunction bitsToBytes(bitsArray: Uint8ClampedArray): Uint8Array {\n\tconst bytes = new Uint8Array(DER_BYTES_LENGTH);\n\tfor (let i = 0; i < DER_BIT_STRING_LENGTH; i++) {\n\t\tif (bitsArray[i] === 1) {\n\t\t\tbytes[Math.floor(i / 8)] |= 1 << (7 - (i % 8));\n\t\t}\n\t}\n\treturn bytes;\n}\n\nexport function publicKeyFromDER(derBytes: Uint8Array) {\n\tconst encodedData: Uint8Array = derBytes;\n\tconst derElement = new DERElement();\n\tderElement.fromBytes(encodedData);\n\n\t// Validate the ASN.1 structure of the public key\n\tif (\n\t\t!(\n\t\t\tderElement.tagClass === ASN1TagClass.universal &&\n\t\t\tderElement.construction === ASN1Construction.constructed\n\t\t)\n\t) {\n\t\tthrow new Error('Unexpected ASN.1 structure');\n\t}\n\n\tconst components = derElement.components;\n\tconst publicKeyElement = components[1];\n\n\tif (!publicKeyElement) {\n\t\tthrow new Error('Public Key not found in the DER structure');\n\t}\n\n\treturn compressPublicKeyClamped(publicKeyElement.bitString);\n}\n\nexport function getConcatenatedSignature(signature: Uint8Array, keyScheme: string) {\n\tif (!signature || signature.length === 0) {\n\t\tthrow new Error('Invalid signature');\n\t}\n\n\t// Initialize a DERElement to parse the DER-encoded signature\n\tconst derElement = new DERElement();\n\tderElement.fromBytes(signature);\n\n\tconst [r, s] = derElement.toJSON() as [string, string];\n\n\tswitch (keyScheme) {\n\t\tcase 'Secp256k1':\n\t\t\treturn new secp256k1.Signature(BigInt(r), BigInt(s))\n\t\t\t\t.normalizeS()\n\t\t\t\t.toCompactRawBytes() as Uint8Array<ArrayBuffer>;\n\t\tcase 'Secp256r1':\n\t\t\treturn new secp256r1.Signature(BigInt(r), BigInt(s))\n\t\t\t\t.normalizeS()\n\t\t\t\t.toCompactRawBytes() as Uint8Array<ArrayBuffer>;\n\t\tdefault:\n\t\t\tthrow new Error('Unsupported key scheme');\n\t}\n}\n\n/**\n * Compresses an uncompressed public key into its compressed form.\n *\n * The uncompressed key must follow the DER bit string format as specified in [RFC 5480](https://datatracker.ietf.org/doc/html/rfc5480#section-2.2)\n * and [SEC 1: Elliptic Curve Cryptography](https://www.secg.org/sec1-v2.pdf).\n *\n * @param uncompressedKey - A `Uint8ClampedArray` representing the uncompressed public key bits.\n * @returns A `Uint8Array` containing the compressed public key.\n *\n * @throws {Error} If the uncompressed key has an unexpected length or does not start with the expected prefix.\n */\nexport function compressPublicKeyClamped(uncompressedKey: Uint8ClampedArray): Uint8Array {\n\tif (uncompressedKey.length !== DER_BIT_STRING_LENGTH) {\n\t\tthrow new Error('Unexpected length for an uncompressed public key');\n\t}\n\n\t// Convert bits to bytes\n\tconst uncompressedBytes = bitsToBytes(uncompressedKey);\n\n\t// Ensure the public key starts with the standard uncompressed prefix 0x04\n\tif (uncompressedBytes[0] !== 0x04) {\n\t\tthrow new Error('Public key does not start with 0x04');\n\t}\n\n\t// Extract X-Coordinate (skip the first byte, which is the prefix 0x04)\n\tconst xCoord = uncompressedBytes.slice(1, 33);\n\n\t// Determine parity byte for Y coordinate based on the last byte\n\tconst yCoordLastByte = uncompressedBytes[64];\n\tconst parityByte = yCoordLastByte % 2 === 0 ? 0x02 : 0x03;\n\n\t// Return the compressed public key consisting of the parity byte and X-coordinate\n\treturn new Uint8Array([parityByte, ...xCoord]);\n}\n"],
|
|
5
|
-
"mappings": "AAGA,SAAS,iBAAiB;AAC1B,SAAS,iBAAiB;AAC1B,SAAS,kBAAkB,cAAc,kBAAkB;AAGpD,MAAM,wBAAwB;AAG9B,MAAM,mBAAmB,wBAAwB;AAcxD,SAAS,YAAY,WAA0C;AAC9D,QAAM,QAAQ,IAAI,WAAW,gBAAgB;AAC7C,WAAS,IAAI,GAAG,IAAI,uBAAuB,KAAK;AAC/C,QAAI,UAAU,CAAC,MAAM,GAAG;AACvB,YAAM,KAAK,MAAM,IAAI,CAAC,CAAC,KAAK,KAAM,IAAK,IAAI;AAAA,IAC5C;AAAA,EACD;AACA,SAAO;AACR;AAEO,SAAS,iBAAiB,UAAsB;AACtD,QAAM,cAA0B;AAChC,QAAM,aAAa,IAAI,WAAW;AAClC,aAAW,UAAU,WAAW;AAGhC,MACC,EACC,WAAW,aAAa,aAAa,aACrC,WAAW,iBAAiB,iBAAiB,cAE7C;AACD,UAAM,IAAI,MAAM,4BAA4B;AAAA,EAC7C;AAEA,QAAM,aAAa,WAAW;AAC9B,QAAM,mBAAmB,WAAW,CAAC;AAErC,MAAI,CAAC,kBAAkB;AACtB,UAAM,IAAI,MAAM,2CAA2C;AAAA,EAC5D;AAEA,SAAO,yBAAyB,iBAAiB,SAAS;AAC3D;AAEO,SAAS,yBAAyB,WAAuB,WAAmB;AAClF,MAAI,CAAC,aAAa,UAAU,WAAW,GAAG;AACzC,UAAM,IAAI,MAAM,mBAAmB;AAAA,EACpC;AAGA,QAAM,aAAa,IAAI,WAAW;AAClC,aAAW,UAAU,SAAS;AAE9B,QAAM,CAAC,GAAG,CAAC,IAAI,WAAW,OAAO;AAEjC,UAAQ,WAAW;AAAA,IAClB,KAAK;AACJ,aAAO,IAAI,UAAU,UAAU,OAAO,CAAC,GAAG,OAAO,CAAC,CAAC,EACjD,WAAW,EACX,kBAAkB;AAAA,IACrB,KAAK;AACJ,aAAO,IAAI,UAAU,UAAU,OAAO,CAAC,GAAG,OAAO,CAAC,CAAC,EACjD,WAAW,EACX,kBAAkB;AAAA,IACrB;AACC,YAAM,IAAI,MAAM,wBAAwB;AAAA,EAC1C;AACD;AAaO,SAAS,yBAAyB,iBAAgD;AACxF,MAAI,gBAAgB,WAAW,uBAAuB;AACrD,UAAM,IAAI,MAAM,kDAAkD;AAAA,EACnE;AAGA,QAAM,oBAAoB,YAAY,eAAe;AAGrD,MAAI,kBAAkB,CAAC,MAAM,GAAM;AAClC,UAAM,IAAI,MAAM,qCAAqC;AAAA,EACtD;AAGA,QAAM,SAAS,kBAAkB,MAAM,GAAG,EAAE;AAG5C,QAAM,iBAAiB,kBAAkB,EAAE;AAC3C,QAAM,aAAa,iBAAiB,MAAM,IAAI,IAAO;AAGrD,SAAO,IAAI,WAAW,CAAC,YAAY,GAAG,MAAM,CAAC;AAC9C;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { SignatureScheme } from '@haneullabs/haneul/cryptography';
|
|
2
|
-
import { Signer } from '@haneullabs/haneul/cryptography';
|
|
3
|
-
import { Secp256r1PublicKey } from '@haneullabs/haneul/keypairs/secp256r1';
|
|
4
|
-
export interface ExportedWebCryptoKeypair {
|
|
5
|
-
privateKey: CryptoKey;
|
|
6
|
-
publicKey: Uint8Array<ArrayBuffer>;
|
|
7
|
-
}
|
|
8
|
-
export declare class WebCryptoSigner extends Signer {
|
|
9
|
-
#private;
|
|
10
|
-
privateKey: CryptoKey;
|
|
11
|
-
static generate({ extractable }?: {
|
|
12
|
-
extractable?: boolean;
|
|
13
|
-
}): Promise<WebCryptoSigner>;
|
|
14
|
-
/**
|
|
15
|
-
* Imports a keypair using the value returned by `export()`.
|
|
16
|
-
*/
|
|
17
|
-
static import(data: ExportedWebCryptoKeypair): WebCryptoSigner;
|
|
18
|
-
getKeyScheme(): SignatureScheme;
|
|
19
|
-
constructor(privateKey: CryptoKey, publicKey: Uint8Array);
|
|
20
|
-
/**
|
|
21
|
-
* Exports the keypair so that it can be stored in IndexedDB.
|
|
22
|
-
*/
|
|
23
|
-
export(): ExportedWebCryptoKeypair;
|
|
24
|
-
getPublicKey(): Secp256r1PublicKey;
|
|
25
|
-
sign(bytes: Uint8Array): Promise<Uint8Array<ArrayBuffer>>;
|
|
26
|
-
}
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
var __typeError = (msg) => {
|
|
2
|
-
throw TypeError(msg);
|
|
3
|
-
};
|
|
4
|
-
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
5
|
-
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
6
|
-
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
7
|
-
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
8
|
-
var _publicKey;
|
|
9
|
-
import { Signer } from "@haneullabs/haneul/cryptography";
|
|
10
|
-
import { Secp256r1PublicKey } from "@haneullabs/haneul/keypairs/secp256r1";
|
|
11
|
-
import { secp256r1 } from "@noble/curves/p256";
|
|
12
|
-
function getCompressedPublicKey(publicKey) {
|
|
13
|
-
const rawBytes = new Uint8Array(publicKey);
|
|
14
|
-
const x = rawBytes.slice(1, 33);
|
|
15
|
-
const y = rawBytes.slice(33, 65);
|
|
16
|
-
const prefix = (y[31] & 1) === 0 ? 2 : 3;
|
|
17
|
-
const compressed = new Uint8Array(Secp256r1PublicKey.SIZE);
|
|
18
|
-
compressed[0] = prefix;
|
|
19
|
-
compressed.set(x, 1);
|
|
20
|
-
return compressed;
|
|
21
|
-
}
|
|
22
|
-
const _WebCryptoSigner = class _WebCryptoSigner extends Signer {
|
|
23
|
-
constructor(privateKey, publicKey) {
|
|
24
|
-
super();
|
|
25
|
-
__privateAdd(this, _publicKey);
|
|
26
|
-
this.privateKey = privateKey;
|
|
27
|
-
__privateSet(this, _publicKey, new Secp256r1PublicKey(publicKey));
|
|
28
|
-
}
|
|
29
|
-
static async generate({ extractable = false } = {}) {
|
|
30
|
-
const keypair = await globalThis.crypto.subtle.generateKey(
|
|
31
|
-
{
|
|
32
|
-
name: "ECDSA",
|
|
33
|
-
namedCurve: "P-256"
|
|
34
|
-
},
|
|
35
|
-
extractable,
|
|
36
|
-
["sign", "verify"]
|
|
37
|
-
);
|
|
38
|
-
const publicKey = await globalThis.crypto.subtle.exportKey("raw", keypair.publicKey);
|
|
39
|
-
return new _WebCryptoSigner(
|
|
40
|
-
keypair.privateKey,
|
|
41
|
-
getCompressedPublicKey(new Uint8Array(publicKey))
|
|
42
|
-
);
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Imports a keypair using the value returned by `export()`.
|
|
46
|
-
*/
|
|
47
|
-
static import(data) {
|
|
48
|
-
return new _WebCryptoSigner(data.privateKey, data.publicKey);
|
|
49
|
-
}
|
|
50
|
-
getKeyScheme() {
|
|
51
|
-
return "Secp256r1";
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Exports the keypair so that it can be stored in IndexedDB.
|
|
55
|
-
*/
|
|
56
|
-
export() {
|
|
57
|
-
const exportedKeypair = {
|
|
58
|
-
privateKey: this.privateKey,
|
|
59
|
-
publicKey: __privateGet(this, _publicKey).toRawBytes()
|
|
60
|
-
};
|
|
61
|
-
Object.defineProperty(exportedKeypair, "toJSON", {
|
|
62
|
-
enumerable: false,
|
|
63
|
-
value: () => {
|
|
64
|
-
throw new Error(
|
|
65
|
-
"The exported keypair must not be serialized. It must be stored in IndexedDB directly."
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
return exportedKeypair;
|
|
70
|
-
}
|
|
71
|
-
getPublicKey() {
|
|
72
|
-
return __privateGet(this, _publicKey);
|
|
73
|
-
}
|
|
74
|
-
async sign(bytes) {
|
|
75
|
-
const rawSignature = await globalThis.crypto.subtle.sign(
|
|
76
|
-
{
|
|
77
|
-
name: "ECDSA",
|
|
78
|
-
hash: "SHA-256"
|
|
79
|
-
},
|
|
80
|
-
this.privateKey,
|
|
81
|
-
bytes
|
|
82
|
-
);
|
|
83
|
-
const signature = secp256r1.Signature.fromCompact(new Uint8Array(rawSignature));
|
|
84
|
-
return signature.normalizeS().toCompactRawBytes();
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
_publicKey = new WeakMap();
|
|
88
|
-
let WebCryptoSigner = _WebCryptoSigner;
|
|
89
|
-
export {
|
|
90
|
-
WebCryptoSigner
|
|
91
|
-
};
|
|
92
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/webcrypto/index.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { SignatureScheme } from '@haneullabs/haneul/cryptography';\nimport { Signer } from '@haneullabs/haneul/cryptography';\nimport { Secp256r1PublicKey } from '@haneullabs/haneul/keypairs/secp256r1';\nimport { secp256r1 } from '@noble/curves/p256';\n\n// Convert from uncompressed (65 bytes) to compressed (33 bytes) format\nfunction getCompressedPublicKey(publicKey: Uint8Array) {\n\tconst rawBytes = new Uint8Array(publicKey);\n\tconst x = rawBytes.slice(1, 33);\n\tconst y = rawBytes.slice(33, 65);\n\n\tconst prefix = (y[31] & 1) === 0 ? 0x02 : 0x03;\n\n\tconst compressed = new Uint8Array(Secp256r1PublicKey.SIZE);\n\tcompressed[0] = prefix;\n\tcompressed.set(x, 1);\n\n\treturn compressed;\n}\n\nexport interface ExportedWebCryptoKeypair {\n\tprivateKey: CryptoKey;\n\tpublicKey: Uint8Array<ArrayBuffer>;\n}\n\nexport class WebCryptoSigner extends Signer {\n\tprivateKey: CryptoKey;\n\n\t#publicKey: Secp256r1PublicKey;\n\n\tstatic async generate({ extractable = false }: { extractable?: boolean } = {}) {\n\t\tconst keypair = await globalThis.crypto.subtle.generateKey(\n\t\t\t{\n\t\t\t\tname: 'ECDSA',\n\t\t\t\tnamedCurve: 'P-256',\n\t\t\t},\n\t\t\textractable,\n\t\t\t['sign', 'verify'],\n\t\t);\n\n\t\tconst publicKey = await globalThis.crypto.subtle.exportKey('raw', keypair.publicKey);\n\n\t\treturn new WebCryptoSigner(\n\t\t\tkeypair.privateKey,\n\t\t\tgetCompressedPublicKey(new Uint8Array(publicKey)),\n\t\t);\n\t}\n\n\t/**\n\t * Imports a keypair using the value returned by `export()`.\n\t */\n\tstatic import(data: ExportedWebCryptoKeypair) {\n\t\treturn new WebCryptoSigner(data.privateKey, data.publicKey);\n\t}\n\n\tgetKeyScheme(): SignatureScheme {\n\t\treturn 'Secp256r1';\n\t}\n\n\tconstructor(privateKey: CryptoKey, publicKey: Uint8Array) {\n\t\tsuper();\n\t\tthis.privateKey = privateKey;\n\t\tthis.#publicKey = new Secp256r1PublicKey(publicKey);\n\t}\n\n\t/**\n\t * Exports the keypair so that it can be stored in IndexedDB.\n\t */\n\texport(): ExportedWebCryptoKeypair {\n\t\tconst exportedKeypair = {\n\t\t\tprivateKey: this.privateKey,\n\t\t\tpublicKey: this.#publicKey.toRawBytes(),\n\t\t};\n\n\t\tObject.defineProperty(exportedKeypair, 'toJSON', {\n\t\t\tenumerable: false,\n\t\t\tvalue: () => {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t'The exported keypair must not be serialized. It must be stored in IndexedDB directly.',\n\t\t\t\t);\n\t\t\t},\n\t\t});\n\n\t\treturn exportedKeypair;\n\t}\n\n\tgetPublicKey() {\n\t\treturn this.#publicKey;\n\t}\n\n\tasync sign(bytes: Uint8Array): Promise<Uint8Array<ArrayBuffer>> {\n\t\tconst rawSignature = await globalThis.crypto.subtle.sign(\n\t\t\t{\n\t\t\t\tname: 'ECDSA',\n\t\t\t\thash: 'SHA-256',\n\t\t\t},\n\t\t\tthis.privateKey,\n\t\t\tbytes as BufferSource,\n\t\t);\n\n\t\tconst signature = secp256r1.Signature.fromCompact(new Uint8Array(rawSignature));\n\n\t\treturn signature.normalizeS().toCompactRawBytes() as Uint8Array<ArrayBuffer>;\n\t}\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;AAAA;AAIA,SAAS,cAAc;AACvB,SAAS,0BAA0B;AACnC,SAAS,iBAAiB;AAG1B,SAAS,uBAAuB,WAAuB;AACtD,QAAM,WAAW,IAAI,WAAW,SAAS;AACzC,QAAM,IAAI,SAAS,MAAM,GAAG,EAAE;AAC9B,QAAM,IAAI,SAAS,MAAM,IAAI,EAAE;AAE/B,QAAM,UAAU,EAAE,EAAE,IAAI,OAAO,IAAI,IAAO;AAE1C,QAAM,aAAa,IAAI,WAAW,mBAAmB,IAAI;AACzD,aAAW,CAAC,IAAI;AAChB,aAAW,IAAI,GAAG,CAAC;AAEnB,SAAO;AACR;AAOO,MAAM,mBAAN,MAAM,yBAAwB,OAAO;AAAA,EAkC3C,YAAY,YAAuB,WAAuB;AACzD,UAAM;AAhCP;AAiCC,SAAK,aAAa;AAClB,uBAAK,YAAa,IAAI,mBAAmB,SAAS;AAAA,EACnD;AAAA,EAjCA,aAAa,SAAS,EAAE,cAAc,MAAM,IAA+B,CAAC,GAAG;AAC9E,UAAM,UAAU,MAAM,WAAW,OAAO,OAAO;AAAA,MAC9C;AAAA,QACC,MAAM;AAAA,QACN,YAAY;AAAA,MACb;AAAA,MACA;AAAA,MACA,CAAC,QAAQ,QAAQ;AAAA,IAClB;AAEA,UAAM,YAAY,MAAM,WAAW,OAAO,OAAO,UAAU,OAAO,QAAQ,SAAS;AAEnF,WAAO,IAAI;AAAA,MACV,QAAQ;AAAA,MACR,uBAAuB,IAAI,WAAW,SAAS,CAAC;AAAA,IACjD;AAAA,EACD;AAAA;AAAA;AAAA;AAAA,EAKA,OAAO,OAAO,MAAgC;AAC7C,WAAO,IAAI,iBAAgB,KAAK,YAAY,KAAK,SAAS;AAAA,EAC3D;AAAA,EAEA,eAAgC;AAC/B,WAAO;AAAA,EACR;AAAA;AAAA;AAAA;AAAA,EAWA,SAAmC;AAClC,UAAM,kBAAkB;AAAA,MACvB,YAAY,KAAK;AAAA,MACjB,WAAW,mBAAK,YAAW,WAAW;AAAA,IACvC;AAEA,WAAO,eAAe,iBAAiB,UAAU;AAAA,MAChD,YAAY;AAAA,MACZ,OAAO,MAAM;AACZ,cAAM,IAAI;AAAA,UACT;AAAA,QACD;AAAA,MACD;AAAA,IACD,CAAC;AAED,WAAO;AAAA,EACR;AAAA,EAEA,eAAe;AACd,WAAO,mBAAK;AAAA,EACb;AAAA,EAEA,MAAM,KAAK,OAAqD;AAC/D,UAAM,eAAe,MAAM,WAAW,OAAO,OAAO;AAAA,MACnD;AAAA,QACC,MAAM;AAAA,QACN,MAAM;AAAA,MACP;AAAA,MACA,KAAK;AAAA,MACL;AAAA,IACD;AAEA,UAAM,YAAY,UAAU,UAAU,YAAY,IAAI,WAAW,YAAY,CAAC;AAE9E,WAAO,UAAU,WAAW,EAAE,kBAAkB;AAAA,EACjD;AACD;AA5EC;AAHM,IAAM,kBAAN;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|