phonelink 0.1.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/dist/chunk-27WHFHUI.mjs +11 -0
- package/dist/expo/index.d.mts +10 -0
- package/dist/expo/index.d.ts +10 -0
- package/dist/expo/index.js +70 -0
- package/dist/expo/index.mjs +31 -0
- package/dist/server/index.d.mts +5 -0
- package/dist/server/index.d.ts +5 -0
- package/dist/server/index.js +51 -0
- package/dist/server/index.mjs +25 -0
- package/dist/types-C_z0XiQR.d.mts +15 -0
- package/dist/types-C_z0XiQR.d.ts +15 -0
- package/package.json +49 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// src/shared/constants.ts
|
|
2
|
+
var PHONELINK_URL = "https://phonelink-web-git-new-base-vrl.vercel.app/auth";
|
|
3
|
+
var EXPECTED_ISSUER = "https://auth.phone.link";
|
|
4
|
+
function buildAuthUrl(clientId, redirectUrl, nonce) {
|
|
5
|
+
return `${PHONELINK_URL}?client_id=${encodeURIComponent(clientId)}&redirect_url=${encodeURIComponent(redirectUrl)}&nonce=${nonce}`;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export {
|
|
9
|
+
EXPECTED_ISSUER,
|
|
10
|
+
buildAuthUrl
|
|
11
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/expo/index.ts
|
|
31
|
+
var expo_exports = {};
|
|
32
|
+
__export(expo_exports, {
|
|
33
|
+
phonelink: () => phonelink
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(expo_exports);
|
|
36
|
+
var Crypto = __toESM(require("expo-crypto"));
|
|
37
|
+
var WebBrowser = __toESM(require("expo-web-browser"));
|
|
38
|
+
|
|
39
|
+
// src/shared/constants.ts
|
|
40
|
+
var PHONELINK_URL = "https://phonelink-web-git-new-base-vrl.vercel.app/auth";
|
|
41
|
+
function buildAuthUrl(clientId, redirectUrl, nonce) {
|
|
42
|
+
return `${PHONELINK_URL}?client_id=${encodeURIComponent(clientId)}&redirect_url=${encodeURIComponent(redirectUrl)}&nonce=${nonce}`;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// src/expo/index.ts
|
|
46
|
+
function generateNonce(length = 32) {
|
|
47
|
+
const bytes = Crypto.getRandomBytes(length);
|
|
48
|
+
return Array.from(bytes).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
49
|
+
}
|
|
50
|
+
var phonelink = {
|
|
51
|
+
async verify(clientId, redirectUrl) {
|
|
52
|
+
const redirectUrlParam = redirectUrl || "phonelink://verify";
|
|
53
|
+
const nonce = generateNonce();
|
|
54
|
+
const url = buildAuthUrl(clientId, redirectUrlParam, nonce);
|
|
55
|
+
const result = await WebBrowser.openAuthSessionAsync(
|
|
56
|
+
url,
|
|
57
|
+
redirectUrlParam
|
|
58
|
+
);
|
|
59
|
+
if (result.type === "success") {
|
|
60
|
+
const token = new URL(result.url).searchParams.get("token");
|
|
61
|
+
if (!token) return null;
|
|
62
|
+
return { token, nonce };
|
|
63
|
+
}
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
68
|
+
0 && (module.exports = {
|
|
69
|
+
phonelink
|
|
70
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import {
|
|
2
|
+
buildAuthUrl
|
|
3
|
+
} from "../chunk-27WHFHUI.mjs";
|
|
4
|
+
|
|
5
|
+
// src/expo/index.ts
|
|
6
|
+
import * as Crypto from "expo-crypto";
|
|
7
|
+
import * as WebBrowser from "expo-web-browser";
|
|
8
|
+
function generateNonce(length = 32) {
|
|
9
|
+
const bytes = Crypto.getRandomBytes(length);
|
|
10
|
+
return Array.from(bytes).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
11
|
+
}
|
|
12
|
+
var phonelink = {
|
|
13
|
+
async verify(clientId, redirectUrl) {
|
|
14
|
+
const redirectUrlParam = redirectUrl || "phonelink://verify";
|
|
15
|
+
const nonce = generateNonce();
|
|
16
|
+
const url = buildAuthUrl(clientId, redirectUrlParam, nonce);
|
|
17
|
+
const result = await WebBrowser.openAuthSessionAsync(
|
|
18
|
+
url,
|
|
19
|
+
redirectUrlParam
|
|
20
|
+
);
|
|
21
|
+
if (result.type === "success") {
|
|
22
|
+
const token = new URL(result.url).searchParams.get("token");
|
|
23
|
+
if (!token) return null;
|
|
24
|
+
return { token, nonce };
|
|
25
|
+
}
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
export {
|
|
30
|
+
phonelink
|
|
31
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
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
|
+
|
|
20
|
+
// src/server/index.ts
|
|
21
|
+
var server_exports = {};
|
|
22
|
+
__export(server_exports, {
|
|
23
|
+
verifyPhonelinkToken: () => verifyPhonelinkToken
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(server_exports);
|
|
26
|
+
var import_jose = require("jose");
|
|
27
|
+
|
|
28
|
+
// src/shared/constants.ts
|
|
29
|
+
var EXPECTED_ISSUER = "https://auth.phone.link";
|
|
30
|
+
|
|
31
|
+
// src/server/index.ts
|
|
32
|
+
var JWKS = (0, import_jose.createRemoteJWKSet)(
|
|
33
|
+
new URL("https://auth.phone.link/.well-known/jwks.json")
|
|
34
|
+
);
|
|
35
|
+
async function verifyPhonelinkToken(token, expectedNonce, expectedAud) {
|
|
36
|
+
const { payload } = await (0, import_jose.jwtVerify)(token, JWKS, {
|
|
37
|
+
issuer: EXPECTED_ISSUER,
|
|
38
|
+
audience: expectedAud
|
|
39
|
+
});
|
|
40
|
+
if (payload.nonce !== expectedNonce) {
|
|
41
|
+
throw new Error("Nonce mismatch");
|
|
42
|
+
}
|
|
43
|
+
if (payload.verified !== true) {
|
|
44
|
+
throw new Error("Phone number not verified");
|
|
45
|
+
}
|
|
46
|
+
return payload;
|
|
47
|
+
}
|
|
48
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
49
|
+
0 && (module.exports = {
|
|
50
|
+
verifyPhonelinkToken
|
|
51
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import {
|
|
2
|
+
EXPECTED_ISSUER
|
|
3
|
+
} from "../chunk-27WHFHUI.mjs";
|
|
4
|
+
|
|
5
|
+
// src/server/index.ts
|
|
6
|
+
import { createRemoteJWKSet, jwtVerify } from "jose";
|
|
7
|
+
var JWKS = createRemoteJWKSet(
|
|
8
|
+
new URL("https://auth.phone.link/.well-known/jwks.json")
|
|
9
|
+
);
|
|
10
|
+
async function verifyPhonelinkToken(token, expectedNonce, expectedAud) {
|
|
11
|
+
const { payload } = await jwtVerify(token, JWKS, {
|
|
12
|
+
issuer: EXPECTED_ISSUER,
|
|
13
|
+
audience: expectedAud
|
|
14
|
+
});
|
|
15
|
+
if (payload.nonce !== expectedNonce) {
|
|
16
|
+
throw new Error("Nonce mismatch");
|
|
17
|
+
}
|
|
18
|
+
if (payload.verified !== true) {
|
|
19
|
+
throw new Error("Phone number not verified");
|
|
20
|
+
}
|
|
21
|
+
return payload;
|
|
22
|
+
}
|
|
23
|
+
export {
|
|
24
|
+
verifyPhonelinkToken
|
|
25
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
interface PhonelinkPayload {
|
|
2
|
+
phone_e164: string;
|
|
3
|
+
verified: boolean;
|
|
4
|
+
method: string;
|
|
5
|
+
provider: string;
|
|
6
|
+
nonce: string;
|
|
7
|
+
sub: string;
|
|
8
|
+
iss: string;
|
|
9
|
+
aud: string;
|
|
10
|
+
iat: number;
|
|
11
|
+
exp: number;
|
|
12
|
+
jti: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export type { PhonelinkPayload as P };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
interface PhonelinkPayload {
|
|
2
|
+
phone_e164: string;
|
|
3
|
+
verified: boolean;
|
|
4
|
+
method: string;
|
|
5
|
+
provider: string;
|
|
6
|
+
nonce: string;
|
|
7
|
+
sub: string;
|
|
8
|
+
iss: string;
|
|
9
|
+
aud: string;
|
|
10
|
+
iat: number;
|
|
11
|
+
exp: number;
|
|
12
|
+
jti: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export type { PhonelinkPayload as P };
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "phonelink",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Phone number verification SDK",
|
|
5
|
+
"exports": {
|
|
6
|
+
"./expo": {
|
|
7
|
+
"types": "./dist/expo/index.d.ts",
|
|
8
|
+
"import": "./dist/expo/index.mjs",
|
|
9
|
+
"require": "./dist/expo/index.js"
|
|
10
|
+
},
|
|
11
|
+
"./server": {
|
|
12
|
+
"types": "./dist/server/index.d.ts",
|
|
13
|
+
"import": "./dist/server/index.mjs",
|
|
14
|
+
"require": "./dist/server/index.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"typesVersions": {
|
|
18
|
+
"*": {
|
|
19
|
+
"expo": ["dist/expo/index.d.ts"],
|
|
20
|
+
"server": ["dist/server/index.d.ts"]
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"files": ["dist"],
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "tsup",
|
|
26
|
+
"prepublishOnly": "npm run build"
|
|
27
|
+
},
|
|
28
|
+
"peerDependencies": {
|
|
29
|
+
"expo-crypto": ">=15.0.0",
|
|
30
|
+
"expo-web-browser": ">=15.0.0"
|
|
31
|
+
},
|
|
32
|
+
"peerDependenciesMeta": {
|
|
33
|
+
"expo-crypto": {
|
|
34
|
+
"optional": true
|
|
35
|
+
},
|
|
36
|
+
"expo-web-browser": {
|
|
37
|
+
"optional": true
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"jose": "^6.0.11"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"expo-crypto": "~15.0.8",
|
|
45
|
+
"expo-web-browser": "~15.0.10",
|
|
46
|
+
"tsup": "^8.4.0",
|
|
47
|
+
"typescript": "~5.9.2"
|
|
48
|
+
}
|
|
49
|
+
}
|