@ic-reactor/core 3.6.0 → 3.7.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/README.md +4 -4
- package/dist/client.d.ts +17 -79
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +49 -527
- package/dist/client.js.map +1 -1
- package/dist/display/visitor.d.ts.map +1 -1
- package/dist/display/visitor.js +6 -1
- package/dist/display/visitor.js.map +1 -1
- package/dist/display-reactor.d.ts +3 -0
- package/dist/display-reactor.d.ts.map +1 -1
- package/dist/display-reactor.js +3 -0
- package/dist/display-reactor.js.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/dist/reactor.d.ts +4 -4
- package/dist/reactor.d.ts.map +1 -1
- package/dist/reactor.js +27 -10
- package/dist/reactor.js.map +1 -1
- package/dist/types/client.d.ts +1 -120
- package/dist/types/client.d.ts.map +1 -1
- package/dist/types/display-reactor.d.ts.map +1 -1
- package/dist/types/reactor.d.ts +8 -0
- package/dist/types/reactor.d.ts.map +1 -1
- package/dist/types/variant.d.ts.map +1 -1
- package/dist/utils/agent.d.ts +3 -2
- package/dist/utils/agent.d.ts.map +1 -1
- package/dist/utils/agent.js +9 -3
- package/dist/utils/agent.js.map +1 -1
- package/dist/utils/constants.d.ts +0 -2
- package/dist/utils/constants.d.ts.map +1 -1
- package/dist/utils/constants.js +0 -2
- package/dist/utils/constants.js.map +1 -1
- package/dist/utils/helper.d.ts +14 -1
- package/dist/utils/helper.d.ts.map +1 -1
- package/dist/utils/helper.js +48 -9
- package/dist/utils/helper.js.map +1 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/polling.d.ts.map +1 -1
- package/dist/utils/polling.js +2 -2
- package/dist/utils/polling.js.map +1 -1
- package/dist/utils/query-data.d.ts +4 -0
- package/dist/utils/query-data.d.ts.map +1 -0
- package/dist/utils/query-data.js +3 -0
- package/dist/utils/query-data.js.map +1 -0
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +2 -2
- package/dist/version.js.map +1 -1
- package/llms.txt +43 -0
- package/package.json +15 -17
- package/src/client.ts +53 -626
- package/src/display/visitor.ts +10 -1
- package/src/display-reactor.ts +3 -0
- package/src/index.ts +0 -1
- package/src/reactor.ts +48 -18
- package/src/types/client.ts +1 -138
- package/src/types/display-reactor.ts +1 -2
- package/src/types/reactor.ts +15 -0
- package/src/types/variant.ts +8 -6
- package/src/utils/agent.ts +12 -3
- package/src/utils/constants.ts +0 -5
- package/src/utils/helper.ts +52 -7
- package/src/utils/index.ts +1 -0
- package/src/utils/polling.ts +3 -3
- package/src/utils/query-data.ts +5 -0
- package/src/version.ts +2 -2
- package/dist/identity-attributes.d.ts +0 -19
- package/dist/identity-attributes.d.ts.map +0 -1
- package/dist/identity-attributes.js +0 -167
- package/dist/identity-attributes.js.map +0 -1
- package/src/identity-attributes.ts +0 -263
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
import { IDL } from "@icp-sdk/core/candid";
|
|
2
|
-
import { IC_INTERNET_IDENTITY_PROVIDER } from "./utils/constants";
|
|
3
|
-
export const IDENTITY_ATTRIBUTES_PROVIDER = IC_INTERNET_IDENTITY_PROVIDER;
|
|
4
|
-
/**
|
|
5
|
-
* @deprecated Use the default ClientManager identity provider or
|
|
6
|
-
* `IDENTITY_ATTRIBUTES_PROVIDER` instead.
|
|
7
|
-
*/
|
|
8
|
-
export const IDENTITY_ATTRIBUTES_BETA_PROVIDER = IDENTITY_ATTRIBUTES_PROVIDER;
|
|
9
|
-
const OPEN_ID_PROVIDER_URLS = {
|
|
10
|
-
apple: "https://appleid.apple.com",
|
|
11
|
-
google: "https://accounts.google.com",
|
|
12
|
-
microsoft: "https://login.microsoftonline.com/{tid}/v2.0",
|
|
13
|
-
};
|
|
14
|
-
export function identityAttributeKeys({ openIdProvider, keys, }) {
|
|
15
|
-
const provider = normalizeOpenIdProvider(openIdProvider);
|
|
16
|
-
return keys.map((key) => `openid:${provider}:${key}`);
|
|
17
|
-
}
|
|
18
|
-
export function normalizeOpenIdProvider(openIdProvider) {
|
|
19
|
-
return (OPEN_ID_PROVIDER_URLS[openIdProvider] ?? openIdProvider);
|
|
20
|
-
}
|
|
21
|
-
export async function resolveIdentityAttributeKeys({ openIdProvider, keys, }) {
|
|
22
|
-
return identityAttributeKeys({ openIdProvider, keys });
|
|
23
|
-
}
|
|
24
|
-
export function decodeIdentityAttributeValues(data, requestedKeys) {
|
|
25
|
-
const requestedKeyMap = requestedKeys.reduce((acc, key) => {
|
|
26
|
-
acc[key] = identityAttributeDisplayKey(key);
|
|
27
|
-
acc[identityAttributeDisplayKey(key)] = identityAttributeDisplayKey(key);
|
|
28
|
-
return acc;
|
|
29
|
-
}, {});
|
|
30
|
-
const decodedValues = decodeCandidAttributeValues(data, requestedKeyMap);
|
|
31
|
-
if (Object.keys(decodedValues).length > 0) {
|
|
32
|
-
return decodedValues;
|
|
33
|
-
}
|
|
34
|
-
return extractPrintableAttributeValues(data, requestedKeys);
|
|
35
|
-
}
|
|
36
|
-
function decodeCandidAttributeValues(data, requestedKeyMap) {
|
|
37
|
-
const textPairs = IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text));
|
|
38
|
-
const recordPairs = IDL.Vec(IDL.Record({
|
|
39
|
-
key: IDL.Text,
|
|
40
|
-
value: IDL.Text,
|
|
41
|
-
}));
|
|
42
|
-
const candidates = [
|
|
43
|
-
[textPairs],
|
|
44
|
-
[recordPairs],
|
|
45
|
-
[IDL.Record({ attributes: textPairs })],
|
|
46
|
-
[IDL.Record({ values: textPairs })],
|
|
47
|
-
[IDL.Record({ attributes: recordPairs })],
|
|
48
|
-
[IDL.Record({ values: recordPairs })],
|
|
49
|
-
];
|
|
50
|
-
for (const candidate of candidates) {
|
|
51
|
-
try {
|
|
52
|
-
const decoded = IDL.decode(candidate, data);
|
|
53
|
-
const values = collectDecodedAttributeValues(decoded, requestedKeyMap);
|
|
54
|
-
if (Object.keys(values).length > 0) {
|
|
55
|
-
return values;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
catch {
|
|
59
|
-
// Try the next known beta payload shape, then fall back to text extraction.
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
return {};
|
|
63
|
-
}
|
|
64
|
-
function collectDecodedAttributeValues(value, requestedKeyMap, activeKey) {
|
|
65
|
-
const values = {};
|
|
66
|
-
if (typeof value === "string") {
|
|
67
|
-
const displayKey = requestedKeyMap[value];
|
|
68
|
-
if (displayKey) {
|
|
69
|
-
return values;
|
|
70
|
-
}
|
|
71
|
-
if (activeKey && isPrintableTextValue(value)) {
|
|
72
|
-
values[activeKey] = value;
|
|
73
|
-
}
|
|
74
|
-
return values;
|
|
75
|
-
}
|
|
76
|
-
if (Array.isArray(value)) {
|
|
77
|
-
if (value.length === 2 && typeof value[0] === "string") {
|
|
78
|
-
const displayKey = requestedKeyMap[value[0]];
|
|
79
|
-
if (displayKey &&
|
|
80
|
-
typeof value[1] === "string" &&
|
|
81
|
-
isPrintableTextValue(value[1])) {
|
|
82
|
-
values[displayKey] = value[1];
|
|
83
|
-
return values;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
for (const item of value) {
|
|
87
|
-
Object.assign(values, collectDecodedAttributeValues(item, requestedKeyMap, activeKey));
|
|
88
|
-
}
|
|
89
|
-
return values;
|
|
90
|
-
}
|
|
91
|
-
if (value && typeof value === "object") {
|
|
92
|
-
const record = value;
|
|
93
|
-
if (typeof record.key === "string" && typeof record.value === "string") {
|
|
94
|
-
const displayKey = requestedKeyMap[record.key];
|
|
95
|
-
if (displayKey && isPrintableTextValue(record.value)) {
|
|
96
|
-
values[displayKey] = record.value;
|
|
97
|
-
return values;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
for (const [key, nested] of Object.entries(record)) {
|
|
101
|
-
const displayKey = requestedKeyMap[key] ?? activeKey;
|
|
102
|
-
if (displayKey &&
|
|
103
|
-
typeof nested === "string" &&
|
|
104
|
-
isPrintableTextValue(nested)) {
|
|
105
|
-
values[displayKey] = nested;
|
|
106
|
-
continue;
|
|
107
|
-
}
|
|
108
|
-
Object.assign(values, collectDecodedAttributeValues(nested, requestedKeyMap, displayKey));
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
return values;
|
|
112
|
-
}
|
|
113
|
-
function extractPrintableAttributeValues(data, requestedKeys) {
|
|
114
|
-
const text = new TextDecoder().decode(data);
|
|
115
|
-
const values = {};
|
|
116
|
-
for (const requestedKey of requestedKeys) {
|
|
117
|
-
const start = text.indexOf(requestedKey);
|
|
118
|
-
if (start === -1) {
|
|
119
|
-
continue;
|
|
120
|
-
}
|
|
121
|
-
const tail = text.slice(start + requestedKey.length);
|
|
122
|
-
const printableRuns = tail.match(/[\x20-\x7E]{2,512}/g) ?? [];
|
|
123
|
-
const value = printableRuns
|
|
124
|
-
.map((candidate) => cleanPrintableAttributeValue(candidate, requestedKeys))
|
|
125
|
-
.find((candidate) => isPrintableTextValue(candidate) &&
|
|
126
|
-
candidate !== requestedKey &&
|
|
127
|
-
!candidate.startsWith("openid:"));
|
|
128
|
-
if (value) {
|
|
129
|
-
values[identityAttributeDisplayKey(requestedKey)] = value.trim();
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
return values;
|
|
133
|
-
}
|
|
134
|
-
function cleanPrintableAttributeValue(value, requestedKeys) {
|
|
135
|
-
let cleaned = value;
|
|
136
|
-
for (const requestedKey of requestedKeys) {
|
|
137
|
-
const nextKeyIndex = cleaned.indexOf(requestedKey);
|
|
138
|
-
if (nextKeyIndex > 0) {
|
|
139
|
-
cleaned = cleaned.slice(0, trimCandidTextLengthPrefix(cleaned, nextKeyIndex));
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
const nextOpenIdKeyMatch = /\d*openid:/.exec(cleaned);
|
|
143
|
-
if (nextOpenIdKeyMatch?.index && nextOpenIdKeyMatch.index > 0) {
|
|
144
|
-
cleaned = cleaned.slice(0, nextOpenIdKeyMatch.index);
|
|
145
|
-
}
|
|
146
|
-
return cleaned.trim();
|
|
147
|
-
}
|
|
148
|
-
function trimCandidTextLengthPrefix(value, index) {
|
|
149
|
-
let trimmedIndex = index;
|
|
150
|
-
while (trimmedIndex > 0 && /\d/.test(value[trimmedIndex - 1])) {
|
|
151
|
-
trimmedIndex -= 1;
|
|
152
|
-
}
|
|
153
|
-
return trimmedIndex;
|
|
154
|
-
}
|
|
155
|
-
function identityAttributeDisplayKey(key) {
|
|
156
|
-
return key.split(":").pop() || key;
|
|
157
|
-
}
|
|
158
|
-
function isPrintableTextValue(value) {
|
|
159
|
-
return value.length > 0 && value.length <= 512 && /^[\x20-\x7E]+$/.test(value);
|
|
160
|
-
}
|
|
161
|
-
export function normalizeSignedIdentityAttributes(attributes) {
|
|
162
|
-
return {
|
|
163
|
-
data: new Uint8Array(attributes.data),
|
|
164
|
-
signature: new Uint8Array(attributes.signature),
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
//# sourceMappingURL=identity-attributes.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"identity-attributes.js","sourceRoot":"","sources":["../src/identity-attributes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,sBAAsB,CAAA;AAO1C,OAAO,EAAE,6BAA6B,EAAE,MAAM,mBAAmB,CAAA;AAEjE,MAAM,CAAC,MAAM,4BAA4B,GAAG,6BAA6B,CAAA;AAEzE;;;GAGG;AACH,MAAM,CAAC,MAAM,iCAAiC,GAAG,4BAA4B,CAAA;AAE7E,MAAM,qBAAqB,GAAG;IAC5B,KAAK,EAAE,2BAA2B;IAClC,MAAM,EAAE,6BAA6B;IACrC,SAAS,EAAE,8CAA8C;CACjD,CAAA;AAEV,MAAM,UAAU,qBAAqB,CAAC,EACpC,cAAc,EACd,IA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CAAC;IACD,OAAO,YAAY,CAAA;AACrB,CAAC;AAED,SAAS,2BAA2B,CAAC,GAAW;IAC9C,OAAO,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,IAAI,GAAG,CAAA;AACpC,CAAC;AAED,SAAS,oBAAoB,CAAC,KAAa;IACzC,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,KAAK,CAAC,MAAM,IAAI,GAAG,IAAI,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;AAChF,CAAC;AAED,MAAM,UAAU,iCAAiC,CAC/C,UAAoC;IAEpC,OAAO;QACL,IAAI,EAAE,IAAI,UAAU,CAAC,UAAU,CAAC,IAAI,CAAC;QACrC,SAAS,EAAE,IAAI,UAAU,CAAC,UAAU,CAAC,SAAS,CAAC;KAChD,CAAA;AACH,CAAC"}
|
|
@@ -1,263 +0,0 @@
|
|
|
1
|
-
import { IDL } from "@icp-sdk/core/candid"
|
|
2
|
-
|
|
3
|
-
import type {
|
|
4
|
-
IdentityAttributeOpenIdProvider,
|
|
5
|
-
IdentityAttributeValues,
|
|
6
|
-
SignedIdentityAttributes,
|
|
7
|
-
} from "./types/client"
|
|
8
|
-
import { IC_INTERNET_IDENTITY_PROVIDER } from "./utils/constants"
|
|
9
|
-
|
|
10
|
-
export const IDENTITY_ATTRIBUTES_PROVIDER = IC_INTERNET_IDENTITY_PROVIDER
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* @deprecated Use the default ClientManager identity provider or
|
|
14
|
-
* `IDENTITY_ATTRIBUTES_PROVIDER` instead.
|
|
15
|
-
*/
|
|
16
|
-
export const IDENTITY_ATTRIBUTES_BETA_PROVIDER = IDENTITY_ATTRIBUTES_PROVIDER
|
|
17
|
-
|
|
18
|
-
const OPEN_ID_PROVIDER_URLS = {
|
|
19
|
-
apple: "https://appleid.apple.com",
|
|
20
|
-
google: "https://accounts.google.com",
|
|
21
|
-
microsoft: "https://login.microsoftonline.com/{tid}/v2.0",
|
|
22
|
-
} as const
|
|
23
|
-
|
|
24
|
-
export function identityAttributeKeys({
|
|
25
|
-
openIdProvider,
|
|
26
|
-
keys,
|
|
27
|
-
}: {
|
|
28
|
-
openIdProvider: IdentityAttributeOpenIdProvider
|
|
29
|
-
keys: string[]
|
|
30
|
-
}): string[] {
|
|
31
|
-
const provider = normalizeOpenIdProvider(openIdProvider)
|
|
32
|
-
return keys.map((key) => `openid:${provider}:${key}`)
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export function normalizeOpenIdProvider(
|
|
36
|
-
openIdProvider: IdentityAttributeOpenIdProvider
|
|
37
|
-
): string {
|
|
38
|
-
return (
|
|
39
|
-
OPEN_ID_PROVIDER_URLS[
|
|
40
|
-
openIdProvider as keyof typeof OPEN_ID_PROVIDER_URLS
|
|
41
|
-
] ?? openIdProvider
|
|
42
|
-
)
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export async function resolveIdentityAttributeKeys({
|
|
46
|
-
openIdProvider,
|
|
47
|
-
keys,
|
|
48
|
-
}: {
|
|
49
|
-
openIdProvider: IdentityAttributeOpenIdProvider
|
|
50
|
-
keys: string[]
|
|
51
|
-
}): Promise<string[]> {
|
|
52
|
-
return identityAttributeKeys({ openIdProvider, keys })
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export function decodeIdentityAttributeValues(
|
|
56
|
-
data: Uint8Array,
|
|
57
|
-
requestedKeys: string[]
|
|
58
|
-
): IdentityAttributeValues {
|
|
59
|
-
const requestedKeyMap = requestedKeys.reduce<Record<string, string>>(
|
|
60
|
-
(acc, key) => {
|
|
61
|
-
acc[key] = identityAttributeDisplayKey(key)
|
|
62
|
-
acc[identityAttributeDisplayKey(key)] = identityAttributeDisplayKey(key)
|
|
63
|
-
return acc
|
|
64
|
-
},
|
|
65
|
-
{}
|
|
66
|
-
)
|
|
67
|
-
|
|
68
|
-
const decodedValues = decodeCandidAttributeValues(data, requestedKeyMap)
|
|
69
|
-
if (Object.keys(decodedValues).length > 0) {
|
|
70
|
-
return decodedValues
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
return extractPrintableAttributeValues(data, requestedKeys)
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
function decodeCandidAttributeValues(
|
|
77
|
-
data: Uint8Array,
|
|
78
|
-
requestedKeyMap: Record<string, string>
|
|
79
|
-
): IdentityAttributeValues {
|
|
80
|
-
const textPairs = IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text))
|
|
81
|
-
const recordPairs = IDL.Vec(
|
|
82
|
-
IDL.Record({
|
|
83
|
-
key: IDL.Text,
|
|
84
|
-
value: IDL.Text,
|
|
85
|
-
})
|
|
86
|
-
)
|
|
87
|
-
|
|
88
|
-
const candidates = [
|
|
89
|
-
[textPairs],
|
|
90
|
-
[recordPairs],
|
|
91
|
-
[IDL.Record({ attributes: textPairs })],
|
|
92
|
-
[IDL.Record({ values: textPairs })],
|
|
93
|
-
[IDL.Record({ attributes: recordPairs })],
|
|
94
|
-
[IDL.Record({ values: recordPairs })],
|
|
95
|
-
]
|
|
96
|
-
|
|
97
|
-
for (const candidate of candidates) {
|
|
98
|
-
try {
|
|
99
|
-
const decoded = IDL.decode(candidate, data)
|
|
100
|
-
const values = collectDecodedAttributeValues(decoded, requestedKeyMap)
|
|
101
|
-
if (Object.keys(values).length > 0) {
|
|
102
|
-
return values
|
|
103
|
-
}
|
|
104
|
-
} catch {
|
|
105
|
-
// Try the next known beta payload shape, then fall back to text extraction.
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
return {}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
function collectDecodedAttributeValues(
|
|
113
|
-
value: unknown,
|
|
114
|
-
requestedKeyMap: Record<string, string>,
|
|
115
|
-
activeKey?: string
|
|
116
|
-
): IdentityAttributeValues {
|
|
117
|
-
const values: IdentityAttributeValues = {}
|
|
118
|
-
|
|
119
|
-
if (typeof value === "string") {
|
|
120
|
-
const displayKey = requestedKeyMap[value]
|
|
121
|
-
if (displayKey) {
|
|
122
|
-
return values
|
|
123
|
-
}
|
|
124
|
-
if (activeKey && isPrintableTextValue(value)) {
|
|
125
|
-
values[activeKey] = value
|
|
126
|
-
}
|
|
127
|
-
return values
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
if (Array.isArray(value)) {
|
|
131
|
-
if (value.length === 2 && typeof value[0] === "string") {
|
|
132
|
-
const displayKey = requestedKeyMap[value[0]]
|
|
133
|
-
if (
|
|
134
|
-
displayKey &&
|
|
135
|
-
typeof value[1] === "string" &&
|
|
136
|
-
isPrintableTextValue(value[1])
|
|
137
|
-
) {
|
|
138
|
-
values[displayKey] = value[1]
|
|
139
|
-
return values
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
for (const item of value) {
|
|
144
|
-
Object.assign(
|
|
145
|
-
values,
|
|
146
|
-
collectDecodedAttributeValues(item, requestedKeyMap, activeKey)
|
|
147
|
-
)
|
|
148
|
-
}
|
|
149
|
-
return values
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
if (value && typeof value === "object") {
|
|
153
|
-
const record = value as Record<string, unknown>
|
|
154
|
-
if (typeof record.key === "string" && typeof record.value === "string") {
|
|
155
|
-
const displayKey = requestedKeyMap[record.key]
|
|
156
|
-
if (displayKey && isPrintableTextValue(record.value)) {
|
|
157
|
-
values[displayKey] = record.value
|
|
158
|
-
return values
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
for (const [key, nested] of Object.entries(record)) {
|
|
163
|
-
const displayKey = requestedKeyMap[key] ?? activeKey
|
|
164
|
-
if (
|
|
165
|
-
displayKey &&
|
|
166
|
-
typeof nested === "string" &&
|
|
167
|
-
isPrintableTextValue(nested)
|
|
168
|
-
) {
|
|
169
|
-
values[displayKey] = nested
|
|
170
|
-
continue
|
|
171
|
-
}
|
|
172
|
-
Object.assign(
|
|
173
|
-
values,
|
|
174
|
-
collectDecodedAttributeValues(nested, requestedKeyMap, displayKey)
|
|
175
|
-
)
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
return values
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
function extractPrintableAttributeValues(
|
|
183
|
-
data: Uint8Array,
|
|
184
|
-
requestedKeys: string[]
|
|
185
|
-
): IdentityAttributeValues {
|
|
186
|
-
const text = new TextDecoder().decode(data)
|
|
187
|
-
const values: IdentityAttributeValues = {}
|
|
188
|
-
|
|
189
|
-
for (const requestedKey of requestedKeys) {
|
|
190
|
-
const start = text.indexOf(requestedKey)
|
|
191
|
-
if (start === -1) {
|
|
192
|
-
continue
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
const tail = text.slice(start + requestedKey.length)
|
|
196
|
-
const printableRuns = tail.match(/[\x20-\x7E]{2,512}/g) ?? []
|
|
197
|
-
const value = printableRuns
|
|
198
|
-
.map((candidate) =>
|
|
199
|
-
cleanPrintableAttributeValue(candidate, requestedKeys)
|
|
200
|
-
)
|
|
201
|
-
.find(
|
|
202
|
-
(candidate) =>
|
|
203
|
-
isPrintableTextValue(candidate) &&
|
|
204
|
-
candidate !== requestedKey &&
|
|
205
|
-
!candidate.startsWith("openid:")
|
|
206
|
-
)
|
|
207
|
-
|
|
208
|
-
if (value) {
|
|
209
|
-
values[identityAttributeDisplayKey(requestedKey)] = value.trim()
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
return values
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
function cleanPrintableAttributeValue(
|
|
217
|
-
value: string,
|
|
218
|
-
requestedKeys: string[]
|
|
219
|
-
): string {
|
|
220
|
-
let cleaned = value
|
|
221
|
-
|
|
222
|
-
for (const requestedKey of requestedKeys) {
|
|
223
|
-
const nextKeyIndex = cleaned.indexOf(requestedKey)
|
|
224
|
-
if (nextKeyIndex > 0) {
|
|
225
|
-
cleaned = cleaned.slice(
|
|
226
|
-
0,
|
|
227
|
-
trimCandidTextLengthPrefix(cleaned, nextKeyIndex)
|
|
228
|
-
)
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
const nextOpenIdKeyMatch = /\d*openid:/.exec(cleaned)
|
|
233
|
-
if (nextOpenIdKeyMatch?.index && nextOpenIdKeyMatch.index > 0) {
|
|
234
|
-
cleaned = cleaned.slice(0, nextOpenIdKeyMatch.index)
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
return cleaned.trim()
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
function trimCandidTextLengthPrefix(value: string, index: number): number {
|
|
241
|
-
let trimmedIndex = index
|
|
242
|
-
while (trimmedIndex > 0 && /\d/.test(value[trimmedIndex - 1])) {
|
|
243
|
-
trimmedIndex -= 1
|
|
244
|
-
}
|
|
245
|
-
return trimmedIndex
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
function identityAttributeDisplayKey(key: string): string {
|
|
249
|
-
return key.split(":").pop() || key
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
function isPrintableTextValue(value: string): boolean {
|
|
253
|
-
return value.length > 0 && value.length <= 512 && /^[\x20-\x7E]+$/.test(value)
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
export function normalizeSignedIdentityAttributes(
|
|
257
|
-
attributes: SignedIdentityAttributes
|
|
258
|
-
): SignedIdentityAttributes {
|
|
259
|
-
return {
|
|
260
|
-
data: new Uint8Array(attributes.data),
|
|
261
|
-
signature: new Uint8Array(attributes.signature),
|
|
262
|
-
}
|
|
263
|
-
}
|