passkey-kit 0.5.4 → 0.5.6
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/package.json +3 -3
- package/src/kit.ts +20 -13
- package/types/kit.d.ts +7 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "passkey-kit",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.6",
|
|
4
4
|
"description": "A helper library for creating and using passkey accounts on the Stellar blockchain.",
|
|
5
5
|
"author": "Tyler van der Hoeven",
|
|
6
6
|
"license": "MIT",
|
|
@@ -13,9 +13,9 @@
|
|
|
13
13
|
"@stellar/stellar-sdk": "12.1.0",
|
|
14
14
|
"base64url": "^3.0.1",
|
|
15
15
|
"buffer": "^6.0.3",
|
|
16
|
-
"passkey-factory-sdk": "0.2.1",
|
|
17
16
|
"passkey-kit-sdk": "0.2.1",
|
|
18
|
-
"sac-sdk": "0.1.0"
|
|
17
|
+
"sac-sdk": "0.1.0",
|
|
18
|
+
"passkey-factory-sdk": "0.2.1"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"@simplewebauthn/types": "^10.0.0",
|
package/src/kit.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { Client as FactoryClient } from 'passkey-factory-sdk'
|
|
|
3
3
|
import { Address, StrKey, hash, xdr, Transaction, SorobanRpc, Operation, TransactionBuilder } from '@stellar/stellar-sdk'
|
|
4
4
|
import base64url from 'base64url'
|
|
5
5
|
import { startRegistration, startAuthentication } from "@simplewebauthn/browser"
|
|
6
|
-
import type { AuthenticatorAttestationResponseJSON } from "@simplewebauthn/types"
|
|
6
|
+
import type { AuthenticatorAttestationResponseJSON, AuthenticatorSelectionCriteria } from "@simplewebauthn/types"
|
|
7
7
|
import { Buffer } from 'buffer'
|
|
8
8
|
import { PasskeyBase } from './base'
|
|
9
9
|
import { DEFAULT_TIMEOUT } from '@stellar/stellar-sdk/contract'
|
|
@@ -29,7 +29,7 @@ export class PasskeyKit extends PasskeyBase {
|
|
|
29
29
|
startAuthentication: typeof startAuthentication
|
|
30
30
|
}
|
|
31
31
|
}) {
|
|
32
|
-
const { rpcUrl, networkPassphrase, factoryContractId } = options
|
|
32
|
+
const { rpcUrl, networkPassphrase, factoryContractId, WebAuthn } = options
|
|
33
33
|
|
|
34
34
|
super(rpcUrl)
|
|
35
35
|
|
|
@@ -39,7 +39,7 @@ export class PasskeyKit extends PasskeyBase {
|
|
|
39
39
|
networkPassphrase,
|
|
40
40
|
rpcUrl
|
|
41
41
|
})
|
|
42
|
-
this.WebAuthn =
|
|
42
|
+
this.WebAuthn = WebAuthn || { startRegistration, startAuthentication }
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
public async createWallet(app: string, user: string) {
|
|
@@ -66,13 +66,17 @@ export class PasskeyKit extends PasskeyBase {
|
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
public async createKey(app: string, user: string
|
|
69
|
+
public async createKey(app: string, user: string, settings?: {
|
|
70
|
+
rpId?: string
|
|
71
|
+
authenticatorSelection?: AuthenticatorSelectionCriteria
|
|
72
|
+
}) {
|
|
70
73
|
const now = new Date()
|
|
71
74
|
const displayName = `${user} — ${now.toLocaleString()}`
|
|
75
|
+
const { rpId, authenticatorSelection } = settings || {}
|
|
72
76
|
const { id, response } = await this.WebAuthn.startRegistration({
|
|
73
77
|
challenge: base64url("stellaristhebetterblockchain"),
|
|
74
78
|
rp: {
|
|
75
|
-
|
|
79
|
+
id: rpId,
|
|
76
80
|
name: app,
|
|
77
81
|
},
|
|
78
82
|
user: {
|
|
@@ -80,10 +84,11 @@ export class PasskeyKit extends PasskeyBase {
|
|
|
80
84
|
name: displayName,
|
|
81
85
|
displayName
|
|
82
86
|
},
|
|
87
|
+
authenticatorSelection,
|
|
83
88
|
// authenticatorSelection: {
|
|
84
|
-
//
|
|
85
|
-
//
|
|
86
|
-
//
|
|
89
|
+
// requireResidentKey: false,
|
|
90
|
+
// residentKey: "preferred",
|
|
91
|
+
// userVerification: "discouraged",
|
|
87
92
|
// },
|
|
88
93
|
pubKeyCredParams: [{ alg: -7, type: "public-key" }],
|
|
89
94
|
// attestation: "none",
|
|
@@ -101,15 +106,16 @@ export class PasskeyKit extends PasskeyBase {
|
|
|
101
106
|
|
|
102
107
|
public async connectWallet(opts?: {
|
|
103
108
|
keyId?: string | Uint8Array,
|
|
109
|
+
rpId?: string,
|
|
104
110
|
getContractId?: (keyId: string) => Promise<string | undefined>
|
|
105
111
|
}) {
|
|
106
|
-
let { keyId, getContractId } = opts || {}
|
|
112
|
+
let { keyId, rpId, getContractId } = opts || {}
|
|
107
113
|
let keyIdBuffer: Buffer
|
|
108
114
|
|
|
109
115
|
if (!keyId) {
|
|
110
116
|
const response = await this.WebAuthn.startAuthentication({
|
|
111
117
|
challenge: base64url("stellaristhebetterblockchain"),
|
|
112
|
-
|
|
118
|
+
rpId,
|
|
113
119
|
// userVerification: "discouraged",
|
|
114
120
|
// timeout: 120_000
|
|
115
121
|
});
|
|
@@ -169,10 +175,11 @@ export class PasskeyKit extends PasskeyBase {
|
|
|
169
175
|
entry: xdr.SorobanAuthorizationEntry,
|
|
170
176
|
options?: {
|
|
171
177
|
keyId?: 'any' | string | Uint8Array
|
|
178
|
+
rpId?: string,
|
|
172
179
|
ledgersToLive?: number
|
|
173
180
|
}
|
|
174
181
|
) {
|
|
175
|
-
let { keyId, ledgersToLive = DEFAULT_TIMEOUT } = options || {}
|
|
182
|
+
let { keyId, rpId, ledgersToLive = DEFAULT_TIMEOUT } = options || {}
|
|
176
183
|
|
|
177
184
|
const lastLedger = await this.rpc.getLatestLedger().then(({ sequence }) => sequence)
|
|
178
185
|
const credentials = entry.credentials().address();
|
|
@@ -191,13 +198,13 @@ export class PasskeyKit extends PasskeyBase {
|
|
|
191
198
|
|| (!keyId && !this.keyId)
|
|
192
199
|
? {
|
|
193
200
|
challenge: base64url(payload),
|
|
194
|
-
|
|
201
|
+
rpId,
|
|
195
202
|
// userVerification: "discouraged",
|
|
196
203
|
// timeout: 120_000
|
|
197
204
|
}
|
|
198
205
|
: {
|
|
199
206
|
challenge: base64url(payload),
|
|
200
|
-
|
|
207
|
+
rpId,
|
|
201
208
|
allowCredentials: [
|
|
202
209
|
{
|
|
203
210
|
id: keyId instanceof Uint8Array
|
package/types/kit.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { Client as PasskeyClient } from 'passkey-kit-sdk';
|
|
|
2
2
|
import { Client as FactoryClient } from 'passkey-factory-sdk';
|
|
3
3
|
import { xdr, Transaction, SorobanRpc } from '@stellar/stellar-sdk';
|
|
4
4
|
import { startRegistration, startAuthentication } from "@simplewebauthn/browser";
|
|
5
|
+
import type { AuthenticatorSelectionCriteria } from "@simplewebauthn/types";
|
|
5
6
|
import { Buffer } from 'buffer';
|
|
6
7
|
import { PasskeyBase } from './base';
|
|
7
8
|
export declare class PasskeyKit extends PasskeyBase {
|
|
@@ -29,12 +30,16 @@ export declare class PasskeyKit extends PasskeyBase {
|
|
|
29
30
|
contractId: string;
|
|
30
31
|
xdr: string | undefined;
|
|
31
32
|
}>;
|
|
32
|
-
createKey(app: string, user: string
|
|
33
|
+
createKey(app: string, user: string, settings?: {
|
|
34
|
+
rpId?: string;
|
|
35
|
+
authenticatorSelection?: AuthenticatorSelectionCriteria;
|
|
36
|
+
}): Promise<{
|
|
33
37
|
keyId: Buffer;
|
|
34
38
|
publicKey: Buffer;
|
|
35
39
|
}>;
|
|
36
40
|
connectWallet(opts?: {
|
|
37
41
|
keyId?: string | Uint8Array;
|
|
42
|
+
rpId?: string;
|
|
38
43
|
getContractId?: (keyId: string) => Promise<string | undefined>;
|
|
39
44
|
}): Promise<{
|
|
40
45
|
keyId: Buffer;
|
|
@@ -42,6 +47,7 @@ export declare class PasskeyKit extends PasskeyBase {
|
|
|
42
47
|
}>;
|
|
43
48
|
signAuthEntry(entry: xdr.SorobanAuthorizationEntry, options?: {
|
|
44
49
|
keyId?: 'any' | string | Uint8Array;
|
|
50
|
+
rpId?: string;
|
|
45
51
|
ledgersToLive?: number;
|
|
46
52
|
}): Promise<xdr.SorobanAuthorizationEntry>;
|
|
47
53
|
signAuthEntries(entries: xdr.SorobanAuthorizationEntry[], options?: {
|