@mysten/sui 1.19.0 → 1.21.0
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 +16 -0
- package/dist/cjs/bcs/index.d.ts +1 -0
- package/dist/cjs/bcs/index.js +3 -1
- package/dist/cjs/bcs/index.js.map +2 -2
- package/dist/cjs/bcs/pure.d.ts +22 -0
- package/dist/cjs/bcs/pure.js +59 -0
- package/dist/cjs/bcs/pure.js.map +7 -0
- package/dist/cjs/keypairs/passkey/index.d.ts +1 -1
- package/dist/cjs/keypairs/passkey/index.js +2 -1
- package/dist/cjs/keypairs/passkey/index.js.map +2 -2
- package/dist/cjs/keypairs/passkey/keypair.d.ts +58 -4
- package/dist/cjs/keypairs/passkey/keypair.js +87 -4
- package/dist/cjs/keypairs/passkey/keypair.js.map +2 -2
- package/dist/cjs/keypairs/passkey/types.d.ts +12 -0
- package/dist/cjs/keypairs/passkey/types.js +17 -0
- package/dist/cjs/keypairs/passkey/types.js.map +7 -0
- package/dist/cjs/transactions/pure.d.ts +1 -9
- package/dist/cjs/transactions/pure.js +6 -36
- package/dist/cjs/transactions/pure.js.map +2 -2
- package/dist/cjs/version.d.ts +2 -2
- package/dist/cjs/version.js +2 -2
- package/dist/cjs/version.js.map +1 -1
- package/dist/esm/bcs/index.d.ts +1 -0
- package/dist/esm/bcs/index.js +5 -1
- package/dist/esm/bcs/index.js.map +2 -2
- package/dist/esm/bcs/pure.d.ts +22 -0
- package/dist/esm/bcs/pure.js +39 -0
- package/dist/esm/bcs/pure.js.map +7 -0
- package/dist/esm/keypairs/passkey/index.d.ts +1 -1
- package/dist/esm/keypairs/passkey/index.js +3 -2
- package/dist/esm/keypairs/passkey/index.js.map +2 -2
- package/dist/esm/keypairs/passkey/keypair.d.ts +58 -4
- package/dist/esm/keypairs/passkey/keypair.js +87 -4
- package/dist/esm/keypairs/passkey/keypair.js.map +2 -2
- package/dist/esm/keypairs/passkey/types.d.ts +12 -0
- package/dist/esm/keypairs/passkey/types.js +1 -0
- package/dist/esm/keypairs/passkey/types.js.map +7 -0
- package/dist/esm/transactions/pure.d.ts +1 -9
- package/dist/esm/transactions/pure.js +6 -36
- package/dist/esm/transactions/pure.js.map +2 -2
- package/dist/esm/version.d.ts +2 -2
- package/dist/esm/version.js +2 -2
- package/dist/esm/version.js.map +1 -1
- package/dist/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -2
- package/src/bcs/index.ts +5 -0
- package/src/bcs/pure.ts +91 -0
- package/src/keypairs/passkey/index.ts +1 -1
- package/src/keypairs/passkey/keypair.ts +105 -8
- package/src/keypairs/passkey/types.ts +16 -0
- package/src/transactions/pure.ts +8 -76
- package/src/version.ts +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @mysten/sui.js
|
|
2
2
|
|
|
3
|
+
## 1.21.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 3d8a0d9: expose `pureBcsSchemaFromTypeName` utility
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- 20a5aaa: remove dependency on deprecate webauthn types
|
|
12
|
+
|
|
13
|
+
## 1.20.0
|
|
14
|
+
|
|
15
|
+
### Minor Changes
|
|
16
|
+
|
|
17
|
+
- 827a200: add recover passkey option to sdk
|
|
18
|
+
|
|
3
19
|
## 1.19.0
|
|
4
20
|
|
|
5
21
|
### Minor Changes
|
package/dist/cjs/bcs/index.d.ts
CHANGED
|
@@ -3143,4 +3143,5 @@ declare const suiBcs: {
|
|
|
3143
3143
|
map<K, V, InputK = K, InputV = V>(keyType: import("@mysten/bcs").BcsType<K, InputK>, valueType: import("@mysten/bcs").BcsType<V, InputV>): import("@mysten/bcs").BcsType<Map<K, V>, Map<InputK, InputV>>;
|
|
3144
3144
|
lazy<T extends import("@mysten/bcs").BcsType<any>>(cb: () => T): T;
|
|
3145
3145
|
};
|
|
3146
|
+
export { pureBcsSchemaFromTypeName, type ShapeFromPureTypeName, type PureTypeName, } from './pure.js';
|
|
3146
3147
|
export { suiBcs as bcs };
|
package/dist/cjs/bcs/index.js
CHANGED
|
@@ -20,7 +20,8 @@ var bcs_exports = {};
|
|
|
20
20
|
__export(bcs_exports, {
|
|
21
21
|
BcsType: () => import_bcs3.BcsType,
|
|
22
22
|
TypeTagSerializer: () => import_type_tag_serializer.TypeTagSerializer,
|
|
23
|
-
bcs: () => suiBcs
|
|
23
|
+
bcs: () => suiBcs,
|
|
24
|
+
pureBcsSchemaFromTypeName: () => import_pure.pureBcsSchemaFromTypeName
|
|
24
25
|
});
|
|
25
26
|
module.exports = __toCommonJS(bcs_exports);
|
|
26
27
|
var import_bcs = require("@mysten/bcs");
|
|
@@ -28,6 +29,7 @@ var import_bcs2 = require("./bcs.js");
|
|
|
28
29
|
var import_effects = require("./effects.js");
|
|
29
30
|
var import_type_tag_serializer = require("./type-tag-serializer.js");
|
|
30
31
|
var import_bcs3 = require("@mysten/bcs");
|
|
32
|
+
var import_pure = require("./pure.js");
|
|
31
33
|
const suiBcs = {
|
|
32
34
|
...import_bcs.bcs,
|
|
33
35
|
U8: import_bcs.bcs.u8(),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/bcs/index.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { bcs } from '@mysten/bcs';\n\nimport {\n\tAddress,\n\tAppId,\n\tArgument,\n\tCallArg,\n\tCommand,\n\tCompressedSignature,\n\tGasData,\n\tIntent,\n\tIntentMessage,\n\tIntentScope,\n\tIntentVersion,\n\tMultiSig,\n\tMultiSigPkMap,\n\tMultiSigPublicKey,\n\tObjectArg,\n\tObjectDigest,\n\tPasskeyAuthenticator,\n\tProgrammableMoveCall,\n\tProgrammableTransaction,\n\tPublicKey,\n\tSenderSignedData,\n\tSenderSignedTransaction,\n\tSharedObjectRef,\n\tStructTag,\n\tSuiObjectRef,\n\tTransactionData,\n\tTransactionDataV1,\n\tTransactionExpiration,\n\tTransactionKind,\n\tTypeTag,\n} from './bcs.js';\nimport { TransactionEffects } from './effects.js';\n\nexport type { TypeTag } from './types.js';\n\nexport { TypeTagSerializer } from './type-tag-serializer.js';\nexport { BcsType, type BcsTypeOptions } from '@mysten/bcs';\n\nconst suiBcs = {\n\t...bcs,\n\tU8: bcs.u8(),\n\tU16: bcs.u16(),\n\tU32: bcs.u32(),\n\tU64: bcs.u64(),\n\tU128: bcs.u128(),\n\tU256: bcs.u256(),\n\tULEB128: bcs.uleb128(),\n\tBool: bcs.bool(),\n\tString: bcs.string(),\n\tAddress,\n\tAppId,\n\tArgument,\n\tCallArg,\n\tCompressedSignature,\n\tGasData,\n\tIntent,\n\tIntentMessage,\n\tIntentScope,\n\tIntentVersion,\n\tMultiSig,\n\tMultiSigPkMap,\n\tMultiSigPublicKey,\n\tObjectArg,\n\tObjectDigest,\n\tProgrammableMoveCall,\n\tProgrammableTransaction,\n\tPublicKey,\n\tSenderSignedData,\n\tSenderSignedTransaction,\n\tSharedObjectRef,\n\tStructTag,\n\tSuiObjectRef,\n\tCommand,\n\tTransactionData,\n\tTransactionDataV1,\n\tTransactionExpiration,\n\tTransactionKind,\n\tTypeTag,\n\tTransactionEffects,\n\tPasskeyAuthenticator,\n};\n\nexport { suiBcs as bcs };\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,iBAAoB;AAEpB,IAAAA,cA+BO;AACP,qBAAmC;AAInC,iCAAkC;AAClC,IAAAA,cAA6C;
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { bcs } from '@mysten/bcs';\n\nimport {\n\tAddress,\n\tAppId,\n\tArgument,\n\tCallArg,\n\tCommand,\n\tCompressedSignature,\n\tGasData,\n\tIntent,\n\tIntentMessage,\n\tIntentScope,\n\tIntentVersion,\n\tMultiSig,\n\tMultiSigPkMap,\n\tMultiSigPublicKey,\n\tObjectArg,\n\tObjectDigest,\n\tPasskeyAuthenticator,\n\tProgrammableMoveCall,\n\tProgrammableTransaction,\n\tPublicKey,\n\tSenderSignedData,\n\tSenderSignedTransaction,\n\tSharedObjectRef,\n\tStructTag,\n\tSuiObjectRef,\n\tTransactionData,\n\tTransactionDataV1,\n\tTransactionExpiration,\n\tTransactionKind,\n\tTypeTag,\n} from './bcs.js';\nimport { TransactionEffects } from './effects.js';\n\nexport type { TypeTag } from './types.js';\n\nexport { TypeTagSerializer } from './type-tag-serializer.js';\nexport { BcsType, type BcsTypeOptions } from '@mysten/bcs';\n\nconst suiBcs = {\n\t...bcs,\n\tU8: bcs.u8(),\n\tU16: bcs.u16(),\n\tU32: bcs.u32(),\n\tU64: bcs.u64(),\n\tU128: bcs.u128(),\n\tU256: bcs.u256(),\n\tULEB128: bcs.uleb128(),\n\tBool: bcs.bool(),\n\tString: bcs.string(),\n\tAddress,\n\tAppId,\n\tArgument,\n\tCallArg,\n\tCompressedSignature,\n\tGasData,\n\tIntent,\n\tIntentMessage,\n\tIntentScope,\n\tIntentVersion,\n\tMultiSig,\n\tMultiSigPkMap,\n\tMultiSigPublicKey,\n\tObjectArg,\n\tObjectDigest,\n\tProgrammableMoveCall,\n\tProgrammableTransaction,\n\tPublicKey,\n\tSenderSignedData,\n\tSenderSignedTransaction,\n\tSharedObjectRef,\n\tStructTag,\n\tSuiObjectRef,\n\tCommand,\n\tTransactionData,\n\tTransactionDataV1,\n\tTransactionExpiration,\n\tTransactionKind,\n\tTypeTag,\n\tTransactionEffects,\n\tPasskeyAuthenticator,\n};\nexport {\n\tpureBcsSchemaFromTypeName,\n\ttype ShapeFromPureTypeName,\n\ttype PureTypeName,\n} from './pure.js';\n\nexport { suiBcs as bcs };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,iBAAoB;AAEpB,IAAAA,cA+BO;AACP,qBAAmC;AAInC,iCAAkC;AAClC,IAAAA,cAA6C;AA6C7C,kBAIO;AA/CP,MAAM,SAAS;AAAA,EACd,GAAG;AAAA,EACH,IAAI,eAAI,GAAG;AAAA,EACX,KAAK,eAAI,IAAI;AAAA,EACb,KAAK,eAAI,IAAI;AAAA,EACb,KAAK,eAAI,IAAI;AAAA,EACb,MAAM,eAAI,KAAK;AAAA,EACf,MAAM,eAAI,KAAK;AAAA,EACf,SAAS,eAAI,QAAQ;AAAA,EACrB,MAAM,eAAI,KAAK;AAAA,EACf,QAAQ,eAAI,OAAO;AAAA,EACnB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD;",
|
|
6
6
|
"names": ["import_bcs"]
|
|
7
7
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { BcsType } from '@mysten/bcs';
|
|
2
|
+
export type BasePureType = 'u8' | 'u16' | 'u32' | 'u64' | 'u128' | 'u256' | 'bool' | 'id' | 'string' | 'address';
|
|
3
|
+
interface PureShapeByType {
|
|
4
|
+
u8: number;
|
|
5
|
+
u16: number;
|
|
6
|
+
u32: number;
|
|
7
|
+
u64: bigint | string | number;
|
|
8
|
+
u128: bigint | string | number;
|
|
9
|
+
u256: bigint | string | number;
|
|
10
|
+
bool: boolean;
|
|
11
|
+
string: string;
|
|
12
|
+
id: string | Uint8Array;
|
|
13
|
+
address: string | Uint8Array;
|
|
14
|
+
}
|
|
15
|
+
export type PureTypeName = BasePureType | `vector<${string}>` | `option<${string}>`;
|
|
16
|
+
export type ValidPureTypeName<T extends string> = T extends BasePureType ? PureTypeName : T extends `vector<${infer U}>` ? ValidPureTypeName<U> : T extends `option<${infer U}>` ? ValidPureTypeName<U> : PureTypeValidationError<T>;
|
|
17
|
+
export type ShapeFromPureTypeName<T extends PureTypeName> = T extends BasePureType ? PureShapeByType[T] : T extends `vector<${infer U extends PureTypeName}>` ? ShapeFromPureTypeName<U>[] : T extends `option<${infer U extends PureTypeName}>` ? ShapeFromPureTypeName<U> | null : never;
|
|
18
|
+
type PureTypeValidationError<T extends string> = T & {
|
|
19
|
+
error: `Invalid Pure type name: ${T}`;
|
|
20
|
+
};
|
|
21
|
+
export declare function pureBcsSchemaFromTypeName<T extends PureTypeName>(name: T extends PureTypeName ? ValidPureTypeName<T> : T): BcsType<ShapeFromPureTypeName<T>>;
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,59 @@
|
|
|
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 pure_exports = {};
|
|
20
|
+
__export(pure_exports, {
|
|
21
|
+
pureBcsSchemaFromTypeName: () => pureBcsSchemaFromTypeName
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(pure_exports);
|
|
24
|
+
var import_bcs = require("@mysten/bcs");
|
|
25
|
+
var import_bcs2 = require("./bcs.js");
|
|
26
|
+
function pureBcsSchemaFromTypeName(name) {
|
|
27
|
+
switch (name) {
|
|
28
|
+
case "u8":
|
|
29
|
+
return import_bcs.bcs.u8();
|
|
30
|
+
case "u16":
|
|
31
|
+
return import_bcs.bcs.u16();
|
|
32
|
+
case "u32":
|
|
33
|
+
return import_bcs.bcs.u32();
|
|
34
|
+
case "u64":
|
|
35
|
+
return import_bcs.bcs.u64();
|
|
36
|
+
case "u128":
|
|
37
|
+
return import_bcs.bcs.u128();
|
|
38
|
+
case "u256":
|
|
39
|
+
return import_bcs.bcs.u256();
|
|
40
|
+
case "bool":
|
|
41
|
+
return import_bcs.bcs.bool();
|
|
42
|
+
case "string":
|
|
43
|
+
return import_bcs.bcs.string();
|
|
44
|
+
case "id":
|
|
45
|
+
case "address":
|
|
46
|
+
return import_bcs2.Address;
|
|
47
|
+
}
|
|
48
|
+
const generic = name.match(/^(vector|option)<(.+)>$/);
|
|
49
|
+
if (generic) {
|
|
50
|
+
const [kind, inner] = generic.slice(1);
|
|
51
|
+
if (kind === "vector") {
|
|
52
|
+
return import_bcs.bcs.vector(pureBcsSchemaFromTypeName(inner));
|
|
53
|
+
} else {
|
|
54
|
+
return import_bcs.bcs.option(pureBcsSchemaFromTypeName(inner));
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
throw new Error(`Invalid Pure type name: ${name}`);
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=pure.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/bcs/pure.ts"],
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { bcs } from '@mysten/bcs';\nimport type { BcsType } from '@mysten/bcs';\n\nimport { Address } from './bcs.js';\n\nexport type BasePureType =\n\t| 'u8'\n\t| 'u16'\n\t| 'u32'\n\t| 'u64'\n\t| 'u128'\n\t| 'u256'\n\t| 'bool'\n\t| 'id'\n\t| 'string'\n\t| 'address';\n\ninterface PureShapeByType {\n\tu8: number;\n\tu16: number;\n\tu32: number;\n\tu64: bigint | string | number;\n\tu128: bigint | string | number;\n\tu256: bigint | string | number;\n\tbool: boolean;\n\tstring: string;\n\tid: string | Uint8Array;\n\taddress: string | Uint8Array;\n}\n\nexport type PureTypeName = BasePureType | `vector<${string}>` | `option<${string}>`;\nexport type ValidPureTypeName<T extends string> = T extends BasePureType\n\t? PureTypeName\n\t: T extends `vector<${infer U}>`\n\t\t? ValidPureTypeName<U>\n\t\t: T extends `option<${infer U}>`\n\t\t\t? ValidPureTypeName<U>\n\t\t\t: PureTypeValidationError<T>;\n\nexport type ShapeFromPureTypeName<T extends PureTypeName> = T extends BasePureType\n\t? PureShapeByType[T]\n\t: T extends `vector<${infer U extends PureTypeName}>`\n\t\t? ShapeFromPureTypeName<U>[]\n\t\t: T extends `option<${infer U extends PureTypeName}>`\n\t\t\t? ShapeFromPureTypeName<U> | null\n\t\t\t: never;\n\ntype PureTypeValidationError<T extends string> = T & {\n\terror: `Invalid Pure type name: ${T}`;\n};\n\nexport function pureBcsSchemaFromTypeName<T extends PureTypeName>(\n\tname: T extends PureTypeName ? ValidPureTypeName<T> : T,\n): BcsType<ShapeFromPureTypeName<T>> {\n\tswitch (name) {\n\t\tcase 'u8':\n\t\t\treturn bcs.u8() as never;\n\t\tcase 'u16':\n\t\t\treturn bcs.u16() as never;\n\t\tcase 'u32':\n\t\t\treturn bcs.u32() as never;\n\t\tcase 'u64':\n\t\t\treturn bcs.u64() as never;\n\t\tcase 'u128':\n\t\t\treturn bcs.u128() as never;\n\t\tcase 'u256':\n\t\t\treturn bcs.u256() as never;\n\t\tcase 'bool':\n\t\t\treturn bcs.bool() as never;\n\t\tcase 'string':\n\t\t\treturn bcs.string() as never;\n\t\tcase 'id':\n\t\tcase 'address':\n\t\t\treturn Address as never;\n\t}\n\n\tconst generic = name.match(/^(vector|option)<(.+)>$/);\n\tif (generic) {\n\t\tconst [kind, inner] = generic.slice(1);\n\t\tif (kind === 'vector') {\n\t\t\treturn bcs.vector(pureBcsSchemaFromTypeName(inner as PureTypeName)) as never;\n\t\t} else {\n\t\t\treturn bcs.option(pureBcsSchemaFromTypeName(inner as PureTypeName)) as never;\n\t\t}\n\t}\n\n\tthrow new Error(`Invalid Pure type name: ${name}`);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,iBAAoB;AAGpB,IAAAA,cAAwB;AAgDjB,SAAS,0BACf,MACoC;AACpC,UAAQ,MAAM;AAAA,IACb,KAAK;AACJ,aAAO,eAAI,GAAG;AAAA,IACf,KAAK;AACJ,aAAO,eAAI,IAAI;AAAA,IAChB,KAAK;AACJ,aAAO,eAAI,IAAI;AAAA,IAChB,KAAK;AACJ,aAAO,eAAI,IAAI;AAAA,IAChB,KAAK;AACJ,aAAO,eAAI,KAAK;AAAA,IACjB,KAAK;AACJ,aAAO,eAAI,KAAK;AAAA,IACjB,KAAK;AACJ,aAAO,eAAI,KAAK;AAAA,IACjB,KAAK;AACJ,aAAO,eAAI,OAAO;AAAA,IACnB,KAAK;AAAA,IACL,KAAK;AACJ,aAAO;AAAA,EACT;AAEA,QAAM,UAAU,KAAK,MAAM,yBAAyB;AACpD,MAAI,SAAS;AACZ,UAAM,CAAC,MAAM,KAAK,IAAI,QAAQ,MAAM,CAAC;AACrC,QAAI,SAAS,UAAU;AACtB,aAAO,eAAI,OAAO,0BAA0B,KAAqB,CAAC;AAAA,IACnE,OAAO;AACN,aAAO,eAAI,OAAO,0BAA0B,KAAqB,CAAC;AAAA,IACnE;AAAA,EACD;AAEA,QAAM,IAAI,MAAM,2BAA2B,IAAI,EAAE;AAClD;",
|
|
6
|
+
"names": ["import_bcs"]
|
|
7
|
+
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { PasskeyKeypair, BrowserPasskeyProvider } from './keypair.js';
|
|
1
|
+
export { PasskeyKeypair, BrowserPasskeyProvider, findCommonPublicKey } from './keypair.js';
|
|
2
2
|
export type { PasskeyProvider, BrowserPasswordProviderOptions } from './keypair.js';
|
|
3
3
|
export { PasskeyPublicKey } from './publickey.js';
|
|
@@ -20,7 +20,8 @@ var passkey_exports = {};
|
|
|
20
20
|
__export(passkey_exports, {
|
|
21
21
|
BrowserPasskeyProvider: () => import_keypair.BrowserPasskeyProvider,
|
|
22
22
|
PasskeyKeypair: () => import_keypair.PasskeyKeypair,
|
|
23
|
-
PasskeyPublicKey: () => import_publickey.PasskeyPublicKey
|
|
23
|
+
PasskeyPublicKey: () => import_publickey.PasskeyPublicKey,
|
|
24
|
+
findCommonPublicKey: () => import_keypair.findCommonPublicKey
|
|
24
25
|
});
|
|
25
26
|
module.exports = __toCommonJS(passkey_exports);
|
|
26
27
|
var import_keypair = require("./keypair.js");
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/keypairs/passkey/index.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\nexport { PasskeyKeypair, BrowserPasskeyProvider } from './keypair.js';\nexport type { PasskeyProvider, BrowserPasswordProviderOptions } from './keypair.js';\nexport { PasskeyPublicKey } from './publickey.js';\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\nexport { PasskeyKeypair, BrowserPasskeyProvider, findCommonPublicKey } from './keypair.js';\nexport type { PasskeyProvider, BrowserPasswordProviderOptions } from './keypair.js';\nexport { PasskeyPublicKey } from './publickey.js';\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,qBAA4E;AAE5E,uBAAiC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { AuthenticationCredential, RegistrationCredential } from '@simplewebauthn/typescript-types';
|
|
2
1
|
import type { IntentScope, SignatureWithBytes } from '../../cryptography/index.js';
|
|
3
2
|
import { Signer } from '../../cryptography/index.js';
|
|
4
3
|
import type { PublicKey } from '../../cryptography/publickey.js';
|
|
5
4
|
import type { SignatureScheme } from '../../cryptography/signature-scheme.js';
|
|
5
|
+
import type { AuthenticationCredential, RegistrationCredential } from './types.js';
|
|
6
6
|
type DeepPartialConfigKeys = 'rp' | 'user' | 'authenticatorSelection';
|
|
7
7
|
type DeepPartial<T> = T extends object ? {
|
|
8
8
|
[P in keyof T]?: DeepPartial<T[P]>;
|
|
@@ -30,15 +30,27 @@ export declare class PasskeyKeypair extends Signer {
|
|
|
30
30
|
*/
|
|
31
31
|
getKeyScheme(): SignatureScheme;
|
|
32
32
|
/**
|
|
33
|
-
* Creates an instance of Passkey signer.
|
|
34
|
-
* For example:
|
|
33
|
+
* Creates an instance of Passkey signer. If no passkey wallet had created before,
|
|
34
|
+
* use `getPasskeyInstance`. For example:
|
|
35
35
|
* ```
|
|
36
|
-
*
|
|
36
|
+
* let provider = new BrowserPasskeyProvider('Sui Passkey Example',{
|
|
37
|
+
* rpName: 'Sui Passkey Example',
|
|
38
|
+
* rpId: window.location.hostname,
|
|
39
|
+
* } as BrowserPasswordProviderOptions);
|
|
40
|
+
* const signer = await PasskeyKeypair.getPasskeyInstance(provider);
|
|
37
41
|
* ```
|
|
42
|
+
*
|
|
43
|
+
* If there are existing passkey wallet, use `signAndRecover` to identify the correct
|
|
44
|
+
* public key and then initialize the instance. See usage in `signAndRecover`.
|
|
38
45
|
*/
|
|
39
46
|
constructor(publicKey: Uint8Array, provider: PasskeyProvider);
|
|
40
47
|
/**
|
|
41
48
|
* Creates an instance of Passkey signer invoking the passkey from navigator.
|
|
49
|
+
* Note that this will invoke the passkey device to create a fresh credential.
|
|
50
|
+
* Should only be called if passkey wallet is created for the first time.
|
|
51
|
+
*
|
|
52
|
+
* @param provider - the passkey provider.
|
|
53
|
+
* @returns the passkey instance.
|
|
42
54
|
*/
|
|
43
55
|
static getPasskeyInstance(provider: PasskeyProvider): Promise<PasskeyKeypair>;
|
|
44
56
|
/**
|
|
@@ -55,5 +67,47 @@ export declare class PasskeyKeypair extends Signer {
|
|
|
55
67
|
* digest of the intent message, then serialize it with the passkey flag.
|
|
56
68
|
*/
|
|
57
69
|
signWithIntent(bytes: Uint8Array, intent: IntentScope): Promise<SignatureWithBytes>;
|
|
70
|
+
/**
|
|
71
|
+
* Given a message, asks the passkey device to sign it and return all (up to 4) possible public keys.
|
|
72
|
+
* See: https://bitcoin.stackexchange.com/questions/81232/how-is-public-key-extracted-from-message-digital-signature-address
|
|
73
|
+
*
|
|
74
|
+
* This is useful if the user previously created passkey wallet with the origin, but the wallet session
|
|
75
|
+
* does not have the public key / address. By calling this method twice with two different messages, the
|
|
76
|
+
* wallet can compare the returned public keys and uniquely identify the previously created passkey wallet
|
|
77
|
+
* using `findCommonPublicKey`.
|
|
78
|
+
*
|
|
79
|
+
* Alternatively, one call can be made and all possible public keys should be checked onchain to see if
|
|
80
|
+
* there is any assets.
|
|
81
|
+
*
|
|
82
|
+
* Once the correct public key is identified, a passkey instance can then be initialized with this public key.
|
|
83
|
+
*
|
|
84
|
+
* Example usage to recover wallet with two signing calls:
|
|
85
|
+
* ```
|
|
86
|
+
* let provider = new BrowserPasskeyProvider('Sui Passkey Example',{
|
|
87
|
+
* rpName: 'Sui Passkey Example',
|
|
88
|
+
* rpId: window.location.hostname,
|
|
89
|
+
* } as BrowserPasswordProviderOptions);
|
|
90
|
+
* const testMessage = new TextEncoder().encode('Hello world!');
|
|
91
|
+
* const possiblePks = await PasskeyKeypair.signAndRecover(provider, testMessage);
|
|
92
|
+
* const testMessage2 = new TextEncoder().encode('Hello world 2!');
|
|
93
|
+
* const possiblePks2 = await PasskeyKeypair.signAndRecover(provider, testMessage2);
|
|
94
|
+
* const commonPk = findCommonPublicKey(possiblePks, possiblePks2);
|
|
95
|
+
* const signer = new PasskeyKeypair(provider, commonPk.toRawBytes());
|
|
96
|
+
* ```
|
|
97
|
+
*
|
|
98
|
+
* @param provider - the passkey provider.
|
|
99
|
+
* @param message - the message to sign.
|
|
100
|
+
* @returns all possible public keys.
|
|
101
|
+
*/
|
|
102
|
+
static signAndRecover(provider: PasskeyProvider, message: Uint8Array): Promise<PublicKey[]>;
|
|
58
103
|
}
|
|
104
|
+
/**
|
|
105
|
+
* Finds the unique public key that exists in both arrays, throws error if the common
|
|
106
|
+
* pubkey does not equal to one.
|
|
107
|
+
*
|
|
108
|
+
* @param arr1 - The first pubkeys array.
|
|
109
|
+
* @param arr2 - The second pubkeys array.
|
|
110
|
+
* @returns The only common pubkey in both arrays.
|
|
111
|
+
*/
|
|
112
|
+
export declare function findCommonPublicKey(arr1: PublicKey[], arr2: PublicKey[]): PublicKey;
|
|
59
113
|
export {};
|
|
@@ -26,12 +26,14 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
|
|
|
26
26
|
var keypair_exports = {};
|
|
27
27
|
__export(keypair_exports, {
|
|
28
28
|
BrowserPasskeyProvider: () => BrowserPasskeyProvider,
|
|
29
|
-
PasskeyKeypair: () => PasskeyKeypair
|
|
29
|
+
PasskeyKeypair: () => PasskeyKeypair,
|
|
30
|
+
findCommonPublicKey: () => findCommonPublicKey
|
|
30
31
|
});
|
|
31
32
|
module.exports = __toCommonJS(keypair_exports);
|
|
32
33
|
var import_bcs = require("@mysten/bcs");
|
|
33
34
|
var import_p256 = require("@noble/curves/p256");
|
|
34
35
|
var import_blake2b = require("@noble/hashes/blake2b");
|
|
36
|
+
var import_sha256 = require("@noble/hashes/sha256");
|
|
35
37
|
var import_utils = require("@noble/hashes/utils");
|
|
36
38
|
var import_bcs2 = require("../../bcs/bcs.js");
|
|
37
39
|
var import_cryptography = require("../../cryptography/index.js");
|
|
@@ -91,11 +93,18 @@ class PasskeyKeypair extends import_cryptography.Signer {
|
|
|
91
93
|
return "Passkey";
|
|
92
94
|
}
|
|
93
95
|
/**
|
|
94
|
-
* Creates an instance of Passkey signer.
|
|
95
|
-
* For example:
|
|
96
|
+
* Creates an instance of Passkey signer. If no passkey wallet had created before,
|
|
97
|
+
* use `getPasskeyInstance`. For example:
|
|
96
98
|
* ```
|
|
97
|
-
*
|
|
99
|
+
* let provider = new BrowserPasskeyProvider('Sui Passkey Example',{
|
|
100
|
+
* rpName: 'Sui Passkey Example',
|
|
101
|
+
* rpId: window.location.hostname,
|
|
102
|
+
* } as BrowserPasswordProviderOptions);
|
|
103
|
+
* const signer = await PasskeyKeypair.getPasskeyInstance(provider);
|
|
98
104
|
* ```
|
|
105
|
+
*
|
|
106
|
+
* If there are existing passkey wallet, use `signAndRecover` to identify the correct
|
|
107
|
+
* public key and then initialize the instance. See usage in `signAndRecover`.
|
|
99
108
|
*/
|
|
100
109
|
constructor(publicKey, provider) {
|
|
101
110
|
super();
|
|
@@ -104,6 +113,11 @@ class PasskeyKeypair extends import_cryptography.Signer {
|
|
|
104
113
|
}
|
|
105
114
|
/**
|
|
106
115
|
* Creates an instance of Passkey signer invoking the passkey from navigator.
|
|
116
|
+
* Note that this will invoke the passkey device to create a fresh credential.
|
|
117
|
+
* Should only be called if passkey wallet is created for the first time.
|
|
118
|
+
*
|
|
119
|
+
* @param provider - the passkey provider.
|
|
120
|
+
* @returns the passkey instance.
|
|
107
121
|
*/
|
|
108
122
|
static async getPasskeyInstance(provider) {
|
|
109
123
|
const credential = await provider.create();
|
|
@@ -164,5 +178,74 @@ class PasskeyKeypair extends import_cryptography.Signer {
|
|
|
164
178
|
bytes: (0, import_bcs.toBase64)(bytes)
|
|
165
179
|
};
|
|
166
180
|
}
|
|
181
|
+
/**
|
|
182
|
+
* Given a message, asks the passkey device to sign it and return all (up to 4) possible public keys.
|
|
183
|
+
* See: https://bitcoin.stackexchange.com/questions/81232/how-is-public-key-extracted-from-message-digital-signature-address
|
|
184
|
+
*
|
|
185
|
+
* This is useful if the user previously created passkey wallet with the origin, but the wallet session
|
|
186
|
+
* does not have the public key / address. By calling this method twice with two different messages, the
|
|
187
|
+
* wallet can compare the returned public keys and uniquely identify the previously created passkey wallet
|
|
188
|
+
* using `findCommonPublicKey`.
|
|
189
|
+
*
|
|
190
|
+
* Alternatively, one call can be made and all possible public keys should be checked onchain to see if
|
|
191
|
+
* there is any assets.
|
|
192
|
+
*
|
|
193
|
+
* Once the correct public key is identified, a passkey instance can then be initialized with this public key.
|
|
194
|
+
*
|
|
195
|
+
* Example usage to recover wallet with two signing calls:
|
|
196
|
+
* ```
|
|
197
|
+
* let provider = new BrowserPasskeyProvider('Sui Passkey Example',{
|
|
198
|
+
* rpName: 'Sui Passkey Example',
|
|
199
|
+
* rpId: window.location.hostname,
|
|
200
|
+
* } as BrowserPasswordProviderOptions);
|
|
201
|
+
* const testMessage = new TextEncoder().encode('Hello world!');
|
|
202
|
+
* const possiblePks = await PasskeyKeypair.signAndRecover(provider, testMessage);
|
|
203
|
+
* const testMessage2 = new TextEncoder().encode('Hello world 2!');
|
|
204
|
+
* const possiblePks2 = await PasskeyKeypair.signAndRecover(provider, testMessage2);
|
|
205
|
+
* const commonPk = findCommonPublicKey(possiblePks, possiblePks2);
|
|
206
|
+
* const signer = new PasskeyKeypair(provider, commonPk.toRawBytes());
|
|
207
|
+
* ```
|
|
208
|
+
*
|
|
209
|
+
* @param provider - the passkey provider.
|
|
210
|
+
* @param message - the message to sign.
|
|
211
|
+
* @returns all possible public keys.
|
|
212
|
+
*/
|
|
213
|
+
static async signAndRecover(provider, message) {
|
|
214
|
+
const credential = await provider.get(message);
|
|
215
|
+
const fullMessage = messageFromAssertionResponse(credential.response);
|
|
216
|
+
const sig = import_p256.secp256r1.Signature.fromDER(new Uint8Array(credential.response.signature));
|
|
217
|
+
const res = [];
|
|
218
|
+
for (let i = 0; i < 4; i++) {
|
|
219
|
+
const s = sig.addRecoveryBit(i);
|
|
220
|
+
try {
|
|
221
|
+
const pubkey = s.recoverPublicKey((0, import_sha256.sha256)(fullMessage));
|
|
222
|
+
const pk = new import_publickey.PasskeyPublicKey(pubkey.toRawBytes(true));
|
|
223
|
+
res.push(pk);
|
|
224
|
+
} catch {
|
|
225
|
+
continue;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
return res;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
function findCommonPublicKey(arr1, arr2) {
|
|
232
|
+
const matchingPubkeys = [];
|
|
233
|
+
for (const pubkey1 of arr1) {
|
|
234
|
+
for (const pubkey2 of arr2) {
|
|
235
|
+
if (pubkey1.equals(pubkey2)) {
|
|
236
|
+
matchingPubkeys.push(pubkey1);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
if (matchingPubkeys.length !== 1) {
|
|
241
|
+
throw new Error("No unique public key found");
|
|
242
|
+
}
|
|
243
|
+
return matchingPubkeys[0];
|
|
244
|
+
}
|
|
245
|
+
function messageFromAssertionResponse(response) {
|
|
246
|
+
const authenticatorData = new Uint8Array(response.authenticatorData);
|
|
247
|
+
const clientDataJSON = new Uint8Array(response.clientDataJSON);
|
|
248
|
+
const clientDataJSONDigest = (0, import_sha256.sha256)(clientDataJSON);
|
|
249
|
+
return new Uint8Array([...authenticatorData, ...clientDataJSONDigest]);
|
|
167
250
|
}
|
|
168
251
|
//# sourceMappingURL=keypair.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/keypairs/passkey/keypair.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { toBase64 } from '@mysten/bcs';\nimport { secp256r1 } from '@noble/curves/p256';\nimport { blake2b } from '@noble/hashes/blake2b';\nimport { randomBytes } from '@noble/hashes/utils';\nimport type {\n\tAuthenticationCredential,\n\tRegistrationCredential,\n} from '@simplewebauthn/typescript-types';\n\nimport { PasskeyAuthenticator } from '../../bcs/bcs.js';\nimport type { IntentScope, SignatureWithBytes } from '../../cryptography/index.js';\nimport { messageWithIntent, SIGNATURE_SCHEME_TO_FLAG, Signer } from '../../cryptography/index.js';\nimport type { PublicKey } from '../../cryptography/publickey.js';\nimport type { SignatureScheme } from '../../cryptography/signature-scheme.js';\nimport {\n\tparseDerSPKI,\n\tPASSKEY_PUBLIC_KEY_SIZE,\n\tPASSKEY_SIGNATURE_SIZE,\n\tPasskeyPublicKey,\n} from './publickey.js';\n\ntype DeepPartialConfigKeys = 'rp' | 'user' | 'authenticatorSelection';\n\ntype DeepPartial<T> = T extends object\n\t? {\n\t\t\t[P in keyof T]?: DeepPartial<T[P]>;\n\t\t}\n\t: T;\n\nexport type BrowserPasswordProviderOptions = Pick<\n\tDeepPartial<PublicKeyCredentialCreationOptions>,\n\tDeepPartialConfigKeys\n> &\n\tOmit<\n\t\tPartial<PublicKeyCredentialCreationOptions>,\n\t\tDeepPartialConfigKeys | 'pubKeyCredParams' | 'challenge'\n\t>;\n\nexport interface PasskeyProvider {\n\tcreate(): Promise<RegistrationCredential>;\n\tget(challenge: Uint8Array): Promise<AuthenticationCredential>;\n}\n\n// Default browser implementation\nexport class BrowserPasskeyProvider implements PasskeyProvider {\n\t#name: string;\n\t#options: BrowserPasswordProviderOptions;\n\n\tconstructor(name: string, options: BrowserPasswordProviderOptions) {\n\t\tthis.#name = name;\n\t\tthis.#options = options;\n\t}\n\n\tasync create(): Promise<RegistrationCredential> {\n\t\treturn (await navigator.credentials.create({\n\t\t\tpublicKey: {\n\t\t\t\ttimeout: this.#options.timeout ?? 60000,\n\t\t\t\t...this.#options,\n\t\t\t\trp: {\n\t\t\t\t\tname: this.#name,\n\t\t\t\t\t...this.#options.rp,\n\t\t\t\t},\n\t\t\t\tuser: {\n\t\t\t\t\tname: this.#name,\n\t\t\t\t\tdisplayName: this.#name,\n\t\t\t\t\t...this.#options.user,\n\t\t\t\t\tid: randomBytes(10),\n\t\t\t\t},\n\t\t\t\tchallenge: new TextEncoder().encode('Create passkey wallet on Sui'),\n\t\t\t\tpubKeyCredParams: [{ alg: -7, type: 'public-key' }],\n\t\t\t\tauthenticatorSelection: {\n\t\t\t\t\tauthenticatorAttachment: 'cross-platform',\n\t\t\t\t\tresidentKey: 'required',\n\t\t\t\t\trequireResidentKey: true,\n\t\t\t\t\tuserVerification: 'required',\n\t\t\t\t\t...this.#options.authenticatorSelection,\n\t\t\t\t},\n\t\t\t},\n\t\t})) as RegistrationCredential;\n\t}\n\n\tasync get(challenge: Uint8Array): Promise<AuthenticationCredential> {\n\t\treturn (await navigator.credentials.get({\n\t\t\tpublicKey: {\n\t\t\t\tchallenge,\n\t\t\t\tuserVerification: this.#options.authenticatorSelection?.userVerification || 'required',\n\t\t\t\ttimeout: this.#options.timeout ?? 60000,\n\t\t\t},\n\t\t})) as AuthenticationCredential;\n\t}\n}\n\n/**\n * @experimental\n * A passkey signer used for signing transactions. This is a client side implementation for [SIP-9](https://github.com/sui-foundation/sips/blob/main/sips/sip-9.md).\n */\nexport class PasskeyKeypair extends Signer {\n\tprivate publicKey: Uint8Array;\n\tprivate provider: PasskeyProvider;\n\n\t/**\n\t * Get the key scheme of passkey,\n\t */\n\tgetKeyScheme(): SignatureScheme {\n\t\treturn 'Passkey';\n\t}\n\n\t/**\n\t * Creates an instance of Passkey signer. It's expected to call the static `getPasskeyInstance` method to create an instance.\n\t * For example:\n\t * ```\n\t * const signer = await PasskeyKeypair.getPasskeyInstance();\n\t * ```\n\t */\n\tconstructor(publicKey: Uint8Array, provider: PasskeyProvider) {\n\t\tsuper();\n\t\tthis.publicKey = publicKey;\n\t\tthis.provider = provider;\n\t}\n\n\t/**\n\t * Creates an instance of Passkey signer invoking the passkey from navigator.\n\t */\n\tstatic async getPasskeyInstance(provider: PasskeyProvider): Promise<PasskeyKeypair> {\n\t\t// create a passkey secp256r1 with the provider.\n\t\tconst credential = await provider.create();\n\n\t\tif (!credential.response.getPublicKey()) {\n\t\t\tthrow new Error('Invalid credential create response');\n\t\t} else {\n\t\t\tconst derSPKI = credential.response.getPublicKey()!;\n\t\t\tconst pubkeyUncompressed = parseDerSPKI(new Uint8Array(derSPKI));\n\t\t\tconst pubkey = secp256r1.ProjectivePoint.fromHex(pubkeyUncompressed);\n\t\t\tconst pubkeyCompressed = pubkey.toRawBytes(true);\n\t\t\treturn new PasskeyKeypair(pubkeyCompressed, provider);\n\t\t}\n\t}\n\n\t/**\n\t * Return the public key for this passkey.\n\t */\n\tgetPublicKey(): PublicKey {\n\t\treturn new PasskeyPublicKey(this.publicKey);\n\t}\n\n\t/**\n\t * Return the signature for the provided data (i.e. blake2b(intent_message)).\n\t * This is sent to passkey as the challenge field.\n\t */\n\tasync sign(data: Uint8Array) {\n\t\t// sendss the passkey to sign over challenge as the data.\n\t\tconst credential = await this.provider.get(data);\n\n\t\t// parse authenticatorData (as bytes), clientDataJSON (decoded as string).\n\t\tconst authenticatorData = new Uint8Array(credential.response.authenticatorData);\n\t\tconst clientDataJSON = new Uint8Array(credential.response.clientDataJSON); // response.clientDataJSON is already UTF-8 encoded JSON\n\t\tconst decoder = new TextDecoder();\n\t\tconst clientDataJSONString: string = decoder.decode(clientDataJSON);\n\n\t\t// parse the signature from DER format, normalize and convert to compressed format (33 bytes).\n\t\tconst sig = secp256r1.Signature.fromDER(new Uint8Array(credential.response.signature));\n\t\tconst normalized = sig.normalizeS().toCompactRawBytes();\n\n\t\tif (\n\t\t\tnormalized.length !== PASSKEY_SIGNATURE_SIZE ||\n\t\t\tthis.publicKey.length !== PASSKEY_PUBLIC_KEY_SIZE\n\t\t) {\n\t\t\tthrow new Error('Invalid signature or public key length');\n\t\t}\n\n\t\t// construct userSignature as flag || sig || pubkey for the secp256r1 signature.\n\t\tconst arr = new Uint8Array(1 + normalized.length + this.publicKey.length);\n\t\tarr.set([SIGNATURE_SCHEME_TO_FLAG['Secp256r1']]);\n\t\tarr.set(normalized, 1);\n\t\tarr.set(this.publicKey, 1 + normalized.length);\n\n\t\t// serialize all fields into a passkey signature according to https://github.com/sui-foundation/sips/blob/main/sips/sip-9.md#signature-encoding\n\t\treturn PasskeyAuthenticator.serialize({\n\t\t\tauthenticatorData: authenticatorData,\n\t\t\tclientDataJson: clientDataJSONString,\n\t\t\tuserSignature: arr,\n\t\t}).toBytes();\n\t}\n\n\t/**\n\t * This overrides the base class implementation that accepts the raw bytes and signs its\n\t * digest of the intent message, then serialize it with the passkey flag.\n\t */\n\tasync signWithIntent(bytes: Uint8Array, intent: IntentScope): Promise<SignatureWithBytes> {\n\t\t// prepend it into an intent message and computes the digest.\n\t\tconst intentMessage = messageWithIntent(intent, bytes);\n\t\tconst digest = blake2b(intentMessage, { dkLen: 32 });\n\n\t\t// sign the digest.\n\t\tconst signature = await this.sign(digest);\n\n\t\t// prepend with the passkey flag.\n\t\tconst serializedSignature = new Uint8Array(1 + signature.length);\n\t\tserializedSignature.set([SIGNATURE_SCHEME_TO_FLAG[this.getKeyScheme()]]);\n\t\tserializedSignature.set(signature, 1);\n\t\treturn {\n\t\t\tsignature: toBase64(serializedSignature),\n\t\t\tbytes: toBase64(bytes),\n\t\t};\n\t}\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,iBAAyB;AACzB,kBAA0B;AAC1B,qBAAwB;AACxB,mBAA4B;
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { toBase64 } from '@mysten/bcs';\nimport { secp256r1 } from '@noble/curves/p256';\nimport { blake2b } from '@noble/hashes/blake2b';\nimport { sha256 } from '@noble/hashes/sha256';\nimport { randomBytes } from '@noble/hashes/utils';\n\nimport { PasskeyAuthenticator } from '../../bcs/bcs.js';\nimport type { IntentScope, SignatureWithBytes } from '../../cryptography/index.js';\nimport { messageWithIntent, SIGNATURE_SCHEME_TO_FLAG, Signer } from '../../cryptography/index.js';\nimport type { PublicKey } from '../../cryptography/publickey.js';\nimport type { SignatureScheme } from '../../cryptography/signature-scheme.js';\nimport {\n\tparseDerSPKI,\n\tPASSKEY_PUBLIC_KEY_SIZE,\n\tPASSKEY_SIGNATURE_SIZE,\n\tPasskeyPublicKey,\n} from './publickey.js';\nimport type { AuthenticationCredential, RegistrationCredential } from './types.js';\n\ntype DeepPartialConfigKeys = 'rp' | 'user' | 'authenticatorSelection';\n\ntype DeepPartial<T> = T extends object\n\t? {\n\t\t\t[P in keyof T]?: DeepPartial<T[P]>;\n\t\t}\n\t: T;\n\nexport type BrowserPasswordProviderOptions = Pick<\n\tDeepPartial<PublicKeyCredentialCreationOptions>,\n\tDeepPartialConfigKeys\n> &\n\tOmit<\n\t\tPartial<PublicKeyCredentialCreationOptions>,\n\t\tDeepPartialConfigKeys | 'pubKeyCredParams' | 'challenge'\n\t>;\n\nexport interface PasskeyProvider {\n\tcreate(): Promise<RegistrationCredential>;\n\tget(challenge: Uint8Array): Promise<AuthenticationCredential>;\n}\n\n// Default browser implementation\nexport class BrowserPasskeyProvider implements PasskeyProvider {\n\t#name: string;\n\t#options: BrowserPasswordProviderOptions;\n\n\tconstructor(name: string, options: BrowserPasswordProviderOptions) {\n\t\tthis.#name = name;\n\t\tthis.#options = options;\n\t}\n\n\tasync create(): Promise<RegistrationCredential> {\n\t\treturn (await navigator.credentials.create({\n\t\t\tpublicKey: {\n\t\t\t\ttimeout: this.#options.timeout ?? 60000,\n\t\t\t\t...this.#options,\n\t\t\t\trp: {\n\t\t\t\t\tname: this.#name,\n\t\t\t\t\t...this.#options.rp,\n\t\t\t\t},\n\t\t\t\tuser: {\n\t\t\t\t\tname: this.#name,\n\t\t\t\t\tdisplayName: this.#name,\n\t\t\t\t\t...this.#options.user,\n\t\t\t\t\tid: randomBytes(10),\n\t\t\t\t},\n\t\t\t\tchallenge: new TextEncoder().encode('Create passkey wallet on Sui'),\n\t\t\t\tpubKeyCredParams: [{ alg: -7, type: 'public-key' }],\n\t\t\t\tauthenticatorSelection: {\n\t\t\t\t\tauthenticatorAttachment: 'cross-platform',\n\t\t\t\t\tresidentKey: 'required',\n\t\t\t\t\trequireResidentKey: true,\n\t\t\t\t\tuserVerification: 'required',\n\t\t\t\t\t...this.#options.authenticatorSelection,\n\t\t\t\t},\n\t\t\t},\n\t\t})) as RegistrationCredential;\n\t}\n\n\tasync get(challenge: Uint8Array): Promise<AuthenticationCredential> {\n\t\treturn (await navigator.credentials.get({\n\t\t\tpublicKey: {\n\t\t\t\tchallenge,\n\t\t\t\tuserVerification: this.#options.authenticatorSelection?.userVerification || 'required',\n\t\t\t\ttimeout: this.#options.timeout ?? 60000,\n\t\t\t},\n\t\t})) as AuthenticationCredential;\n\t}\n}\n\n/**\n * @experimental\n * A passkey signer used for signing transactions. This is a client side implementation for [SIP-9](https://github.com/sui-foundation/sips/blob/main/sips/sip-9.md).\n */\nexport class PasskeyKeypair extends Signer {\n\tprivate publicKey: Uint8Array;\n\tprivate provider: PasskeyProvider;\n\n\t/**\n\t * Get the key scheme of passkey,\n\t */\n\tgetKeyScheme(): SignatureScheme {\n\t\treturn 'Passkey';\n\t}\n\n\t/**\n\t * Creates an instance of Passkey signer. If no passkey wallet had created before,\n\t * use `getPasskeyInstance`. For example:\n\t * ```\n\t * let provider = new BrowserPasskeyProvider('Sui Passkey Example',{\n\t * \t rpName: 'Sui Passkey Example',\n\t * \t rpId: window.location.hostname,\n\t * } as BrowserPasswordProviderOptions);\n\t * const signer = await PasskeyKeypair.getPasskeyInstance(provider);\n\t * ```\n\t *\n\t * If there are existing passkey wallet, use `signAndRecover` to identify the correct\n\t * public key and then initialize the instance. See usage in `signAndRecover`.\n\t */\n\tconstructor(publicKey: Uint8Array, provider: PasskeyProvider) {\n\t\tsuper();\n\t\tthis.publicKey = publicKey;\n\t\tthis.provider = provider;\n\t}\n\n\t/**\n\t * Creates an instance of Passkey signer invoking the passkey from navigator.\n\t * Note that this will invoke the passkey device to create a fresh credential.\n\t * Should only be called if passkey wallet is created for the first time.\n\t *\n\t * @param provider - the passkey provider.\n\t * @returns the passkey instance.\n\t */\n\tstatic async getPasskeyInstance(provider: PasskeyProvider): Promise<PasskeyKeypair> {\n\t\t// create a passkey secp256r1 with the provider.\n\t\tconst credential = await provider.create();\n\n\t\tif (!credential.response.getPublicKey()) {\n\t\t\tthrow new Error('Invalid credential create response');\n\t\t} else {\n\t\t\tconst derSPKI = credential.response.getPublicKey()!;\n\t\t\tconst pubkeyUncompressed = parseDerSPKI(new Uint8Array(derSPKI));\n\t\t\tconst pubkey = secp256r1.ProjectivePoint.fromHex(pubkeyUncompressed);\n\t\t\tconst pubkeyCompressed = pubkey.toRawBytes(true);\n\t\t\treturn new PasskeyKeypair(pubkeyCompressed, provider);\n\t\t}\n\t}\n\n\t/**\n\t * Return the public key for this passkey.\n\t */\n\tgetPublicKey(): PublicKey {\n\t\treturn new PasskeyPublicKey(this.publicKey);\n\t}\n\n\t/**\n\t * Return the signature for the provided data (i.e. blake2b(intent_message)).\n\t * This is sent to passkey as the challenge field.\n\t */\n\tasync sign(data: Uint8Array) {\n\t\t// asks the passkey to sign over challenge as the data.\n\t\tconst credential = await this.provider.get(data);\n\n\t\t// parse authenticatorData (as bytes), clientDataJSON (decoded as string).\n\t\tconst authenticatorData = new Uint8Array(credential.response.authenticatorData);\n\t\tconst clientDataJSON = new Uint8Array(credential.response.clientDataJSON); // response.clientDataJSON is already UTF-8 encoded JSON\n\t\tconst decoder = new TextDecoder();\n\t\tconst clientDataJSONString: string = decoder.decode(clientDataJSON);\n\n\t\t// parse the signature from DER format, normalize and convert to compressed format (33 bytes).\n\t\tconst sig = secp256r1.Signature.fromDER(new Uint8Array(credential.response.signature));\n\t\tconst normalized = sig.normalizeS().toCompactRawBytes();\n\n\t\tif (\n\t\t\tnormalized.length !== PASSKEY_SIGNATURE_SIZE ||\n\t\t\tthis.publicKey.length !== PASSKEY_PUBLIC_KEY_SIZE\n\t\t) {\n\t\t\tthrow new Error('Invalid signature or public key length');\n\t\t}\n\n\t\t// construct userSignature as flag || sig || pubkey for the secp256r1 signature.\n\t\tconst arr = new Uint8Array(1 + normalized.length + this.publicKey.length);\n\t\tarr.set([SIGNATURE_SCHEME_TO_FLAG['Secp256r1']]);\n\t\tarr.set(normalized, 1);\n\t\tarr.set(this.publicKey, 1 + normalized.length);\n\n\t\t// serialize all fields into a passkey signature according to https://github.com/sui-foundation/sips/blob/main/sips/sip-9.md#signature-encoding\n\t\treturn PasskeyAuthenticator.serialize({\n\t\t\tauthenticatorData: authenticatorData,\n\t\t\tclientDataJson: clientDataJSONString,\n\t\t\tuserSignature: arr,\n\t\t}).toBytes();\n\t}\n\n\t/**\n\t * This overrides the base class implementation that accepts the raw bytes and signs its\n\t * digest of the intent message, then serialize it with the passkey flag.\n\t */\n\tasync signWithIntent(bytes: Uint8Array, intent: IntentScope): Promise<SignatureWithBytes> {\n\t\t// prepend it into an intent message and computes the digest.\n\t\tconst intentMessage = messageWithIntent(intent, bytes);\n\t\tconst digest = blake2b(intentMessage, { dkLen: 32 });\n\n\t\t// sign the digest.\n\t\tconst signature = await this.sign(digest);\n\n\t\t// prepend with the passkey flag.\n\t\tconst serializedSignature = new Uint8Array(1 + signature.length);\n\t\tserializedSignature.set([SIGNATURE_SCHEME_TO_FLAG[this.getKeyScheme()]]);\n\t\tserializedSignature.set(signature, 1);\n\t\treturn {\n\t\t\tsignature: toBase64(serializedSignature),\n\t\t\tbytes: toBase64(bytes),\n\t\t};\n\t}\n\n\t/**\n\t * Given a message, asks the passkey device to sign it and return all (up to 4) possible public keys.\n\t * See: https://bitcoin.stackexchange.com/questions/81232/how-is-public-key-extracted-from-message-digital-signature-address\n\t *\n\t * This is useful if the user previously created passkey wallet with the origin, but the wallet session\n\t * does not have the public key / address. By calling this method twice with two different messages, the\n\t * wallet can compare the returned public keys and uniquely identify the previously created passkey wallet\n\t * using `findCommonPublicKey`.\n\t *\n\t * Alternatively, one call can be made and all possible public keys should be checked onchain to see if\n\t * there is any assets.\n\t *\n\t * Once the correct public key is identified, a passkey instance can then be initialized with this public key.\n\t *\n\t * Example usage to recover wallet with two signing calls:\n\t * ```\n\t * let provider = new BrowserPasskeyProvider('Sui Passkey Example',{\n\t * rpName: 'Sui Passkey Example',\n\t * \t rpId: window.location.hostname,\n\t * } as BrowserPasswordProviderOptions);\n\t * const testMessage = new TextEncoder().encode('Hello world!');\n\t * const possiblePks = await PasskeyKeypair.signAndRecover(provider, testMessage);\n\t * const testMessage2 = new TextEncoder().encode('Hello world 2!');\n\t * const possiblePks2 = await PasskeyKeypair.signAndRecover(provider, testMessage2);\n\t * const commonPk = findCommonPublicKey(possiblePks, possiblePks2);\n\t * const signer = new PasskeyKeypair(provider, commonPk.toRawBytes());\n\t * ```\n\t *\n\t * @param provider - the passkey provider.\n\t * @param message - the message to sign.\n\t * @returns all possible public keys.\n\t */\n\tstatic async signAndRecover(\n\t\tprovider: PasskeyProvider,\n\t\tmessage: Uint8Array,\n\t): Promise<PublicKey[]> {\n\t\tconst credential = await provider.get(message);\n\t\tconst fullMessage = messageFromAssertionResponse(credential.response);\n\t\tconst sig = secp256r1.Signature.fromDER(new Uint8Array(credential.response.signature));\n\n\t\tconst res = [];\n\t\tfor (let i = 0; i < 4; i++) {\n\t\t\tconst s = sig.addRecoveryBit(i);\n\t\t\ttry {\n\t\t\t\tconst pubkey = s.recoverPublicKey(sha256(fullMessage));\n\t\t\t\tconst pk = new PasskeyPublicKey(pubkey.toRawBytes(true));\n\t\t\t\tres.push(pk);\n\t\t\t} catch {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\t\treturn res;\n\t}\n}\n\n/**\n * Finds the unique public key that exists in both arrays, throws error if the common\n * pubkey does not equal to one.\n *\n * @param arr1 - The first pubkeys array.\n * @param arr2 - The second pubkeys array.\n * @returns The only common pubkey in both arrays.\n */\nexport function findCommonPublicKey(arr1: PublicKey[], arr2: PublicKey[]): PublicKey {\n\tconst matchingPubkeys: PublicKey[] = [];\n\tfor (const pubkey1 of arr1) {\n\t\tfor (const pubkey2 of arr2) {\n\t\t\tif (pubkey1.equals(pubkey2)) {\n\t\t\t\tmatchingPubkeys.push(pubkey1);\n\t\t\t}\n\t\t}\n\t}\n\tif (matchingPubkeys.length !== 1) {\n\t\tthrow new Error('No unique public key found');\n\t}\n\treturn matchingPubkeys[0];\n}\n\n/**\n * Constructs the message that the passkey signature is produced over as authenticatorData || sha256(clientDataJSON).\n */\nfunction messageFromAssertionResponse(response: AuthenticatorAssertionResponse): Uint8Array {\n\tconst authenticatorData = new Uint8Array(response.authenticatorData);\n\tconst clientDataJSON = new Uint8Array(response.clientDataJSON);\n\tconst clientDataJSONDigest = sha256(clientDataJSON);\n\treturn new Uint8Array([...authenticatorData, ...clientDataJSONDigest]);\n}\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
6
|
"names": ["import_bcs"]
|
|
7
7
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The value returned from navigator.credentials.get()
|
|
3
|
+
*/
|
|
4
|
+
export interface AuthenticationCredential extends PublicKeyCredential {
|
|
5
|
+
response: AuthenticatorAssertionResponse;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* The value returned from navigator.credentials.create()
|
|
9
|
+
*/
|
|
10
|
+
export interface RegistrationCredential extends PublicKeyCredential {
|
|
11
|
+
response: AuthenticatorAttestationResponse;
|
|
12
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
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 __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var types_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(types_exports);
|
|
17
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/keypairs/passkey/types.ts"],
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\n/**\n * The value returned from navigator.credentials.get()\n */\nexport interface AuthenticationCredential extends PublicKeyCredential {\n\tresponse: AuthenticatorAssertionResponse;\n}\n\n/**\n * The value returned from navigator.credentials.create()\n */\nexport interface RegistrationCredential extends PublicKeyCredential {\n\tresponse: AuthenticatorAttestationResponse;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;AAAA;AAAA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { SerializedBcs } from '@mysten/bcs';
|
|
2
|
-
import type {
|
|
2
|
+
import type { PureTypeName, ShapeFromPureTypeName, ValidPureTypeName } from '../bcs/pure.js';
|
|
3
3
|
export declare function createPure<T>(makePure: (value: SerializedBcs<any, any> | Uint8Array) => T): {
|
|
4
4
|
<T_1 extends PureTypeName>(type: T_1 extends PureTypeName ? ValidPureTypeName<T_1> : T_1, value: ShapeFromPureTypeName<T_1>): T_1;
|
|
5
5
|
(value: SerializedBcs<any, any> | Uint8Array): T;
|
|
@@ -18,11 +18,3 @@ export declare function createPure<T>(makePure: (value: SerializedBcs<any, any>
|
|
|
18
18
|
}): T;
|
|
19
19
|
option<Type extends PureTypeName>(type: T extends PureTypeName ? ValidPureTypeName<Type> : Type, value: ShapeFromPureTypeName<Type> | null | undefined): T;
|
|
20
20
|
};
|
|
21
|
-
export type BasePureType = 'u8' | 'u16' | 'u32' | 'u64' | 'u128' | 'u256' | 'bool' | 'id' | 'string' | 'address';
|
|
22
|
-
export type PureTypeName = BasePureType | `vector<${string}>` | `option<${string}>`;
|
|
23
|
-
export type ValidPureTypeName<T extends string> = T extends BasePureType ? PureTypeName : T extends `vector<${infer U}>` ? ValidPureTypeName<U> : T extends `option<${infer U}>` ? ValidPureTypeName<U> : PureTypeValidationError<T>;
|
|
24
|
-
type ShapeFromPureTypeName<T extends PureTypeName> = T extends BasePureType ? Parameters<ReturnType<typeof createPure<Argument>>[T]>[0] : T extends `vector<${infer U extends PureTypeName}>` ? ShapeFromPureTypeName<U>[] : T extends `option<${infer U extends PureTypeName}>` ? ShapeFromPureTypeName<U> | null : never;
|
|
25
|
-
type PureTypeValidationError<T extends string> = T & {
|
|
26
|
-
error: `Invalid Pure type name: ${T}`;
|
|
27
|
-
};
|
|
28
|
-
export {};
|
|
@@ -23,10 +23,11 @@ __export(pure_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(pure_exports);
|
|
24
24
|
var import_bcs = require("@mysten/bcs");
|
|
25
25
|
var import_bcs2 = require("../bcs/index.js");
|
|
26
|
+
var import_pure = require("../bcs/pure.js");
|
|
26
27
|
function createPure(makePure) {
|
|
27
28
|
function pure(typeOrSerializedValue, value) {
|
|
28
29
|
if (typeof typeOrSerializedValue === "string") {
|
|
29
|
-
return makePure(
|
|
30
|
+
return makePure((0, import_pure.pureBcsSchemaFromTypeName)(typeOrSerializedValue).serialize(value));
|
|
30
31
|
}
|
|
31
32
|
if (typeOrSerializedValue instanceof Uint8Array || (0, import_bcs.isSerializedBcs)(typeOrSerializedValue)) {
|
|
32
33
|
return makePure(typeOrSerializedValue);
|
|
@@ -44,44 +45,13 @@ function createPure(makePure) {
|
|
|
44
45
|
pure.address = (value) => makePure(import_bcs2.bcs.Address.serialize(value));
|
|
45
46
|
pure.id = pure.address;
|
|
46
47
|
pure.vector = (type, value) => {
|
|
47
|
-
return makePure(
|
|
48
|
+
return makePure(
|
|
49
|
+
import_bcs2.bcs.vector((0, import_pure.pureBcsSchemaFromTypeName)(type)).serialize(value)
|
|
50
|
+
);
|
|
48
51
|
};
|
|
49
52
|
pure.option = (type, value) => {
|
|
50
|
-
return makePure(import_bcs2.bcs.option(
|
|
53
|
+
return makePure(import_bcs2.bcs.option((0, import_pure.pureBcsSchemaFromTypeName)(type)).serialize(value));
|
|
51
54
|
};
|
|
52
55
|
return pure;
|
|
53
56
|
}
|
|
54
|
-
function schemaFromName(name) {
|
|
55
|
-
switch (name) {
|
|
56
|
-
case "u8":
|
|
57
|
-
return import_bcs2.bcs.u8();
|
|
58
|
-
case "u16":
|
|
59
|
-
return import_bcs2.bcs.u16();
|
|
60
|
-
case "u32":
|
|
61
|
-
return import_bcs2.bcs.u32();
|
|
62
|
-
case "u64":
|
|
63
|
-
return import_bcs2.bcs.u64();
|
|
64
|
-
case "u128":
|
|
65
|
-
return import_bcs2.bcs.u128();
|
|
66
|
-
case "u256":
|
|
67
|
-
return import_bcs2.bcs.u256();
|
|
68
|
-
case "bool":
|
|
69
|
-
return import_bcs2.bcs.bool();
|
|
70
|
-
case "string":
|
|
71
|
-
return import_bcs2.bcs.string();
|
|
72
|
-
case "id":
|
|
73
|
-
case "address":
|
|
74
|
-
return import_bcs2.bcs.Address;
|
|
75
|
-
}
|
|
76
|
-
const generic = name.match(/^(vector|option)<(.+)>$/);
|
|
77
|
-
if (generic) {
|
|
78
|
-
const [kind, inner] = generic.slice(1);
|
|
79
|
-
if (kind === "vector") {
|
|
80
|
-
return import_bcs2.bcs.vector(schemaFromName(inner));
|
|
81
|
-
} else {
|
|
82
|
-
return import_bcs2.bcs.option(schemaFromName(inner));
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
throw new Error(`Invalid Pure type name: ${name}`);
|
|
86
|
-
}
|
|
87
57
|
//# sourceMappingURL=pure.js.map
|