Skip to content

Commit

Permalink
debug-build: dump char encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
kamikazechaser committed Apr 18, 2024
1 parent 269e010 commit 2c0a989
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 7 deletions.
37 changes: 30 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"fastify-metrics": "^10.3.0",
"fastify-plugin": "^4.5.0",
"graphql-request": "^5.2.0",
"iconv-lite": "^0.6.3",
"ioredis": "^5.3.2",
"libphonenumber-js": "^1.10.30",
"moment-timezone": "^0.5.43",
Expand Down
12 changes: 12 additions & 0 deletions src/machines/transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { config } from '@/config';
import {getPhoneNumberFromAddress} from "@services/account";
import {logger} from "@/app";
import {ethers} from "ethers";
import iconv from "iconv-lite"

const VPA_PATTERN = /^[a-zA-Z0-9]+@[a-zA-Z]+$/

Expand Down Expand Up @@ -318,6 +319,17 @@ async function validateRecipient(context: TransferContext, event: any) {
const { input } = event
let phoneNumber = input;
let checksumAddress: string;

logger.debug({
user: context.user.account,
inputUtf8Buffer: iconv.encode(input, "utf8")
}, "input as utf8 buffer")

logger.debug({
user: context.user.account,
inputLatin1Buffer: iconv.encode(input, "ISO-8859-1")
}, "input as latin1 buffer")

if(input.startsWith('0x')){
try {
checksumAddress = ethers.getAddress(input)
Expand Down
12 changes: 12 additions & 0 deletions src/services/africasTalking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { SystemError } from '@lib/errors';
import { SessionRequest } from '@services/session';
import { getCountryCode } from '@lib/ussd';
import { config } from '@/config';
import { logger } from '@/app';
import iconv from "iconv-lite"

export const ATRequestBody = {
type: 'object',
Expand Down Expand Up @@ -29,6 +31,16 @@ export async function ATOnRequestHook(request: SessionRequest) {
export async function ATPreHandlerHook(request: SessionRequest) {
const { phoneNumber, sessionId, serviceCode, text } = request.body as ATRequest;

logger.debug({
inputUtf8Buffer: iconv.encode(text, "utf8"),
phoneNumber: phoneNumber,
}, "AT request as utf8 buffer")

logger.debug({
inputLatin1Buffer: iconv.encode(text, "ISO-8859-1"),
phoneNumber: phoneNumber,
}, "AT reuqest text as latin1 buffer")

const countryCode = await getCountryCode(phoneNumber)
if (!countryCode) {
throw new SystemError(`Could not determine country code from phone number: ${phoneNumber}`);
Expand Down

0 comments on commit 2c0a989

Please sign in to comment.